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. */
48 #include <Carbon/Carbon.h>
50 #define free unexec_free
52 #define malloc unexec_malloc
54 #define realloc unexec_realloc
56 #define min(a, b) ((a) < (b) ? (a) : (b))
58 #define max(a, b) ((a) > (b) ? (a) : (b))
60 #define init_process emacs_init_process
61 /* USE_CARBON_EVENTS determines if the Carbon Event Manager is used to
62 obtain events from the event queue. If set to 0, WaitNextEvent is
64 #define USE_CARBON_EVENTS 1
65 #else /* not MAC_OSX */
66 #include <Quickdraw.h>
67 #include <ToolUtils.h>
71 #include <Resources.h>
73 #include <TextUtils.h>
76 #if defined (__MRC__) || (__MSL__ >= 0x6000)
77 #include <ControlDefinitions.h>
84 #endif /* not MAC_OSX */
98 #include "dispextern.h"
100 #include "termhooks.h"
101 #include "termopts.h"
102 #include "termchar.h"
107 #include "intervals.h"
108 #include "composite.h"
111 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
113 /* Set of macros that handle mapping of Mac modifier keys to emacs. */
114 #define macCtrlKey (NILP (Vmac_reverse_ctrl_meta) ? controlKey : \
115 (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey))
116 #define macShiftKey (shiftKey)
117 #define macMetaKey (NILP (Vmac_reverse_ctrl_meta) ? \
118 (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey) \
120 #define macAltKey (NILP (Vmac_command_key_is_meta) ? cmdKey : optionKey)
123 /* Fringe bitmaps. */
125 enum fringe_bitmap_type
128 LEFT_TRUNCATION_BITMAP
,
129 RIGHT_TRUNCATION_BITMAP
,
130 OVERLAY_ARROW_BITMAP
,
131 CONTINUED_LINE_BITMAP
,
132 CONTINUATION_LINE_BITMAP
,
136 /* Bitmap drawn to indicate lines not displaying text if
137 `indicate-empty-lines' is non-nil. */
142 static unsigned char zv_bits
[] = {
143 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
144 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
145 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
146 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
147 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
148 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
149 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
150 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
152 /* An arrow like this: `<-'. */
155 #define left_height 8
156 static unsigned char left_bits
[] = {
157 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
159 /* Right truncation arrow bitmap `->'. */
161 #define right_width 8
162 #define right_height 8
163 static unsigned char right_bits
[] = {
164 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
166 /* Marker for continued lines. */
168 #define continued_width 8
169 #define continued_height 8
170 static unsigned char continued_bits
[] = {
171 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
173 /* Marker for continuation lines. */
175 #define continuation_width 8
176 #define continuation_height 8
177 static unsigned char continuation_bits
[] = {
178 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
180 /* Overlay arrow bitmap. */
186 static unsigned char ov_bits
[] = {
187 0x0c, 0x10, 0x3c, 0x7e, 0x5e, 0x5e, 0x46, 0x3c};
189 /* A triangular arrow. */
192 static unsigned char ov_bits
[] = {
193 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0};
196 extern Lisp_Object Qhelp_echo
;
199 /* Non-nil means Emacs uses toolkit scroll bars. */
201 Lisp_Object Vx_toolkit_scroll_bars
;
203 /* If a string, XTread_socket generates an event to display that string.
204 (The display is done in read_char.) */
206 static Lisp_Object help_echo
;
207 static Lisp_Object help_echo_window
;
208 static Lisp_Object help_echo_object
;
209 static int help_echo_pos
;
211 /* Temporary variable for XTread_socket. */
213 static Lisp_Object previous_help_echo
;
215 /* Non-zero means that a HELP_EVENT has been generated since Emacs
218 static int any_help_event_p
;
220 /* Non-zero means autoselect window with the mouse cursor. */
222 int x_autoselect_window_p
;
224 /* Non-zero means draw block and hollow cursor as wide as the glyph
225 under it. For example, if a block cursor is over a tab, it will be
226 drawn as wide as that tab on the display. */
228 int x_stretch_cursor_p
;
230 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
232 int x_use_underline_position_properties
;
234 /* This is a chain of structures for all the X displays currently in
237 struct x_display_info
*x_display_list
;
239 /* This is a list of cons cells, each of the form (NAME
240 . FONT-LIST-CACHE), one for each element of x_display_list and in
241 the same order. NAME is the name of the frame. FONT-LIST-CACHE
242 records previous values returned by x-list-fonts. */
244 Lisp_Object x_display_name_list
;
246 /* This is display since Mac does not support multiple ones. */
247 struct mac_display_info one_mac_display_info
;
249 /* Frame being updated by update_frame. This is declared in term.c.
250 This is set by update_begin and looked at by all the XT functions.
251 It is zero while not inside an update. In that case, the XT
252 functions assume that `selected_frame' is the frame to apply to. */
254 extern struct frame
*updating_frame
;
256 extern int waiting_for_input
;
258 /* This is a frame waiting to be auto-raised, within XTread_socket. */
260 struct frame
*pending_autoraise_frame
;
262 /* Nominal cursor position -- where to draw output.
263 HPOS and VPOS are window relative glyph matrix coordinates.
264 X and Y are window relative pixel coordinates. */
266 struct cursor_pos output_cursor
;
268 /* Non-zero means user is interacting with a toolkit scroll bar. */
270 static int toolkit_scroll_bar_interaction
;
274 Formerly, we used PointerMotionHintMask (in standard_event_mask)
275 so that we would have to call XQueryPointer after each MotionNotify
276 event to ask for another such event. However, this made mouse tracking
277 slow, and there was a bug that made it eventually stop.
279 Simply asking for MotionNotify all the time seems to work better.
281 In order to avoid asking for motion events and then throwing most
282 of them away or busy-polling the server for mouse positions, we ask
283 the server for pointer motion hints. This means that we get only
284 one event per group of mouse movements. "Groups" are delimited by
285 other kinds of events (focus changes and button clicks, for
286 example), or by XQueryPointer calls; when one of these happens, we
287 get another MotionNotify event the next time the mouse moves. This
288 is at least as efficient as getting motion events when mouse
289 tracking is on, and I suspect only negligibly worse when tracking
292 /* Where the mouse was last time we reported a mouse event. */
294 FRAME_PTR last_mouse_frame
;
295 static Rect last_mouse_glyph
;
296 static Lisp_Object last_mouse_press_frame
;
298 /* The scroll bar in which the last X motion event occurred.
300 If the last X motion event occurred in a scroll bar, we set this so
301 XTmouse_position can know whether to report a scroll bar motion or
304 If the last X motion event didn't occur in a scroll bar, we set
305 this to Qnil, to tell XTmouse_position to return an ordinary motion
308 static Lisp_Object last_mouse_scroll_bar
;
310 /* This is a hack. We would really prefer that XTmouse_position would
311 return the time associated with the position it returns, but there
312 doesn't seem to be any way to wrest the time-stamp from the server
313 along with the position query. So, we just keep track of the time
314 of the last movement we received, and return that in hopes that
315 it's somewhat accurate. */
317 static Time last_mouse_movement_time
;
319 enum mouse_tracking_type
{
321 mouse_tracking_mouse_movement
,
322 mouse_tracking_scroll_bar
325 enum mouse_tracking_type mouse_tracking_in_progress
= mouse_tracking_none
;
327 struct scroll_bar
*tracked_scroll_bar
= NULL
;
329 /* Incremented by XTread_socket whenever it really tries to read
333 static int volatile input_signal_count
;
335 static int input_signal_count
;
338 /* Used locally within XTread_socket. */
340 static int x_noop_count
;
342 /* Initial values of argv and argc. */
344 extern char **initial_argv
;
345 extern int initial_argc
;
347 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
349 /* Tells if a window manager is present or not. */
351 extern Lisp_Object Vx_no_window_manager
;
353 extern Lisp_Object Qface
, Qmouse_face
;
357 /* A mask of extra modifier bits to put into every keyboard char. */
359 extern int extra_keyboard_modifiers
;
361 static Lisp_Object Qvendor_specific_keysyms
;
364 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
367 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
369 extern int inhibit_window_system
;
372 QDGlobals qd
; /* QuickDraw global information structure. */
376 /* Enumeration for overriding/changing the face to use for drawing
377 glyphs in x_draw_glyphs. */
379 enum draw_glyphs_face
389 struct frame
* x_window_to_frame (struct mac_display_info
*, WindowPtr
);
390 struct mac_display_info
*mac_display_info_for_display (Display
*);
391 static void x_update_window_end
P_ ((struct window
*, int, int));
392 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
393 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
394 int *, int *, Lisp_Object
));
395 static int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
396 int *, int *, int *, int *, int));
397 static void set_output_cursor
P_ ((struct cursor_pos
*));
398 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
399 int *, int *, int *, int));
400 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
401 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
402 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
403 static void x_handle_tool_bar_click
P_ ((struct frame
*, EventRecord
*));
404 static void show_mouse_face
P_ ((struct x_display_info
*,
405 enum draw_glyphs_face
));
406 static int cursor_in_mouse_face_p
P_ ((struct window
*));
407 static int clear_mouse_face
P_ ((struct mac_display_info
*));
408 static int x_io_error_quitter
P_ ((Display
*));
409 int x_catch_errors
P_ ((Display
*));
410 void x_uncatch_errors
P_ ((Display
*, int));
411 void x_lower_frame
P_ ((struct frame
*));
412 void x_scroll_bar_clear
P_ ((struct frame
*));
413 int x_had_errors_p
P_ ((Display
*));
414 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
415 void x_raise_frame
P_ ((struct frame
*));
416 void x_set_window_size
P_ ((struct frame
*, int, int, int));
417 void x_wm_set_window_state
P_ ((struct frame
*, int));
418 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
419 void mac_initialize
P_ ((void));
420 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
421 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
422 enum text_cursor_kinds x_specified_cursor_type
P_ ((Lisp_Object
, int *));
423 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
425 enum draw_glyphs_face
));
426 static void x_update_end
P_ ((struct frame
*));
427 static void XTframe_up_to_date
P_ ((struct frame
*));
428 static void XTreassert_line_highlight
P_ ((int, int));
429 static void x_change_line_highlight
P_ ((int, int, int, int));
430 static void XTset_terminal_modes
P_ ((void));
431 static void XTreset_terminal_modes
P_ ((void));
432 static void XTcursor_to
P_ ((int, int, int, int));
433 static void x_write_glyphs
P_ ((struct glyph
*, int));
434 static void x_clear_end_of_line
P_ ((int));
435 static void x_clear_frame
P_ ((void));
436 static void x_clear_cursor
P_ ((struct window
*));
437 static void frame_highlight
P_ ((struct frame
*));
438 static void frame_unhighlight
P_ ((struct frame
*));
439 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
440 static void XTframe_rehighlight
P_ ((struct frame
*));
441 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
442 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
443 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
444 static int x_intersect_rectangles
P_ ((Rect
*, Rect
*, Rect
*));
445 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
446 static int expose_window_tree
P_ ((struct window
*, Rect
*));
447 static int expose_window
P_ ((struct window
*, Rect
*));
448 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
449 Rect
*, enum glyph_row_area
));
450 static int expose_line
P_ ((struct window
*, struct glyph_row
*,
452 void x_display_cursor (struct window
*, int, int, int, int, int);
453 void x_update_cursor
P_ ((struct frame
*, int));
454 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
455 static void x_update_window_cursor
P_ ((struct window
*, int));
456 static void x_erase_phys_cursor
P_ ((struct window
*));
457 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
458 static void x_draw_fringe_bitmap
P_ ((struct window
*, struct glyph_row
*,
459 enum fringe_bitmap_type
, int left_p
));
460 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
462 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, Rect
*));
463 static void x_draw_row_fringe_bitmaps
P_ ((struct window
*, struct glyph_row
*));
464 static void notice_overwritten_cursor
P_ ((struct window
*,
466 int, int, int, int));
467 static void x_flush
P_ ((struct frame
*f
));
468 static void x_update_begin
P_ ((struct frame
*));
469 static void x_update_window_begin
P_ ((struct window
*));
470 static void x_draw_vertical_border
P_ ((struct window
*));
471 static void x_after_update_window_line
P_ ((struct glyph_row
*));
472 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
473 static void x_produce_stretch_glyph
P_ ((struct it
*));
475 static void activate_scroll_bars (FRAME_PTR
);
476 static void deactivate_scroll_bars (FRAME_PTR
);
478 static int is_emacs_window (WindowPtr
);
480 extern int image_ascent (struct image
*, struct face
*);
481 void x_set_offset (struct frame
*, int, int, int);
482 int x_bitmap_icon (struct frame
*, Lisp_Object
);
483 void x_make_frame_visible (struct frame
*);
485 extern void window_scroll (Lisp_Object
, int, int, int);
487 /* Defined in macmenu.h. */
488 extern void menubar_selection_callback (FRAME_PTR
, int);
489 extern void set_frame_menubar (FRAME_PTR
, int, int);
491 /* X display function emulation */
493 /* Structure borrowed from Xlib.h to represent two-byte characters in
502 XFreePixmap (display
, pixmap
)
506 PixMap
*p
= (PixMap
*) pixmap
;
513 /* Set foreground color for subsequent QuickDraw commands. Assume
514 graphic port has already been set. */
517 mac_set_forecolor (unsigned long color
)
521 fg_color
.red
= RED_FROM_ULONG (color
) * 256;
522 fg_color
.green
= GREEN_FROM_ULONG (color
) * 256;
523 fg_color
.blue
= BLUE_FROM_ULONG (color
) * 256;
525 RGBForeColor (&fg_color
);
529 /* Set background color for subsequent QuickDraw commands. Assume
530 graphic port has already been set. */
533 mac_set_backcolor (unsigned long color
)
537 bg_color
.red
= RED_FROM_ULONG (color
) * 256;
538 bg_color
.green
= GREEN_FROM_ULONG (color
) * 256;
539 bg_color
.blue
= BLUE_FROM_ULONG (color
) * 256;
541 RGBBackColor (&bg_color
);
544 /* Set foreground and background color for subsequent QuickDraw
545 commands. Assume that the graphic port has already been set. */
548 mac_set_colors (GC gc
)
550 mac_set_forecolor (gc
->foreground
);
551 mac_set_backcolor (gc
->background
);
554 /* Mac version of XDrawLine. */
557 XDrawLine (display
, w
, gc
, x1
, y1
, x2
, y2
)
563 #if TARGET_API_MAC_CARBON
564 SetPort (GetWindowPort (w
));
575 /* Mac version of XClearArea. */
578 XClearArea (display
, w
, x
, y
, width
, height
, exposures
)
582 unsigned int width
, height
;
585 struct mac_output
*mwp
= (mac_output
*) GetWRefCon (w
);
589 xgc
.foreground
= mwp
->x_compatible
.foreground_pixel
;
590 xgc
.background
= mwp
->x_compatible
.background_pixel
;
592 #if TARGET_API_MAC_CARBON
593 SetPort (GetWindowPort (w
));
598 mac_set_colors (&xgc
);
599 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
604 /* Mac version of XClearWindow. */
607 XClearWindow (display
, w
)
611 struct mac_output
*mwp
= (mac_output
*) GetWRefCon (w
);
614 xgc
.foreground
= mwp
->x_compatible
.foreground_pixel
;
615 xgc
.background
= mwp
->x_compatible
.background_pixel
;
617 #if TARGET_API_MAC_CARBON
618 SetPort (GetWindowPort (w
));
623 mac_set_colors (&xgc
);
625 #if TARGET_API_MAC_CARBON
629 GetWindowPortBounds (w
, &r
);
632 #else /* not TARGET_API_MAC_CARBON */
633 EraseRect (&(w
->portRect
));
634 #endif /* not TARGET_API_MAC_CARBON */
638 /* Mac replacement for XCopyArea. */
641 mac_draw_bitmap (display
, w
, gc
, x
, y
, bitmap
)
650 #if TARGET_API_MAC_CARBON
651 SetPort (GetWindowPort (w
));
657 SetRect (&r
, x
, y
, x
+ bitmap
->bounds
.right
, y
+ bitmap
->bounds
.bottom
);
659 #if TARGET_API_MAC_CARBON
663 LockPortBits (GetWindowPort (w
));
664 pmh
= GetPortPixMap (GetWindowPort (w
));
665 CopyBits (bitmap
, (BitMap
*) *pmh
, &(bitmap
->bounds
), &r
, srcCopy
, 0);
666 UnlockPortBits (GetWindowPort (w
));
668 #else /* not TARGET_API_MAC_CARBON */
669 CopyBits (bitmap
, &(w
->portBits
), &(bitmap
->bounds
), &r
, srcCopy
, 0);
670 #endif /* not TARGET_API_MAC_CARBON */
674 /* Mac replacement for XSetClipRectangles. */
677 mac_set_clip_rectangle (display
, w
, r
)
682 #if TARGET_API_MAC_CARBON
683 SetPort (GetWindowPort (w
));
692 /* Mac replacement for XSetClipMask. */
695 mac_reset_clipping (display
, w
)
701 #if TARGET_API_MAC_CARBON
702 SetPort (GetWindowPort (w
));
707 SetRect (&r
, -32767, -32767, 32767, 32767);
712 /* Mac replacement for XCreateBitmapFromBitmapData. */
715 mac_create_bitmap_from_bitmap_data (bitmap
, bits
, w
, h
)
720 int bytes_per_row
, i
, j
;
722 bitmap
->rowBytes
= (w
+ 15) / 16 * 2; /* must be on word boundary */
723 bitmap
->baseAddr
= xmalloc (bitmap
->rowBytes
* h
);
724 if (!bitmap
->baseAddr
)
727 bzero (bitmap
->baseAddr
, bitmap
->rowBytes
* h
);
728 for (i
= 0; i
< h
; i
++)
729 for (j
= 0; j
< w
; j
++)
730 if (BitTst (bits
, i
* w
+ j
))
731 BitSet (bitmap
->baseAddr
, i
* bitmap
->rowBytes
* 8 + j
);
733 SetRect (&(bitmap
->bounds
), 0, 0, w
, h
);
738 mac_free_bitmap (bitmap
)
741 xfree (bitmap
->baseAddr
);
744 /* Mac replacement for XFillRectangle. */
747 XFillRectangle (display
, w
, gc
, x
, y
, width
, height
)
752 unsigned int width
, height
;
756 #if TARGET_API_MAC_CARBON
757 SetPort (GetWindowPort (w
));
763 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
765 PaintRect (&r
); /* using foreground color of gc */
769 /* Mac replacement for XDrawRectangle: dest is a window. */
772 mac_draw_rectangle (display
, w
, gc
, x
, y
, width
, height
)
777 unsigned int width
, height
;
781 #if TARGET_API_MAC_CARBON
782 SetPort (GetWindowPort (w
));
788 SetRect (&r
, x
, y
, x
+ width
+ 1, y
+ height
+ 1);
790 FrameRect (&r
); /* using foreground color of gc */
794 /* Mac replacement for XDrawRectangle: dest is a Pixmap. */
797 mac_draw_rectangle_to_pixmap (display
, p
, gc
, x
, y
, width
, height
)
802 unsigned int width
, height
;
804 #if 0 /* MAC_TODO: draw a rectangle in a PixMap */
807 #if TARGET_API_MAC_CARBON
808 SetPort (GetWindowPort (w
));
814 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
816 FrameRect (&r
); /* using foreground color of gc */
822 mac_draw_string_common (display
, w
, gc
, x
, y
, buf
, nchars
, mode
,
829 int nchars
, mode
, bytes_per_char
;
831 #if TARGET_API_MAC_CARBON
832 SetPort (GetWindowPort (w
));
839 TextFont (gc
->font
->mac_fontnum
);
840 TextSize (gc
->font
->mac_fontsize
);
841 TextFace (gc
->font
->mac_fontface
);
845 DrawText (buf
, 0, nchars
* bytes_per_char
);
849 /* Mac replacement for XDrawString. */
852 XDrawString (display
, w
, gc
, x
, y
, buf
, nchars
)
860 mac_draw_string_common (display
, w
, gc
, x
, y
, buf
, nchars
, srcOr
, 1);
864 /* Mac replacement for XDrawString16. */
867 XDrawString16 (display
, w
, gc
, x
, y
, buf
, nchars
)
875 mac_draw_string_common (display
, w
, gc
, x
, y
, (char *) buf
, nchars
, srcOr
,
880 /* Mac replacement for XDrawImageString. */
883 XDrawImageString (display
, w
, gc
, x
, y
, buf
, nchars
)
891 mac_draw_string_common (display
, w
, gc
, x
, y
, buf
, nchars
, srcCopy
, 1);
895 /* Mac replacement for XDrawString16. */
898 XDrawImageString16 (display
, w
, gc
, x
, y
, buf
, nchars
)
906 mac_draw_string_common (display
, w
, gc
, x
, y
, (char *) buf
, nchars
, srcCopy
,
911 /* Mac replacement for XCopyArea: dest must be window. */
914 mac_copy_area (display
, src
, dest
, gc
, src_x
, src_y
, width
, height
, dest_x
,
921 unsigned int width
, height
;
926 #if TARGET_API_MAC_CARBON
927 SetPort (GetWindowPort (dest
));
934 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
935 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
937 #if TARGET_API_MAC_CARBON
941 LockPortBits (GetWindowPort (dest
));
942 pmh
= GetPortPixMap (GetWindowPort (dest
));
943 CopyBits ((BitMap
*) &src
, (BitMap
*) *pmh
, &src_r
, &dest_r
, srcCopy
, 0);
944 UnlockPortBits (GetWindowPort (dest
));
946 #else /* not TARGET_API_MAC_CARBON */
947 CopyBits ((BitMap
*) &src
, &(dest
->portBits
), &src_r
, &dest_r
, srcCopy
, 0);
948 #endif /* not TARGET_API_MAC_CARBON */
953 /* Convert a pair of local coordinates to global (screen) coordinates.
954 Assume graphic port has been properly set. */
956 local_to_global_coord (short *h
, short *v
)
970 /* Mac replacement for XCopyArea: used only for scrolling. */
973 mac_scroll_area (display
, w
, gc
, src_x
, src_y
, width
, height
, dest_x
, dest_y
)
978 unsigned int width
, height
;
981 #if TARGET_API_MAC_CARBON
982 Rect gw_r
, src_r
, dest_r
;
985 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
986 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
988 SetPort (GetWindowPort (w
));
990 ForeColor (blackColor
);
991 BackColor (whiteColor
);
993 LockPortBits (GetWindowPort (w
));
994 pmh
= GetPortPixMap (GetWindowPort (w
));
995 CopyBits ((BitMap
*) *pmh
, (BitMap
*) *pmh
, &src_r
, &dest_r
, srcCopy
, 0);
996 UnlockPortBits (GetWindowPort (w
));
999 #else /* not TARGET_API_MAC_CARBON */
1004 mac_set_colors (gc
);
1007 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1008 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1011 /* Need to use global coordinates and screenBits since src and dest
1012 areas overlap in general. */
1013 local_to_global_coord (&src_r
.left
, &src_r
.top
);
1014 local_to_global_coord (&src_r
.right
, &src_r
.bottom
);
1015 local_to_global_coord (&dest_r
.left
, &dest_r
.top
);
1016 local_to_global_coord (&dest_r
.right
, &dest_r
.bottom
);
1018 CopyBits (&qd
.screenBits
, &qd
.screenBits
, &src_r
, &dest_r
, srcCopy
, 0);
1020 /* In Color QuickDraw, set ForeColor and BackColor as follows to avoid
1021 color mapping in CopyBits. Otherwise, it will be slow. */
1022 ForeColor (blackColor
);
1023 BackColor (whiteColor
);
1024 CopyBits (&(w
->portBits
), &(w
->portBits
), &src_r
, &dest_r
, srcCopy
, 0);
1026 mac_set_colors (gc
);
1028 #endif /* not TARGET_API_MAC_CARBON */
1032 /* Mac replacement for XCopyArea: dest must be Pixmap. */
1035 mac_copy_area_to_pixmap (display
, src
, dest
, gc
, src_x
, src_y
, width
, height
,
1042 unsigned int width
, height
;
1046 int src_right
= ((PixMap
*) src
)->bounds
.right
;
1047 int src_bottom
= ((PixMap
*) src
)->bounds
.bottom
;
1048 int w
= src_right
- src_x
;
1049 int h
= src_bottom
- src_y
;
1051 mac_set_colors (gc
);
1053 SetRect (&src_r
, src_x
, src_y
, src_right
, src_bottom
);
1054 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ w
, dest_y
+ h
);
1056 CopyBits ((BitMap
*) &src
, (BitMap
*) &dest
, &src_r
, &dest_r
, srcCopy
, 0);
1060 /* Mac replacement for XChangeGC. */
1063 XChangeGC (void * ignore
, XGCValues
* gc
, unsigned long mask
,
1066 if (mask
& GCForeground
)
1067 gc
->foreground
= xgcv
->foreground
;
1068 if (mask
& GCBackground
)
1069 gc
->background
= xgcv
->background
;
1071 gc
->font
= xgcv
->font
;
1075 /* Mac replacement for XCreateGC. */
1078 XCreateGC (void * ignore
, Window window
, unsigned long mask
,
1081 XGCValues
*gc
= (XGCValues
*) xmalloc (sizeof (XGCValues
));
1082 bzero (gc
, sizeof (XGCValues
));
1084 XChangeGC (ignore
, gc
, mask
, xgcv
);
1090 /* Used in xfaces.c. */
1093 XFreeGC (display
, gc
)
1101 /* Mac replacement for XGetGCValues. */
1104 XGetGCValues (void* ignore
, XGCValues
*gc
,
1105 unsigned long mask
, XGCValues
*xgcv
)
1107 XChangeGC (ignore
, xgcv
, mask
, gc
);
1111 /* Mac replacement for XSetForeground. */
1114 XSetForeground (display
, gc
, color
)
1117 unsigned long color
;
1119 gc
->foreground
= color
;
1123 /* Mac replacement for XSetFont. */
1126 XSetFont (display
, gc
, font
)
1136 XTextExtents16 (XFontStruct
*font
, XChar2b
*text
, int nchars
,
1137 int *direction
,int *font_ascent
,
1138 int *font_descent
, XCharStruct
*cs
)
1140 /* MAC_TODO: Use GetTextMetrics to do this and inline it below. */
1144 /* x_sync is a no-op on Mac. */
1152 /* Remove calls to XFlush by defining XFlush to an empty replacement.
1153 Calls to XFlush should be unnecessary because the X output buffer
1154 is flushed automatically as needed by calls to XPending,
1155 XNextEvent, or XWindowEvent according to the XFlush man page.
1156 XTread_socket calls XPending. Removing XFlush improves
1159 #if TARGET_API_MAC_CARBON
1160 #define XFlush(DISPLAY) QDFlushPortBuffer (GetQDGlobalsThePort (), NULL)
1162 #define XFlush(DISPLAY) (void) 0
1165 /* Flush display of frame F, or of all frames if F is null. */
1171 #if TARGET_API_MAC_CARBON
1175 Lisp_Object rest
, frame
;
1176 FOR_EACH_FRAME (rest
, frame
)
1177 x_flush (XFRAME (frame
));
1179 else if (FRAME_X_P (f
))
1180 XFlush (FRAME_MAC_DISPLAY (f
));
1182 #endif /* TARGET_API_MAC_CARBON */
1187 /* Return the struct mac_display_info corresponding to DPY. There's
1190 struct mac_display_info
*
1191 mac_display_info_for_display (dpy
)
1194 return &one_mac_display_info
;
1199 /***********************************************************************
1200 Starting and ending an update
1201 ***********************************************************************/
1203 /* Start an update of frame F. This function is installed as a hook
1204 for update_begin, i.e. it is called when update_begin is called.
1205 This function is called prior to calls to x_update_window_begin for
1206 each window being updated. */
1212 /* Nothing to do. */
1216 /* Start update of window W. Set the global variable updated_window
1217 to the window being updated and set output_cursor to the cursor
1221 x_update_window_begin (w
)
1224 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1225 struct mac_display_info
*display_info
= FRAME_MAC_DISPLAY_INFO (f
);
1228 set_output_cursor (&w
->cursor
);
1232 if (f
== display_info
->mouse_face_mouse_frame
)
1234 /* Don't do highlighting for mouse motion during the update. */
1235 display_info
->mouse_face_defer
= 1;
1237 /* If F needs to be redrawn, simply forget about any prior mouse
1239 if (FRAME_GARBAGED_P (f
))
1240 display_info
->mouse_face_window
= Qnil
;
1242 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
1243 their mouse_face_p flag set, which means that they are always
1244 unequal to rows in a desired matrix which never have that
1245 flag set. So, rows containing mouse-face glyphs are never
1246 scrolled, and we don't have to switch the mouse highlight off
1247 here to prevent it from being scrolled. */
1249 /* Can we tell that this update does not affect the window
1250 where the mouse highlight is? If so, no need to turn off.
1251 Likewise, don't do anything if the frame is garbaged;
1252 in that case, the frame's current matrix that we would use
1253 is all wrong, and we will redisplay that line anyway. */
1254 if (!NILP (display_info
->mouse_face_window
)
1255 && w
== XWINDOW (display_info
->mouse_face_window
))
1259 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
1260 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
1263 if (i
< w
->desired_matrix
->nrows
)
1264 clear_mouse_face (display_info
);
1273 /* Draw a vertical window border to the right of window W if W doesn't
1274 have vertical scroll bars. */
1277 x_draw_vertical_border (w
)
1280 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1282 /* Redraw borders between horizontally adjacent windows. Don't
1283 do it for frames with vertical scroll bars because either the
1284 right scroll bar of a window, or the left scroll bar of its
1285 neighbor will suffice as a border. */
1286 if (!WINDOW_RIGHTMOST_P (w
)
1287 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
1291 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
1292 x1
+= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
1295 XDrawLine (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
1296 f
->output_data
.mac
->normal_gc
, x1
, y0
, x1
, y1
);
1301 /* End update of window W (which is equal to updated_window).
1303 Draw vertical borders between horizontally adjacent windows, and
1304 display W's cursor if CURSOR_ON_P is non-zero.
1306 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
1307 glyphs in mouse-face were overwritten. In that case we have to
1308 make sure that the mouse-highlight is properly redrawn.
1310 W may be a menu bar pseudo-window in case we don't have X toolkit
1311 support. Such windows don't have a cursor, so don't display it
1315 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
1317 int cursor_on_p
, mouse_face_overwritten_p
;
1319 struct mac_display_info
*dpyinfo
1320 = FRAME_MAC_DISPLAY_INFO (XFRAME (w
->frame
));
1322 if (!w
->pseudo_window_p
)
1327 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
1329 output_cursor
.x
, output_cursor
.y
);
1331 x_draw_vertical_border (w
);
1335 /* If a row with mouse-face was overwritten, arrange for
1336 XTframe_up_to_date to redisplay the mouse highlight. */
1337 if (mouse_face_overwritten_p
)
1339 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
1340 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
1341 dpyinfo
->mouse_face_window
= Qnil
;
1345 /* Unhide the caret. This won't actually show the cursor, unless it
1346 was visible before the corresponding call to HideCaret in
1347 x_update_window_begin. */
1348 if (w32_use_visible_system_caret
)
1349 SendMessage (w32_system_caret_hwnd
, WM_EMACS_SHOW_CARET
, 0, 0);
1352 updated_window
= NULL
;
1356 /* End update of frame F. This function is installed as a hook in
1363 /* Reset the background color of Mac OS Window to that of the frame after
1364 update so that it is used by Mac Toolbox to clear the update region before
1365 an update event is generated. */
1366 #if TARGET_API_MAC_CARBON
1367 SetPort (GetWindowPort (FRAME_MAC_WINDOW (f
)));
1369 SetPort (FRAME_MAC_WINDOW (f
));
1372 mac_set_backcolor (FRAME_BACKGROUND_PIXEL (f
));
1374 /* Mouse highlight may be displayed again. */
1375 FRAME_MAC_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
1378 XFlush (FRAME_MAC_DISPLAY (f
));
1383 /* This function is called from various places in xdisp.c whenever a
1384 complete update has been performed. The global variable
1385 updated_window is not available here. */
1388 XTframe_up_to_date (f
)
1393 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
1395 if (dpyinfo
->mouse_face_deferred_gc
1396 || f
== dpyinfo
->mouse_face_mouse_frame
)
1399 if (dpyinfo
->mouse_face_mouse_frame
)
1400 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
1401 dpyinfo
->mouse_face_mouse_x
,
1402 dpyinfo
->mouse_face_mouse_y
);
1403 dpyinfo
->mouse_face_deferred_gc
= 0;
1410 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
1411 arrow bitmaps, or clear the fringes if no bitmaps are required
1412 before DESIRED_ROW is made current. The window being updated is
1413 found in updated_window. This function is called from
1414 update_window_line only if it is known that there are differences
1415 between bitmaps to be drawn between current row and DESIRED_ROW. */
1418 x_after_update_window_line (desired_row
)
1419 struct glyph_row
*desired_row
;
1421 struct window
*w
= updated_window
;
1427 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
1430 x_draw_row_fringe_bitmaps (w
, desired_row
);
1434 /* When a window has disappeared, make sure that no rest of
1435 full-width rows stays visible in the internal border. Could
1436 check here if updated_window is the leftmost/rightmost window,
1437 but I guess it's not worth doing since vertically split windows
1438 are almost never used, internal border is rarely set, and the
1439 overhead is very small. */
1440 if (windows_or_buffers_changed
1441 && desired_row
->full_width_p
1442 && (f
= XFRAME (w
->frame
),
1443 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
1445 && (height
= desired_row
->visible_height
,
1448 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
1449 /* Internal border is drawn below the tool bar. */
1450 if (WINDOWP (f
->tool_bar_window
)
1451 && w
== XWINDOW (f
->tool_bar_window
))
1456 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
1457 0, y
, width
, height
, 0);
1458 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
1459 f
->output_data
.mac
->pixel_width
- width
, y
,
1467 /* Draw the bitmap WHICH in one of the left or right fringes of
1468 window W. ROW is the glyph row for which to display the bitmap; it
1469 determines the vertical position at which the bitmap has to be
1473 x_draw_fringe_bitmap (w
, row
, which
, left_p
)
1475 struct glyph_row
*row
;
1476 enum fringe_bitmap_type which
;
1479 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1480 Display
*display
= FRAME_MAC_DISPLAY (f
);
1481 WindowPtr window
= FRAME_MAC_WINDOW (f
);
1482 int x
, y
, wd
, h
, dy
;
1484 unsigned char *bits
;
1487 GC gc
= f
->output_data
.mac
->normal_gc
;
1490 /* Must clip because of partially visible lines. */
1491 x_clip_to_row (w
, row
, gc
, 1);
1493 /* Convert row to frame coordinates. */
1494 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
1498 case NO_FRINGE_BITMAP
:
1503 case LEFT_TRUNCATION_BITMAP
:
1509 case OVERLAY_ARROW_BITMAP
:
1515 case RIGHT_TRUNCATION_BITMAP
:
1521 case CONTINUED_LINE_BITMAP
:
1522 wd
= continued_width
;
1523 h
= continued_height
;
1524 bits
= continued_bits
;
1527 case CONTINUATION_LINE_BITMAP
:
1528 wd
= continuation_width
;
1529 h
= continuation_height
;
1530 bits
= continuation_bits
;
1533 case ZV_LINE_BITMAP
:
1535 h
= zv_height
- (y
% zv_period
);
1536 bits
= zv_bits
+ (y
% zv_period
);
1543 /* Clip bitmap if too high. */
1544 if (h
> row
->height
)
1547 /* Set dy to the offset in the row to start drawing the bitmap. */
1548 dy
= (row
->height
- h
) / 2;
1550 /* Draw the bitmap. */
1551 face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
1552 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1554 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
1559 if (wd
> FRAME_X_LEFT_FRINGE_WIDTH (f
))
1560 wd
= FRAME_X_LEFT_FRINGE_WIDTH (f
);
1561 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
1563 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - wd
) / 2);
1564 if (wd
< FRAME_X_LEFT_FRINGE_WIDTH (f
) || row
->height
> h
)
1566 /* If W has a vertical border to its left, don't draw over it. */
1567 int border
= ((XFASTINT (w
->left
) > 0
1568 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
1570 b1
= (window_box_left (w
, -1)
1571 - FRAME_X_LEFT_FRINGE_WIDTH (f
)
1573 b2
= (FRAME_X_LEFT_FRINGE_WIDTH (f
) - border
);
1578 if (wd
> FRAME_X_RIGHT_FRINGE_WIDTH (f
))
1579 wd
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
1580 x
= (window_box_right (w
, -1)
1581 + (FRAME_X_RIGHT_FRINGE_WIDTH (f
) - wd
) / 2);
1582 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
1584 if (wd
< FRAME_X_RIGHT_FRINGE_WIDTH (f
) || row
->height
> h
)
1586 b1
= window_box_right (w
, -1);
1587 b2
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
1593 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1595 gcv
.foreground
= face
->background
;
1597 #if 0 /* MAC_TODO: stipple */
1598 /* In case the same realized face is used for fringes and
1599 for something displayed in the text (e.g. face `region' on
1600 mono-displays, the fill style may have been changed to
1601 FillSolid in x_draw_glyph_string_background. */
1603 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
1605 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
1608 XFillRectangle (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
1611 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
1614 row
->visible_height
);
1616 #if 0 /* MAC_TODO: stipple */
1618 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
1622 if (which
== NO_FRINGE_BITMAP
)
1624 mac_reset_clipping (display
, window
);
1628 mac_create_bitmap_from_bitmap_data (&bitmap
, bits
, wd
, h
);
1629 gcv
.foreground
= face
->foreground
;
1630 gcv
.background
= face
->background
;
1632 mac_draw_bitmap (display
, window
, &gcv
, x
, y
+ dy
, &bitmap
);
1634 mac_free_bitmap (&bitmap
);
1635 mac_reset_clipping (display
, window
);
1639 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
1640 function with input blocked. */
1643 x_draw_row_fringe_bitmaps (w
, row
)
1645 struct glyph_row
*row
;
1647 struct frame
*f
= XFRAME (w
->frame
);
1648 enum fringe_bitmap_type bitmap
;
1650 xassert (interrupt_input_blocked
);
1652 /* If row is completely invisible, because of vscrolling, we
1653 don't have to draw anything. */
1654 if (row
->visible_height
<= 0)
1657 if (FRAME_X_LEFT_FRINGE_WIDTH (f
) != 0)
1659 /* Decide which bitmap to draw in the left fringe. */
1660 if (row
->overlay_arrow_p
)
1661 bitmap
= OVERLAY_ARROW_BITMAP
;
1662 else if (row
->truncated_on_left_p
)
1663 bitmap
= LEFT_TRUNCATION_BITMAP
;
1664 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
1665 bitmap
= CONTINUATION_LINE_BITMAP
;
1666 else if (row
->indicate_empty_line_p
)
1667 bitmap
= ZV_LINE_BITMAP
;
1669 bitmap
= NO_FRINGE_BITMAP
;
1671 x_draw_fringe_bitmap (w
, row
, bitmap
, 1);
1674 if (FRAME_X_RIGHT_FRINGE_WIDTH (f
) != 0)
1676 /* Decide which bitmap to draw in the right fringe. */
1677 if (row
->truncated_on_right_p
)
1678 bitmap
= RIGHT_TRUNCATION_BITMAP
;
1679 else if (row
->continued_p
)
1680 bitmap
= CONTINUED_LINE_BITMAP
;
1681 else if (row
->indicate_empty_line_p
&& FRAME_X_LEFT_FRINGE_WIDTH (f
) == 0)
1682 bitmap
= ZV_LINE_BITMAP
;
1684 bitmap
= NO_FRINGE_BITMAP
;
1686 x_draw_fringe_bitmap (w
, row
, bitmap
, 0);
1691 /* This is called when starting Emacs and when restarting after
1692 suspend. When starting Emacs, no window is mapped. And nothing
1693 must be done to Emacs's own window if it is suspended (though that
1697 XTset_terminal_modes ()
1701 /* This is called when exiting or suspending Emacs. Exiting will make
1702 the windows go away, and suspending requires no action. */
1705 XTreset_terminal_modes ()
1711 /***********************************************************************
1713 ***********************************************************************/
1715 /* Set the global variable output_cursor to CURSOR. All cursor
1716 positions are relative to updated_window. */
1719 set_output_cursor (cursor
)
1720 struct cursor_pos
*cursor
;
1722 output_cursor
.hpos
= cursor
->hpos
;
1723 output_cursor
.vpos
= cursor
->vpos
;
1724 output_cursor
.x
= cursor
->x
;
1725 output_cursor
.y
= cursor
->y
;
1729 /* Set a nominal cursor position.
1731 HPOS and VPOS are column/row positions in a window glyph matrix. X
1732 and Y are window text area relative pixel positions.
1734 If this is done during an update, updated_window will contain the
1735 window that is being updated and the position is the future output
1736 cursor position for that window. If updated_window is null, use
1737 selected_window and display the cursor at the given position. */
1740 XTcursor_to (vpos
, hpos
, y
, x
)
1741 int vpos
, hpos
, y
, x
;
1745 /* If updated_window is not set, work on selected_window. */
1749 w
= XWINDOW (selected_window
);
1751 /* Set the output cursor. */
1752 output_cursor
.hpos
= hpos
;
1753 output_cursor
.vpos
= vpos
;
1754 output_cursor
.x
= x
;
1755 output_cursor
.y
= y
;
1757 /* If not called as part of an update, really display the cursor.
1758 This will also set the cursor position of W. */
1759 if (updated_window
== NULL
)
1762 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1763 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1770 /***********************************************************************
1772 ***********************************************************************/
1774 /* Function prototypes of this page. */
1776 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1780 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1781 int, XChar2b
*, int));
1782 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1783 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1784 static void x_append_glyph
P_ ((struct it
*));
1785 static void x_append_composite_glyph
P_ ((struct it
*));
1786 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1788 static void x_produce_glyphs
P_ ((struct it
*));
1789 static void x_produce_image_glyph
P_ ((struct it
*it
));
1792 /* Return a pointer to per-char metric information in FONT of a
1793 character pointed by B which is a pointer to an XChar2b. */
1795 #define PER_CHAR_METRIC(font, b) \
1797 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
1798 + (((font)->min_byte1 || (font)->max_byte1) \
1799 ? (((b)->byte1 - (font)->min_byte1) \
1800 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
1802 : &((font)->max_bounds))
1805 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1806 is not contained in the font. */
1808 static INLINE XCharStruct
*
1809 x_per_char_metric (font
, char2b
)
1813 /* The result metric information. */
1814 XCharStruct
*pcm
= NULL
;
1816 xassert (font
&& char2b
);
1818 if (font
->per_char
!= NULL
)
1820 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1822 /* min_char_or_byte2 specifies the linear character index
1823 corresponding to the first element of the per_char array,
1824 max_char_or_byte2 is the index of the last character. A
1825 character with non-zero CHAR2B->byte1 is not in the font.
1826 A character with byte2 less than min_char_or_byte2 or
1827 greater max_char_or_byte2 is not in the font. */
1828 if (char2b
->byte1
== 0
1829 && char2b
->byte2
>= font
->min_char_or_byte2
1830 && char2b
->byte2
<= font
->max_char_or_byte2
)
1831 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1835 /* If either min_byte1 or max_byte1 are nonzero, both
1836 min_char_or_byte2 and max_char_or_byte2 are less than
1837 256, and the 2-byte character index values corresponding
1838 to the per_char array element N (counting from 0) are:
1840 byte1 = N/D + min_byte1
1841 byte2 = N\D + min_char_or_byte2
1845 D = max_char_or_byte2 - min_char_or_byte2 + 1
1846 / = integer division
1847 \ = integer modulus */
1848 if (char2b
->byte1
>= font
->min_byte1
1849 && char2b
->byte1
<= font
->max_byte1
1850 && char2b
->byte2
>= font
->min_char_or_byte2
1851 && char2b
->byte2
<= font
->max_char_or_byte2
)
1853 pcm
= (font
->per_char
1854 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1855 * (char2b
->byte1
- font
->min_byte1
))
1856 + (char2b
->byte2
- font
->min_char_or_byte2
));
1862 /* If the per_char pointer is null, all glyphs between the first
1863 and last character indexes inclusive have the same
1864 information, as given by both min_bounds and max_bounds. */
1865 if (char2b
->byte2
>= font
->min_char_or_byte2
1866 && char2b
->byte2
<= font
->max_char_or_byte2
)
1867 pcm
= &font
->max_bounds
;
1870 return ((pcm
== NULL
1871 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1876 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1877 the two-byte form of C. Encoding is returned in *CHAR2B. */
1880 x_encode_char (c
, char2b
, font_info
)
1883 struct font_info
*font_info
;
1885 int charset
= CHAR_CHARSET (c
);
1886 XFontStruct
*font
= font_info
->font
;
1888 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1889 This may be either a program in a special encoder language or a
1891 if (font_info
->font_encoder
)
1893 /* It's a program. */
1894 struct ccl_program
*ccl
= font_info
->font_encoder
;
1896 if (CHARSET_DIMENSION (charset
) == 1)
1898 ccl
->reg
[0] = charset
;
1899 ccl
->reg
[1] = char2b
->byte2
;
1903 ccl
->reg
[0] = charset
;
1904 ccl
->reg
[1] = char2b
->byte1
;
1905 ccl
->reg
[2] = char2b
->byte2
;
1908 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1910 /* We assume that MSBs are appropriately set/reset by CCL
1912 if (font
->max_byte1
== 0) /* 1-byte font */
1913 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1915 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1917 else if (font_info
->encoding
[charset
])
1919 /* Fixed encoding scheme. See fontset.h for the meaning of the
1920 encoding numbers. */
1921 int enc
= font_info
->encoding
[charset
];
1923 if ((enc
== 1 || enc
== 2)
1924 && CHARSET_DIMENSION (charset
) == 2)
1925 char2b
->byte1
|= 0x80;
1927 if (enc
== 1 || enc
== 3)
1928 char2b
->byte2
|= 0x80;
1934 ENCODE_SJIS (char2b
->byte1
, char2b
->byte2
, sjis1
, sjis2
);
1935 char2b
->byte1
= sjis1
;
1936 char2b
->byte2
= sjis2
;
1942 /* Get face and two-byte form of character C in face FACE_ID on frame
1943 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1944 means we want to display multibyte text. Value is a pointer to a
1945 realized face that is ready for display. */
1947 static INLINE
struct face
*
1948 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1954 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1958 /* Unibyte case. We don't have to encode, but we have to make
1959 sure to use a face suitable for unibyte. */
1962 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1963 face
= FACE_FROM_ID (f
, face_id
);
1965 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1967 /* Case of ASCII in a face known to fit ASCII. */
1973 int c1
, c2
, charset
;
1975 /* Split characters into bytes. If c2 is -1 afterwards, C is
1976 really a one-byte character so that byte1 is zero. */
1977 SPLIT_CHAR (c
, charset
, c1
, c2
);
1979 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1981 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1983 /* Maybe encode the character in *CHAR2B. */
1984 if (face
->font
!= NULL
)
1986 struct font_info
*font_info
1987 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1989 x_encode_char (c
, char2b
, font_info
);
1993 /* Make sure X resources of the face are allocated. */
1994 xassert (face
!= NULL
);
1995 PREPARE_FACE_FOR_DISPLAY (f
, face
);
2001 /* Get face and two-byte form of character glyph GLYPH on frame F.
2002 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
2003 a pointer to a realized face that is ready for display. */
2005 static INLINE
struct face
*
2006 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
2008 struct glyph
*glyph
;
2014 xassert (glyph
->type
== CHAR_GLYPH
);
2015 face
= FACE_FROM_ID (f
, glyph
->face_id
);
2020 if (!glyph
->multibyte_p
)
2022 /* Unibyte case. We don't have to encode, but we have to make
2023 sure to use a face suitable for unibyte. */
2025 char2b
->byte2
= glyph
->u
.ch
;
2027 else if (glyph
->u
.ch
< 128
2028 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
2030 /* Case of ASCII in a face known to fit ASCII. */
2032 char2b
->byte2
= glyph
->u
.ch
;
2036 int c1
, c2
, charset
;
2038 /* Split characters into bytes. If c2 is -1 afterwards, C is
2039 really a one-byte character so that byte1 is zero. */
2040 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
2042 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
2044 char2b
->byte1
= 0, char2b
->byte2
= c1
;
2046 /* Maybe encode the character in *CHAR2B. */
2047 if (charset
!= CHARSET_ASCII
)
2049 struct font_info
*font_info
2050 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2053 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
2056 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
2061 /* Make sure X resources of the face are allocated. */
2062 xassert (face
!= NULL
);
2063 PREPARE_FACE_FOR_DISPLAY (f
, face
);
2068 /* Store one glyph for IT->char_to_display in IT->glyph_row.
2069 Called from x_produce_glyphs when IT->glyph_row is non-null. */
2075 struct glyph
*glyph
;
2076 enum glyph_row_area area
= it
->area
;
2078 xassert (it
->glyph_row
);
2079 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
2081 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
2082 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
2084 glyph
->charpos
= CHARPOS (it
->position
);
2085 glyph
->object
= it
->object
;
2086 glyph
->pixel_width
= it
->pixel_width
;
2087 glyph
->voffset
= it
->voffset
;
2088 glyph
->type
= CHAR_GLYPH
;
2089 glyph
->multibyte_p
= it
->multibyte_p
;
2090 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
2091 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
2092 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
2093 || it
->phys_descent
> it
->descent
);
2094 glyph
->padding_p
= 0;
2095 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
2096 glyph
->face_id
= it
->face_id
;
2097 glyph
->u
.ch
= it
->char_to_display
;
2098 ++it
->glyph_row
->used
[area
];
2102 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
2103 Called from x_produce_glyphs when IT->glyph_row is non-null. */
2106 x_append_composite_glyph (it
)
2109 struct glyph
*glyph
;
2110 enum glyph_row_area area
= it
->area
;
2112 xassert (it
->glyph_row
);
2114 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
2115 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
2117 glyph
->charpos
= CHARPOS (it
->position
);
2118 glyph
->object
= it
->object
;
2119 glyph
->pixel_width
= it
->pixel_width
;
2120 glyph
->voffset
= it
->voffset
;
2121 glyph
->type
= COMPOSITE_GLYPH
;
2122 glyph
->multibyte_p
= it
->multibyte_p
;
2123 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
2124 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
2125 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
2126 || it
->phys_descent
> it
->descent
);
2127 glyph
->padding_p
= 0;
2128 glyph
->glyph_not_available_p
= 0;
2129 glyph
->face_id
= it
->face_id
;
2130 glyph
->u
.cmp_id
= it
->cmp_id
;
2131 ++it
->glyph_row
->used
[area
];
2136 /* Change IT->ascent and IT->height according to the setting of
2140 take_vertical_position_into_account (it
)
2145 if (it
->voffset
< 0)
2146 /* Increase the ascent so that we can display the text higher
2148 it
->ascent
+= abs (it
->voffset
);
2150 /* Increase the descent so that we can display the text lower
2152 it
->descent
+= it
->voffset
;
2157 /* Produce glyphs/get display metrics for the image IT is loaded with.
2158 See the description of struct display_iterator in dispextern.h for
2159 an overview of struct display_iterator. */
2162 x_produce_image_glyph (it
)
2168 xassert (it
->what
== IT_IMAGE
);
2170 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2171 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
2174 /* Make sure X resources of the face and image are loaded. */
2175 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
2176 prepare_image_for_display (it
->f
, img
);
2178 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
2179 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
2180 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
2184 if (face
->box
!= FACE_NO_BOX
)
2186 if (face
->box_line_width
> 0)
2188 it
->ascent
+= face
->box_line_width
;
2189 it
->descent
+= face
->box_line_width
;
2192 if (it
->start_of_box_run_p
)
2193 it
->pixel_width
+= abs (face
->box_line_width
);
2194 if (it
->end_of_box_run_p
)
2195 it
->pixel_width
+= abs (face
->box_line_width
);
2198 take_vertical_position_into_account (it
);
2202 struct glyph
*glyph
;
2203 enum glyph_row_area area
= it
->area
;
2205 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
2206 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
2208 glyph
->charpos
= CHARPOS (it
->position
);
2209 glyph
->object
= it
->object
;
2210 glyph
->pixel_width
= it
->pixel_width
;
2211 glyph
->voffset
= it
->voffset
;
2212 glyph
->type
= IMAGE_GLYPH
;
2213 glyph
->multibyte_p
= it
->multibyte_p
;
2214 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
2215 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
2216 glyph
->overlaps_vertically_p
= 0;
2217 glyph
->padding_p
= 0;
2218 glyph
->glyph_not_available_p
= 0;
2219 glyph
->face_id
= it
->face_id
;
2220 glyph
->u
.img_id
= img
->id
;
2221 ++it
->glyph_row
->used
[area
];
2227 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
2228 of the glyph, WIDTH and HEIGHT are the width and height of the
2229 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
2230 ascent of the glyph (0 <= ASCENT <= 1). */
2233 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
2239 struct glyph
*glyph
;
2240 enum glyph_row_area area
= it
->area
;
2242 xassert (ascent
>= 0 && ascent
<= 1);
2244 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
2245 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
2247 glyph
->charpos
= CHARPOS (it
->position
);
2248 glyph
->object
= object
;
2249 glyph
->pixel_width
= width
;
2250 glyph
->voffset
= it
->voffset
;
2251 glyph
->type
= STRETCH_GLYPH
;
2252 glyph
->multibyte_p
= it
->multibyte_p
;
2253 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
2254 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
2255 glyph
->overlaps_vertically_p
= 0;
2256 glyph
->padding_p
= 0;
2257 glyph
->glyph_not_available_p
= 0;
2258 glyph
->face_id
= it
->face_id
;
2259 glyph
->u
.stretch
.ascent
= height
* ascent
;
2260 glyph
->u
.stretch
.height
= height
;
2261 ++it
->glyph_row
->used
[area
];
2266 /* Produce a stretch glyph for iterator IT. IT->object is the value
2267 of the glyph property displayed. The value must be a list
2268 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
2271 1. `:width WIDTH' specifies that the space should be WIDTH *
2272 canonical char width wide. WIDTH may be an integer or floating
2275 2. `:relative-width FACTOR' specifies that the width of the stretch
2276 should be computed from the width of the first character having the
2277 `glyph' property, and should be FACTOR times that width.
2279 3. `:align-to HPOS' specifies that the space should be wide enough
2280 to reach HPOS, a value in canonical character units.
2282 Exactly one of the above pairs must be present.
2284 4. `:height HEIGHT' specifies that the height of the stretch produced
2285 should be HEIGHT, measured in canonical character units.
2287 5. `:relative-height FACTOR' specifies that the height of the
2288 stretch should be FACTOR times the height of the characters having
2291 Either none or exactly one of 4 or 5 must be present.
2293 6. `:ascent ASCENT' specifies that ASCENT percent of the height
2294 of the stretch should be used for the ascent of the stretch.
2295 ASCENT must be in the range 0 <= ASCENT <= 100. */
2298 ((INTEGERP (X) || FLOATP (X)) \
2304 x_produce_stretch_glyph (it
)
2307 /* (space :width WIDTH :height HEIGHT. */
2309 extern Lisp_Object Qspace
;
2311 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
2312 extern Lisp_Object QCrelative_width
, QCrelative_height
;
2313 extern Lisp_Object QCalign_to
;
2314 Lisp_Object prop
, plist
;
2315 double width
= 0, height
= 0, ascent
= 0;
2316 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2317 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
2319 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
2321 /* List should start with `space'. */
2322 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
2323 plist
= XCDR (it
->object
);
2325 /* Compute the width of the stretch. */
2326 if (prop
= Fplist_get (plist
, QCwidth
),
2328 /* Absolute width `:width WIDTH' specified and valid. */
2329 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
2330 else if (prop
= Fplist_get (plist
, QCrelative_width
),
2333 /* Relative width `:relative-width FACTOR' specified and valid.
2334 Compute the width of the characters having the `glyph'
2337 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
2340 if (it
->multibyte_p
)
2342 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
2343 - IT_BYTEPOS (*it
));
2344 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
2347 it2
.c
= *p
, it2
.len
= 1;
2349 it2
.glyph_row
= NULL
;
2350 it2
.what
= IT_CHARACTER
;
2351 x_produce_glyphs (&it2
);
2352 width
= NUMVAL (prop
) * it2
.pixel_width
;
2354 else if (prop
= Fplist_get (plist
, QCalign_to
),
2356 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
2358 /* Nothing specified -> width defaults to canonical char width. */
2359 width
= CANON_X_UNIT (it
->f
);
2361 /* Compute height. */
2362 if (prop
= Fplist_get (plist
, QCheight
),
2364 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
2365 else if (prop
= Fplist_get (plist
, QCrelative_height
),
2367 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
2369 height
= FONT_HEIGHT (font
);
2371 /* Compute percentage of height used for ascent. If
2372 `:ascent ASCENT' is present and valid, use that. Otherwise,
2373 derive the ascent from the font in use. */
2374 if (prop
= Fplist_get (plist
, QCascent
),
2375 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
2376 ascent
= NUMVAL (prop
) / 100.0;
2378 ascent
= (double) FONT_BASE (font
) / FONT_HEIGHT (font
);
2387 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
2388 if (!STRINGP (object
))
2389 object
= it
->w
->buffer
;
2390 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
2393 it
->pixel_width
= width
;
2394 it
->ascent
= it
->phys_ascent
= height
* ascent
;
2395 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
2398 if (face
->box
!= FACE_NO_BOX
)
2400 if (face
->box_line_width
> 0)
2402 it
->ascent
+= face
->box_line_width
;
2403 it
->descent
+= face
->box_line_width
;
2406 if (it
->start_of_box_run_p
)
2407 it
->pixel_width
+= abs (face
->box_line_width
);
2408 if (it
->end_of_box_run_p
)
2409 it
->pixel_width
+= abs (face
->box_line_width
);
2412 take_vertical_position_into_account (it
);
2415 /* Return proper value to be used as baseline offset of font that has
2416 ASCENT and DESCENT to draw characters by the font at the vertical
2417 center of the line of frame F.
2419 Here, out task is to find the value of BOFF in the following figure;
2421 -------------------------+-----------+-
2422 -+-+---------+-+ | |
2424 | | | | F_ASCENT F_HEIGHT
2427 | | |-|-+------+-----------|------- baseline
2429 | |---------|-+-+ | |
2431 -+-+---------+-+ F_DESCENT |
2432 -------------------------+-----------+-
2434 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
2435 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
2436 DESCENT = FONT->descent
2437 HEIGHT = FONT_HEIGHT (FONT)
2438 F_DESCENT = (F->output_data.x->font->descent
2439 - F->output_data.x->baseline_offset)
2440 F_HEIGHT = FRAME_LINE_HEIGHT (F)
2443 #define VCENTER_BASELINE_OFFSET(FONT, F) \
2444 (FONT_DESCENT (FONT) \
2445 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
2446 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
2447 - (FONT_DESCENT (FRAME_FONT (F)) - FRAME_BASELINE_OFFSET (F)))
2449 /* Produce glyphs/get display metrics for the display element IT is
2450 loaded with. See the description of struct display_iterator in
2451 dispextern.h for an overview of struct display_iterator. */
2454 x_produce_glyphs (it
)
2457 it
->glyph_not_available_p
= 0;
2459 if (it
->what
== IT_CHARACTER
)
2463 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2465 int font_not_found_p
;
2466 struct font_info
*font_info
;
2467 int boff
; /* baseline offset */
2468 /* We may change it->multibyte_p upon unibyte<->multibyte
2469 conversion. So, save the current value now and restore it
2472 Note: It seems that we don't have to record multibyte_p in
2473 struct glyph because the character code itself tells if or
2474 not the character is multibyte. Thus, in the future, we must
2475 consider eliminating the field `multibyte_p' in the struct
2478 int saved_multibyte_p
= it
->multibyte_p
;
2480 /* Maybe translate single-byte characters to multibyte, or the
2482 it
->char_to_display
= it
->c
;
2483 if (!ASCII_BYTE_P (it
->c
))
2485 if (unibyte_display_via_language_environment
2486 && SINGLE_BYTE_CHAR_P (it
->c
)
2488 || !NILP (Vnonascii_translation_table
)))
2490 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2491 it
->multibyte_p
= 1;
2492 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2493 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2495 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
2496 && !it
->multibyte_p
)
2498 it
->multibyte_p
= 1;
2499 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2500 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2504 /* Get font to use. Encode IT->char_to_display. */
2505 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2506 it
->face_id
, &char2b
,
2510 /* When no suitable font found, use the default font. */
2511 font_not_found_p
= font
== NULL
;
2512 if (font_not_found_p
)
2514 font
= FRAME_FONT (it
->f
);
2515 boff
= it
->f
->output_data
.mac
->baseline_offset
;
2520 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2521 boff
= font_info
->baseline_offset
;
2522 if (font_info
->vertical_centering
)
2523 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2526 if (it
->char_to_display
>= ' '
2527 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
2529 /* Either unibyte or ASCII. */
2534 pcm
= x_per_char_metric (font
, &char2b
);
2535 it
->ascent
= FONT_BASE (font
) + boff
;
2536 it
->descent
= FONT_DESCENT (font
) - boff
;
2540 it
->phys_ascent
= pcm
->ascent
+ boff
;
2541 it
->phys_descent
= pcm
->descent
- boff
;
2542 it
->pixel_width
= pcm
->width
;
2546 it
->glyph_not_available_p
= 1;
2547 it
->phys_ascent
= FONT_BASE (font
) + boff
;
2548 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2549 it
->pixel_width
= FONT_WIDTH (font
);
2552 /* If this is a space inside a region of text with
2553 `space-width' property, change its width. */
2554 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
2556 it
->pixel_width
*= XFLOATINT (it
->space_width
);
2558 /* If face has a box, add the box thickness to the character
2559 height. If character has a box line to the left and/or
2560 right, add the box line width to the character's width. */
2561 if (face
->box
!= FACE_NO_BOX
)
2563 int thick
= face
->box_line_width
;
2567 it
->ascent
+= thick
;
2568 it
->descent
+= thick
;
2573 if (it
->start_of_box_run_p
)
2574 it
->pixel_width
+= thick
;
2575 if (it
->end_of_box_run_p
)
2576 it
->pixel_width
+= thick
;
2579 /* If face has an overline, add the height of the overline
2580 (1 pixel) and a 1 pixel margin to the character height. */
2581 if (face
->overline_p
)
2584 take_vertical_position_into_account (it
);
2586 /* If we have to actually produce glyphs, do it. */
2591 /* Translate a space with a `space-width' property
2592 into a stretch glyph. */
2593 double ascent
= (double) FONT_BASE (font
)
2594 / FONT_HEIGHT (font
);
2595 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
2596 it
->ascent
+ it
->descent
, ascent
);
2599 x_append_glyph (it
);
2601 /* If characters with lbearing or rbearing are displayed
2602 in this line, record that fact in a flag of the
2603 glyph row. This is used to optimize X output code. */
2604 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
2605 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2608 else if (it
->char_to_display
== '\n')
2610 /* A newline has no width but we need the height of the line. */
2611 it
->pixel_width
= 0;
2613 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
2614 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2616 if (face
->box
!= FACE_NO_BOX
2617 && face
->box_line_width
> 0)
2619 it
->ascent
+= face
->box_line_width
;
2620 it
->descent
+= face
->box_line_width
;
2623 else if (it
->char_to_display
== '\t')
2625 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
2626 int x
= it
->current_x
+ it
->continuation_lines_width
;
2627 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
2629 /* If the distance from the current position to the next tab
2630 stop is less than a canonical character width, use the
2631 tab stop after that. */
2632 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
2633 next_tab_x
+= tab_width
;
2635 it
->pixel_width
= next_tab_x
- x
;
2637 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
2638 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2642 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
2643 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
2644 it
->ascent
+ it
->descent
, ascent
);
2649 /* A multi-byte character. Assume that the display width of the
2650 character is the width of the character multiplied by the
2651 width of the font. */
2653 /* If we found a font, this font should give us the right
2654 metrics. If we didn't find a font, use the frame's
2655 default font and calculate the width of the character
2656 from the charset width; this is what old redisplay code
2658 pcm
= x_per_char_metric (font
, &char2b
);
2659 if (font_not_found_p
|| !pcm
)
2661 int charset
= CHAR_CHARSET (it
->char_to_display
);
2663 it
->glyph_not_available_p
= 1;
2664 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
2665 * CHARSET_WIDTH (charset
));
2666 it
->phys_ascent
= FONT_BASE (font
) + boff
;
2667 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
2671 it
->pixel_width
= pcm
->width
;
2672 it
->phys_ascent
= pcm
->ascent
+ boff
;
2673 it
->phys_descent
= pcm
->descent
- boff
;
2675 && (pcm
->lbearing
< 0
2676 || pcm
->rbearing
> pcm
->width
))
2677 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2680 it
->ascent
= FONT_BASE (font
) + boff
;
2681 it
->descent
= FONT_DESCENT (font
) - boff
;
2682 if (face
->box
!= FACE_NO_BOX
)
2684 int thick
= face
->box_line_width
;
2688 it
->ascent
+= thick
;
2689 it
->descent
+= thick
;
2694 if (it
->start_of_box_run_p
)
2695 it
->pixel_width
+= thick
;
2696 if (it
->end_of_box_run_p
)
2697 it
->pixel_width
+= thick
;
2700 /* If face has an overline, add the height of the overline
2701 (1 pixel) and a 1 pixel margin to the character height. */
2702 if (face
->overline_p
)
2705 take_vertical_position_into_account (it
);
2708 x_append_glyph (it
);
2710 it
->multibyte_p
= saved_multibyte_p
;
2712 else if (it
->what
== IT_COMPOSITION
)
2714 /* Note: A composition is represented as one glyph in the
2715 glyph matrix. There are no padding glyphs. */
2718 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2720 int font_not_found_p
;
2721 struct font_info
*font_info
;
2722 int boff
; /* baseline offset */
2723 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2725 /* Maybe translate single-byte characters to multibyte. */
2726 it
->char_to_display
= it
->c
;
2727 if (unibyte_display_via_language_environment
2728 && SINGLE_BYTE_CHAR_P (it
->c
)
2731 && !NILP (Vnonascii_translation_table
))))
2733 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2736 /* Get face and font to use. Encode IT->char_to_display. */
2737 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2738 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2739 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2740 it
->face_id
, &char2b
, it
->multibyte_p
);
2743 /* When no suitable font found, use the default font. */
2744 font_not_found_p
= font
== NULL
;
2745 if (font_not_found_p
)
2747 font
= FRAME_FONT (it
->f
);
2748 boff
= it
->f
->output_data
.mac
->baseline_offset
;
2753 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2754 boff
= font_info
->baseline_offset
;
2755 if (font_info
->vertical_centering
)
2756 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2759 /* There are no padding glyphs, so there is only one glyph to
2760 produce for the composition. Important is that pixel_width,
2761 ascent and descent are the values of what is drawn by
2762 draw_glyphs (i.e. the values of the overall glyphs composed). */
2765 /* If we have not yet calculated pixel size data of glyphs of
2766 the composition for the current face font, calculate them
2767 now. Theoretically, we have to check all fonts for the
2768 glyphs, but that requires much time and memory space. So,
2769 here we check only the font of the first glyph. This leads
2770 to incorrect display very rarely, and C-l (recenter) can
2771 correct the display anyway. */
2772 if (cmp
->font
!= (void *) font
)
2774 /* Ascent and descent of the font of the first character of
2775 this composition (adjusted by baseline offset). Ascent
2776 and descent of overall glyphs should not be less than
2777 them respectively. */
2778 int font_ascent
= FONT_BASE (font
) + boff
;
2779 int font_descent
= FONT_DESCENT (font
) - boff
;
2780 /* Bounding box of the overall glyphs. */
2781 int leftmost
, rightmost
, lowest
, highest
;
2782 int i
, width
, ascent
, descent
;
2784 cmp
->font
= (void *) font
;
2786 /* Initialize the bounding box. */
2787 pcm
= x_per_char_metric (font
, &char2b
);
2791 ascent
= pcm
->ascent
;
2792 descent
= pcm
->descent
;
2796 width
= FONT_WIDTH (font
);
2797 ascent
= FONT_BASE (font
);
2798 descent
= FONT_DESCENT (font
);
2802 lowest
= - descent
+ boff
;
2803 highest
= ascent
+ boff
;
2807 && font_info
->default_ascent
2808 && CHAR_TABLE_P (Vuse_default_ascent
)
2809 && !NILP (Faref (Vuse_default_ascent
,
2810 make_number (it
->char_to_display
))))
2811 highest
= font_info
->default_ascent
+ boff
;
2813 /* Draw the first glyph at the normal position. It may be
2814 shifted to right later if some other glyphs are drawn at
2816 cmp
->offsets
[0] = 0;
2817 cmp
->offsets
[1] = boff
;
2819 /* Set cmp->offsets for the remaining glyphs. */
2820 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2822 int left
, right
, btm
, top
;
2823 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2824 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2826 face
= FACE_FROM_ID (it
->f
, face_id
);
2827 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2832 font
= FRAME_FONT (it
->f
);
2833 boff
= it
->f
->output_data
.mac
->baseline_offset
;
2839 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2840 boff
= font_info
->baseline_offset
;
2841 if (font_info
->vertical_centering
)
2842 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2845 pcm
= x_per_char_metric (font
, &char2b
);
2849 ascent
= pcm
->ascent
;
2850 descent
= pcm
->descent
;
2854 width
= FONT_WIDTH (font
);
2859 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2861 /* Relative composition with or without
2863 left
= (leftmost
+ rightmost
- width
) / 2;
2864 btm
= - descent
+ boff
;
2865 if (font_info
&& font_info
->relative_compose
2866 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2867 || NILP (Faref (Vignore_relative_composition
,
2868 make_number (ch
)))))
2871 if (- descent
>= font_info
->relative_compose
)
2872 /* One extra pixel between two glyphs. */
2874 else if (ascent
<= 0)
2875 /* One extra pixel between two glyphs. */
2876 btm
= lowest
- 1 - ascent
- descent
;
2881 /* A composition rule is specified by an integer
2882 value that encodes global and new reference
2883 points (GREF and NREF). GREF and NREF are
2884 specified by numbers as below:
2892 ---3---4---5--- baseline
2894 6---7---8 -- descent
2896 int rule
= COMPOSITION_RULE (cmp
, i
);
2897 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2899 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2900 grefx
= gref
% 3, nrefx
= nref
% 3;
2901 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2904 + grefx
* (rightmost
- leftmost
) / 2
2905 - nrefx
* width
/ 2);
2906 btm
= ((grefy
== 0 ? highest
2908 : grefy
== 2 ? lowest
2909 : (highest
+ lowest
) / 2)
2910 - (nrefy
== 0 ? ascent
+ descent
2911 : nrefy
== 1 ? descent
- boff
2913 : (ascent
+ descent
) / 2));
2916 cmp
->offsets
[i
* 2] = left
;
2917 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2919 /* Update the bounding box of the overall glyphs. */
2920 right
= left
+ width
;
2921 top
= btm
+ descent
+ ascent
;
2922 if (left
< leftmost
)
2924 if (right
> rightmost
)
2932 /* If there are glyphs whose x-offsets are negative,
2933 shift all glyphs to the right and make all x-offsets
2937 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2938 cmp
->offsets
[i
* 2] -= leftmost
;
2939 rightmost
-= leftmost
;
2942 cmp
->pixel_width
= rightmost
;
2943 cmp
->ascent
= highest
;
2944 cmp
->descent
= - lowest
;
2945 if (cmp
->ascent
< font_ascent
)
2946 cmp
->ascent
= font_ascent
;
2947 if (cmp
->descent
< font_descent
)
2948 cmp
->descent
= font_descent
;
2951 it
->pixel_width
= cmp
->pixel_width
;
2952 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2953 it
->descent
= it
->phys_descent
= cmp
->descent
;
2955 if (face
->box
!= FACE_NO_BOX
)
2957 int thick
= face
->box_line_width
;
2961 it
->ascent
+= thick
;
2962 it
->descent
+= thick
;
2967 if (it
->start_of_box_run_p
)
2968 it
->pixel_width
+= thick
;
2969 if (it
->end_of_box_run_p
)
2970 it
->pixel_width
+= thick
;
2973 /* If face has an overline, add the height of the overline
2974 (1 pixel) and a 1 pixel margin to the character height. */
2975 if (face
->overline_p
)
2978 take_vertical_position_into_account (it
);
2981 x_append_composite_glyph (it
);
2983 else if (it
->what
== IT_IMAGE
)
2984 x_produce_image_glyph (it
);
2985 else if (it
->what
== IT_STRETCH
)
2986 x_produce_stretch_glyph (it
);
2988 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2989 because this isn't true for images with `:ascent 100'. */
2990 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2991 if (it
->area
== TEXT_AREA
)
2992 it
->current_x
+= it
->pixel_width
;
2994 it
->descent
+= it
->extra_line_spacing
;
2996 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2997 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2998 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2999 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
3003 /* Estimate the pixel height of the mode or top line on frame F.
3004 FACE_ID specifies what line's height to estimate. */
3007 x_estimate_mode_line_height (f
, face_id
)
3009 enum face_id face_id
;
3011 int height
= FONT_HEIGHT (FRAME_FONT (f
));
3013 /* This function is called so early when Emacs starts that the face
3014 cache and mode line face are not yet initialized. */
3015 if (FRAME_FACE_CACHE (f
))
3017 struct face
*face
= FACE_FROM_ID (f
, face_id
);
3021 height
= FONT_HEIGHT (face
->font
);
3022 if (face
->box_line_width
> 0)
3023 height
+= 2 * face
->box_line_width
;
3031 /***********************************************************************
3033 ***********************************************************************/
3035 /* A sequence of glyphs to be drawn in the same face.
3037 This data structure is not really completely X specific, so it
3038 could possibly, at least partially, be useful for other systems. It
3039 is currently not part of the external redisplay interface because
3040 it's not clear what other systems will need. */
3044 /* X-origin of the string. */
3047 /* Y-origin and y-position of the base line of this string. */
3050 /* The width of the string, not including a face extension. */
3053 /* The width of the string, including a face extension. */
3054 int background_width
;
3056 /* The height of this string. This is the height of the line this
3057 string is drawn in, and can be different from the height of the
3058 font the string is drawn in. */
3061 /* Number of pixels this string overwrites in front of its x-origin.
3062 This number is zero if the string has an lbearing >= 0; it is
3063 -lbearing, if the string has an lbearing < 0. */
3066 /* Number of pixels this string overwrites past its right-most
3067 nominal x-position, i.e. x + width. Zero if the string's
3068 rbearing is <= its nominal width, rbearing - width otherwise. */
3071 /* The frame on which the glyph string is drawn. */
3074 /* The window on which the glyph string is drawn. */
3077 /* X display and window for convenience. */
3081 /* The glyph row for which this string was built. It determines the
3082 y-origin and height of the string. */
3083 struct glyph_row
*row
;
3085 /* The area within row. */
3086 enum glyph_row_area area
;
3088 /* Characters to be drawn, and number of characters. */
3092 /* A face-override for drawing cursors, mouse face and similar. */
3093 enum draw_glyphs_face hl
;
3095 /* Face in which this string is to be drawn. */
3098 /* Font in which this string is to be drawn. */
3101 /* Font info for this string. */
3102 struct font_info
*font_info
;
3104 /* Non-null means this string describes (part of) a composition.
3105 All characters from char2b are drawn composed. */
3106 struct composition
*cmp
;
3108 /* Index of this glyph string's first character in the glyph
3109 definition of CMP. If this is zero, this glyph string describes
3110 the first character of a composition. */
3113 /* 1 means this glyph strings face has to be drawn to the right end
3114 of the window's drawing area. */
3115 unsigned extends_to_end_of_line_p
: 1;
3117 /* 1 means the background of this string has been drawn. */
3118 unsigned background_filled_p
: 1;
3120 /* 1 means glyph string must be drawn with 16-bit functions. */
3121 unsigned two_byte_p
: 1;
3123 /* 1 means that the original font determined for drawing this glyph
3124 string could not be loaded. The member `font' has been set to
3125 the frame's default font in this case. */
3126 unsigned font_not_found_p
: 1;
3128 /* 1 means that the face in which this glyph string is drawn has a
3130 unsigned stippled_p
: 1;
3132 /* 1 means only the foreground of this glyph string must be drawn,
3133 and we should use the physical height of the line this glyph
3134 string appears in as clip rect. */
3135 unsigned for_overlaps_p
: 1;
3137 /* The GC to use for drawing this glyph string. */
3140 /* A pointer to the first glyph in the string. This glyph
3141 corresponds to char2b[0]. Needed to draw rectangles if
3142 font_not_found_p is 1. */
3143 struct glyph
*first_glyph
;
3145 /* Image, if any. */
3148 struct glyph_string
*next
, *prev
;
3155 x_dump_glyph_string (s
)
3156 struct glyph_string
*s
;
3158 fprintf (stderr
, "glyph string\n");
3159 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
3160 s
->x
, s
->y
, s
->width
, s
->height
);
3161 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
3162 fprintf (stderr
, " hl = %d\n", s
->hl
);
3163 fprintf (stderr
, " left overhang = %d, right = %d\n",
3164 s
->left_overhang
, s
->right_overhang
);
3165 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
3166 fprintf (stderr
, " extends to end of line = %d\n",
3167 s
->extends_to_end_of_line_p
);
3168 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
3169 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
3172 #endif /* GLYPH_DEBUG */
3176 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
3177 struct glyph_string
**,
3178 struct glyph_string
*,
3179 struct glyph_string
*));
3180 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
3181 struct glyph_string
**,
3182 struct glyph_string
*,
3183 struct glyph_string
*));
3184 static void x_append_glyph_string
P_ ((struct glyph_string
**,
3185 struct glyph_string
**,
3186 struct glyph_string
*));
3187 static int x_left_overwritten
P_ ((struct glyph_string
*));
3188 static int x_left_overwriting
P_ ((struct glyph_string
*));
3189 static int x_right_overwritten
P_ ((struct glyph_string
*));
3190 static int x_right_overwriting
P_ ((struct glyph_string
*));
3191 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
3193 static void x_init_glyph_string
P_ ((struct glyph_string
*,
3194 XChar2b
*, struct window
*,
3196 enum glyph_row_area
, int,
3197 enum draw_glyphs_face
));
3198 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
3199 enum glyph_row_area
, int, int,
3200 enum draw_glyphs_face
, int));
3201 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
3202 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
3203 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
3205 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
3206 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
3207 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
3208 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
3209 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
3210 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
3211 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
3212 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
3213 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
3215 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
3216 /*static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap,
3217 unsigned long *, double, int));*/
3218 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
3219 double, int, unsigned long));
3220 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
3221 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
3222 static void x_draw_image_relief
P_ ((struct glyph_string
*));
3223 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
3224 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
3225 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
3226 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
3228 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
3229 int, int, int, int, Rect
*));
3230 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
3231 int, int, int, Rect
*));
3232 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
3233 enum glyph_row_area
));
3234 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
3236 enum glyph_row_area
, int, int));
3239 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
3243 /* Append the list of glyph strings with head H and tail T to the list
3244 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
3247 x_append_glyph_string_lists (head
, tail
, h
, t
)
3248 struct glyph_string
**head
, **tail
;
3249 struct glyph_string
*h
, *t
;
3263 /* Prepend the list of glyph strings with head H and tail T to the
3264 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
3268 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
3269 struct glyph_string
**head
, **tail
;
3270 struct glyph_string
*h
, *t
;
3284 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
3285 Set *HEAD and *TAIL to the resulting list. */
3288 x_append_glyph_string (head
, tail
, s
)
3289 struct glyph_string
**head
, **tail
;
3290 struct glyph_string
*s
;
3292 s
->next
= s
->prev
= NULL
;
3293 x_append_glyph_string_lists (head
, tail
, s
, s
);
3297 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
3302 struct glyph_string
*s
;
3304 if (s
->font
== FRAME_FONT (s
->f
)
3305 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
3306 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
3308 s
->gc
= s
->f
->output_data
.mac
->cursor_gc
;
3311 /* Cursor on non-default face: must merge. */
3315 xgcv
.background
= s
->f
->output_data
.mac
->cursor_pixel
;
3316 xgcv
.foreground
= s
->face
->background
;
3318 /* If the glyph would be invisible, try a different foreground. */
3319 if (xgcv
.foreground
== xgcv
.background
)
3320 xgcv
.foreground
= s
->face
->foreground
;
3321 if (xgcv
.foreground
== xgcv
.background
)
3322 xgcv
.foreground
= s
->f
->output_data
.mac
->cursor_foreground_pixel
;
3323 if (xgcv
.foreground
== xgcv
.background
)
3324 xgcv
.foreground
= s
->face
->foreground
;
3326 /* Make sure the cursor is distinct from text in this face. */
3327 if (xgcv
.background
== s
->face
->background
3328 && xgcv
.foreground
== s
->face
->foreground
)
3330 xgcv
.background
= s
->face
->foreground
;
3331 xgcv
.foreground
= s
->face
->background
;
3334 IF_DEBUG (x_check_font (s
->f
, s
->font
));
3335 xgcv
.font
= s
->font
;
3336 mask
= GCForeground
| GCBackground
| GCFont
;
3338 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
3339 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
3342 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
3343 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
3345 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
3350 /* Set up S->gc of glyph string S for drawing text in mouse face. */
3353 x_set_mouse_face_gc (s
)
3354 struct glyph_string
*s
;
3359 /* What face has to be used last for the mouse face? */
3360 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
3361 face
= FACE_FROM_ID (s
->f
, face_id
);
3363 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
3365 if (s
->first_glyph
->type
== CHAR_GLYPH
)
3366 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
3368 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
3369 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
3370 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
3372 /* If font in this face is same as S->font, use it. */
3373 if (s
->font
== s
->face
->font
)
3374 s
->gc
= s
->face
->gc
;
3377 /* Otherwise construct scratch_cursor_gc with values from FACE
3382 xgcv
.background
= s
->face
->background
;
3383 xgcv
.foreground
= s
->face
->foreground
;
3384 IF_DEBUG (x_check_font (s
->f
, s
->font
));
3385 xgcv
.font
= s
->font
;
3386 mask
= GCForeground
| GCBackground
| GCFont
;
3388 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
3389 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
3392 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
3393 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
3395 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
3398 xassert (s
->gc
!= 0);
3402 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
3403 Faces to use in the mode line have already been computed when the
3404 matrix was built, so there isn't much to do, here. */
3407 x_set_mode_line_face_gc (s
)
3408 struct glyph_string
*s
;
3410 s
->gc
= s
->face
->gc
;
3414 /* Set S->gc of glyph string S for drawing that glyph string. Set
3415 S->stippled_p to a non-zero value if the face of S has a stipple
3419 x_set_glyph_string_gc (s
)
3420 struct glyph_string
*s
;
3422 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
3424 if (s
->hl
== DRAW_NORMAL_TEXT
)
3426 s
->gc
= s
->face
->gc
;
3427 s
->stippled_p
= s
->face
->stipple
!= 0;
3429 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
3431 x_set_mode_line_face_gc (s
);
3432 s
->stippled_p
= s
->face
->stipple
!= 0;
3434 else if (s
->hl
== DRAW_CURSOR
)
3436 x_set_cursor_gc (s
);
3439 else if (s
->hl
== DRAW_MOUSE_FACE
)
3441 x_set_mouse_face_gc (s
);
3442 s
->stippled_p
= s
->face
->stipple
!= 0;
3444 else if (s
->hl
== DRAW_IMAGE_RAISED
3445 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3447 s
->gc
= s
->face
->gc
;
3448 s
->stippled_p
= s
->face
->stipple
!= 0;
3452 s
->gc
= s
->face
->gc
;
3453 s
->stippled_p
= s
->face
->stipple
!= 0;
3456 /* GC must have been set. */
3457 xassert (s
->gc
!= 0);
3461 /* Return in *R the clipping rectangle for glyph string S. */
3464 x_get_glyph_string_clip_rect (s
, r
)
3465 struct glyph_string
*s
;
3468 int r_height
, r_width
;
3470 if (s
->row
->full_width_p
)
3472 /* Draw full-width. X coordinates are relative to S->w->left. */
3473 int canon_x
= CANON_X_UNIT (s
->f
);
3475 r
->left
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
3476 r_width
= XFASTINT (s
->w
->width
) * canon_x
;
3478 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
3480 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
3481 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
3485 r
->left
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
3487 /* Unless displaying a mode or menu bar line, which are always
3488 fully visible, clip to the visible part of the row. */
3489 if (s
->w
->pseudo_window_p
)
3490 r_height
= s
->row
->visible_height
;
3492 r_height
= s
->height
;
3496 /* This is a text line that may be partially visible. */
3497 r
->left
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
3498 r_width
= window_box_width (s
->w
, s
->area
);
3499 r_height
= s
->row
->visible_height
;
3502 /* If S draws overlapping rows, it's sufficient to use the top and
3503 bottom of the window for clipping because this glyph string
3504 intentionally draws over other lines. */
3505 if (s
->for_overlaps_p
)
3507 r
->top
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
3508 r_height
= window_text_bottom_y (s
->w
) - r
->top
;
3512 /* Don't use S->y for clipping because it doesn't take partially
3513 visible lines into account. For example, it can be negative for
3514 partially visible lines at the top of a window. */
3515 if (!s
->row
->full_width_p
3516 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
3517 r
->top
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
3519 r
->top
= max (0, s
->row
->y
);
3521 /* If drawing a tool-bar window, draw it over the internal border
3522 at the top of the window. */
3523 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
3524 r
->top
-= s
->f
->output_data
.mac
->internal_border_width
;
3527 r
->top
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->top
);
3529 r
->bottom
= r
->top
+ r_height
;
3530 r
->right
= r
->left
+ r_width
;
3534 /* Set clipping for output of glyph string S. S may be part of a mode
3535 line or menu if we don't have X toolkit support. */
3538 x_set_glyph_string_clipping (s
)
3539 struct glyph_string
*s
;
3542 x_get_glyph_string_clip_rect (s
, &r
);
3543 mac_set_clip_rectangle (s
->display
, s
->window
, &r
);
3547 /* Compute left and right overhang of glyph string S. If S is a glyph
3548 string for a composition, assume overhangs don't exist. */
3551 x_compute_glyph_string_overhangs (s
)
3552 struct glyph_string
*s
;
3555 && s
->first_glyph
->type
== CHAR_GLYPH
)
3558 int direction
, font_ascent
, font_descent
;
3559 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
3560 &font_ascent
, &font_descent
, &cs
);
3561 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
3562 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
3567 /* Compute overhangs and x-positions for glyph string S and its
3568 predecessors, or successors. X is the starting x-position for S.
3569 BACKWARD_P non-zero means process predecessors. */
3572 x_compute_overhangs_and_x (s
, x
, backward_p
)
3573 struct glyph_string
*s
;
3581 x_compute_glyph_string_overhangs (s
);
3591 x_compute_glyph_string_overhangs (s
);
3600 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
3601 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
3602 assumed to be zero. */
3605 x_get_glyph_overhangs (glyph
, f
, left
, right
)
3606 struct glyph
*glyph
;
3612 if (glyph
->type
== CHAR_GLYPH
)
3616 struct font_info
*font_info
;
3620 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
3622 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
3624 && (pcm
= x_per_char_metric (font
, &char2b
)))
3626 if (pcm
->rbearing
> pcm
->width
)
3627 *right
= pcm
->rbearing
- pcm
->width
;
3628 if (pcm
->lbearing
< 0)
3629 *left
= -pcm
->lbearing
;
3635 /* Return the index of the first glyph preceding glyph string S that
3636 is overwritten by S because of S's left overhang. Value is -1
3637 if no glyphs are overwritten. */
3640 x_left_overwritten (s
)
3641 struct glyph_string
*s
;
3645 if (s
->left_overhang
)
3648 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3649 int first
= s
->first_glyph
- glyphs
;
3651 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
3652 x
-= glyphs
[i
].pixel_width
;
3663 /* Return the index of the first glyph preceding glyph string S that
3664 is overwriting S because of its right overhang. Value is -1 if no
3665 glyph in front of S overwrites S. */
3668 x_left_overwriting (s
)
3669 struct glyph_string
*s
;
3672 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3673 int first
= s
->first_glyph
- glyphs
;
3677 for (i
= first
- 1; i
>= 0; --i
)
3680 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3683 x
-= glyphs
[i
].pixel_width
;
3690 /* Return the index of the last glyph following glyph string S that is
3691 not overwritten by S because of S's right overhang. Value is -1 if
3692 no such glyph is found. */
3695 x_right_overwritten (s
)
3696 struct glyph_string
*s
;
3700 if (s
->right_overhang
)
3703 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3704 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3705 int end
= s
->row
->used
[s
->area
];
3707 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3708 x
+= glyphs
[i
].pixel_width
;
3717 /* Return the index of the last glyph following glyph string S that
3718 overwrites S because of its left overhang. Value is negative
3719 if no such glyph is found. */
3722 x_right_overwriting (s
)
3723 struct glyph_string
*s
;
3726 int end
= s
->row
->used
[s
->area
];
3727 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3728 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3732 for (i
= first
; i
< end
; ++i
)
3735 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3738 x
+= glyphs
[i
].pixel_width
;
3745 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3748 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3749 struct glyph_string
*s
;
3754 xgcv
.foreground
= s
->gc
->background
;
3755 XFillRectangle (s
->display
, s
->window
, &xgcv
, x
, y
, w
, h
);
3759 /* Draw the background of glyph_string S. If S->background_filled_p
3760 is non-zero don't draw it. FORCE_P non-zero means draw the
3761 background even if it wouldn't be drawn normally. This is used
3762 when a string preceding S draws into the background of S, or S
3763 contains the first component of a composition. */
3766 x_draw_glyph_string_background (s
, force_p
)
3767 struct glyph_string
*s
;
3770 /* Nothing to do if background has already been drawn or if it
3771 shouldn't be drawn in the first place. */
3772 if (!s
->background_filled_p
)
3774 int box_line_width
= max (s
->face
->box_line_width
, 0);
3776 #if 0 /* MAC_TODO: stipple */
3779 /* Fill background with a stipple pattern. */
3780 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3781 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3782 s
->y
+ box_line_width
,
3783 s
->background_width
,
3784 s
->height
- 2 * box_line_width
);
3785 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3786 s
->background_filled_p
= 1;
3790 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3791 || s
->font_not_found_p
3792 || s
->extends_to_end_of_line_p
3795 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3796 s
->background_width
,
3797 s
->height
- 2 * box_line_width
);
3798 s
->background_filled_p
= 1;
3804 /* Draw the foreground of glyph string S. */
3807 x_draw_glyph_string_foreground (s
)
3808 struct glyph_string
*s
;
3812 /* If first glyph of S has a left box line, start drawing the text
3813 of S to the right of that box line. */
3814 if (s
->face
->box
!= FACE_NO_BOX
3815 && s
->first_glyph
->left_box_line_p
)
3816 x
= s
->x
+ abs (s
->face
->box_line_width
);
3820 /* Draw characters of S as rectangles if S's font could not be
3822 if (s
->font_not_found_p
)
3824 for (i
= 0; i
< s
->nchars
; ++i
)
3826 struct glyph
*g
= s
->first_glyph
+ i
;
3827 mac_draw_rectangle (s
->display
, s
->window
,
3828 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3830 x
+= g
->pixel_width
;
3835 char *char1b
= (char *) s
->char2b
;
3836 int boff
= s
->font_info
->baseline_offset
;
3838 if (s
->font_info
->vertical_centering
)
3839 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3841 /* If we can use 8-bit functions, condense S->char2b. */
3843 for (i
= 0; i
< s
->nchars
; ++i
)
3844 char1b
[i
] = s
->char2b
[i
].byte2
;
3846 /* Draw text with XDrawString if background has already been
3847 filled. Otherwise, use XDrawImageString. (Note that
3848 XDrawImageString is usually faster than XDrawString.) Always
3849 use XDrawImageString when drawing the cursor so that there is
3850 no chance that characters under a box cursor are invisible. */
3851 if (s
->for_overlaps_p
3852 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3854 /* Draw characters with 16-bit or 8-bit functions. */
3856 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3857 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3859 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3860 s
->ybase
- boff
, char1b
, s
->nchars
);
3865 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3866 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3868 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3869 s
->ybase
- boff
, char1b
, s
->nchars
);
3874 /* Draw the foreground of composite glyph string S. */
3877 x_draw_composite_glyph_string_foreground (s
)
3878 struct glyph_string
*s
;
3882 /* If first glyph of S has a left box line, start drawing the text
3883 of S to the right of that box line. */
3884 if (s
->face
->box
!= FACE_NO_BOX
3885 && s
->first_glyph
->left_box_line_p
)
3886 x
= s
->x
+ abs (s
->face
->box_line_width
);
3890 /* S is a glyph string for a composition. S->gidx is the index of
3891 the first character drawn for glyphs of this composition.
3892 S->gidx == 0 means we are drawing the very first character of
3893 this composition. */
3895 /* Draw a rectangle for the composition if the font for the very
3896 first character of the composition could not be loaded. */
3897 if (s
->font_not_found_p
)
3900 mac_draw_rectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3901 s
->width
- 1, s
->height
- 1);
3905 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3906 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3907 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3908 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3914 #ifdef USE_X_TOOLKIT
3916 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3919 /* Return the frame on which widget WIDGET is used.. Abort if frame
3920 cannot be determined. */
3922 static struct frame
*
3923 x_frame_of_widget (widget
)
3926 struct x_display_info
*dpyinfo
;
3930 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3932 /* Find the top-level shell of the widget. Note that this function
3933 can be called when the widget is not yet realized, so XtWindow
3934 (widget) == 0. That's the reason we can't simply use
3935 x_any_window_to_frame. */
3936 while (!XtIsTopLevelShell (widget
))
3937 widget
= XtParent (widget
);
3939 /* Look for a frame with that top-level widget. Allocate the color
3940 on that frame to get the right gamma correction value. */
3941 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3942 if (GC_FRAMEP (XCAR (tail
))
3943 && (f
= XFRAME (XCAR (tail
)),
3944 (f
->output_data
.nothing
!= 1
3945 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3946 && f
->output_data
.x
->widget
== widget
)
3953 /* Allocate the color COLOR->pixel on the screen and display of
3954 widget WIDGET in colormap CMAP. If an exact match cannot be
3955 allocated, try the nearest color available. Value is non-zero
3956 if successful. This is called from lwlib. */
3959 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3964 struct frame
*f
= x_frame_of_widget (widget
);
3965 return x_alloc_nearest_color (f
, cmap
, color
);
3969 #endif /* USE_X_TOOLKIT */
3971 #if 0 /* MAC_TODO */
3973 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
3974 CMAP. If an exact match can't be allocated, try the nearest color
3975 available. Value is non-zero if successful. Set *COLOR to the
3979 x_alloc_nearest_color (f
, cmap
, color
)
3984 Display
*display
= FRAME_X_DISPLAY (f
);
3985 Screen
*screen
= FRAME_X_SCREEN (f
);
3988 gamma_correct (f
, color
);
3989 rc
= XAllocColor (display
, cmap
, color
);
3992 /* If we got to this point, the colormap is full, so we're going
3993 to try to get the next closest color. The algorithm used is
3994 a least-squares matching, which is what X uses for closest
3995 color matching with StaticColor visuals. */
3997 unsigned long nearest_delta
= ~0;
3998 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3999 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
4001 for (i
= 0; i
< ncells
; ++i
)
4003 XQueryColors (display
, cmap
, cells
, ncells
);
4005 for (nearest
= i
= 0; i
< ncells
; ++i
)
4007 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
4008 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
4009 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
4010 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
4012 if (delta
< nearest_delta
)
4015 nearest_delta
= delta
;
4019 color
->red
= cells
[nearest
].red
;
4020 color
->green
= cells
[nearest
].green
;
4021 color
->blue
= cells
[nearest
].blue
;
4022 rc
= XAllocColor (display
, cmap
, color
);
4025 #ifdef DEBUG_X_COLORS
4027 register_color (color
->pixel
);
4028 #endif /* DEBUG_X_COLORS */
4034 /* Allocate color PIXEL on frame F. 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_color (f
, pixel
)
4041 unsigned long pixel
;
4045 color
.pixel
= pixel
;
4047 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
4048 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
4050 #ifdef DEBUG_X_COLORS
4051 register_color (pixel
);
4057 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
4058 It's necessary to do this instead of just using PIXEL directly to
4059 get color reference counts right. */
4062 x_copy_dpy_color (dpy
, cmap
, pixel
)
4065 unsigned long pixel
;
4069 color
.pixel
= pixel
;
4071 XQueryColor (dpy
, cmap
, &color
);
4072 XAllocColor (dpy
, cmap
, &color
);
4074 #ifdef DEBUG_X_COLORS
4075 register_color (pixel
);
4080 #endif /* MAC_TODO */
4082 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
4083 or DELTA. Try a color with RGB values multiplied by FACTOR first.
4084 If this produces the same color as COLOR, try a color where all RGB
4085 values have DELTA added. Return the allocated color in *COLOR.
4086 DISPLAY is the X display, CMAP is the colormap to operate on.
4087 Value is non-zero if successful. */
4090 mac_alloc_lighter_color (f
, color
, factor
, delta
)
4092 unsigned long *color
;
4098 /* Change RGB values by specified FACTOR. Avoid overflow! */
4099 xassert (factor
>= 0);
4100 new = RGB_TO_ULONG (min (0xff, (int) (factor
* RED_FROM_ULONG (*color
))),
4101 min (0xff, (int) (factor
* GREEN_FROM_ULONG (*color
))),
4102 min (0xff, (int) (factor
* BLUE_FROM_ULONG (*color
))));
4104 new = RGB_TO_ULONG (max (0, min (0xff, (int) (delta
+ RED_FROM_ULONG (*color
)))),
4105 max (0, min (0xff, (int) (delta
+ GREEN_FROM_ULONG (*color
)))),
4106 max (0, min (0xff, (int) (delta
+ BLUE_FROM_ULONG (*color
)))));
4108 /* MAC_TODO: Map to palette and retry with delta if same? */
4109 /* MAC_TODO: Free colors (if using palette)? */
4120 /* Set up the foreground color for drawing relief lines of glyph
4121 string S. RELIEF is a pointer to a struct relief containing the GC
4122 with which lines will be drawn. Use a color that is FACTOR or
4123 DELTA lighter or darker than the relief's background which is found
4124 in S->f->output_data.x->relief_background. If such a color cannot
4125 be allocated, use DEFAULT_PIXEL, instead. */
4128 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
4130 struct relief
*relief
;
4133 unsigned long default_pixel
;
4136 struct mac_output
*di
= f
->output_data
.mac
;
4137 unsigned long mask
= GCForeground
;
4138 unsigned long pixel
;
4139 unsigned long background
= di
->relief_background
;
4140 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
4142 /* MAC_TODO: Free colors (if using palette)? */
4144 /* Allocate new color. */
4145 xgcv
.foreground
= default_pixel
;
4147 if (mac_alloc_lighter_color (f
, &pixel
, factor
, delta
))
4149 relief
->allocated_p
= 1;
4150 xgcv
.foreground
= relief
->pixel
= pixel
;
4153 if (relief
->gc
== 0)
4155 #if 0 /* MAC_TODO: stipple */
4156 xgcv
.stipple
= dpyinfo
->gray
;
4159 relief
->gc
= XCreateGC (NULL
, FRAME_MAC_WINDOW (f
), mask
, &xgcv
);
4162 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
4166 /* Set up colors for the relief lines around glyph string S. */
4169 x_setup_relief_colors (s
)
4170 struct glyph_string
*s
;
4172 struct mac_output
*di
= s
->f
->output_data
.mac
;
4173 unsigned long color
;
4175 if (s
->face
->use_box_color_for_shadows_p
)
4176 color
= s
->face
->box_color
;
4181 /* Get the background color of the face. */
4182 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
4183 color
= xgcv
.background
;
4186 if (di
->white_relief
.gc
== 0
4187 || color
!= di
->relief_background
)
4189 di
->relief_background
= color
;
4190 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
4191 WHITE_PIX_DEFAULT (s
->f
));
4192 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
4193 BLACK_PIX_DEFAULT (s
->f
));
4198 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
4199 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
4200 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
4201 relief. LEFT_P non-zero means draw a relief on the left side of
4202 the rectangle. RIGHT_P non-zero means draw a relief on the right
4203 side of the rectangle. CLIP_RECT is the clipping rectangle to use
4207 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
4208 raised_p
, left_p
, right_p
, clip_rect
)
4210 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
4217 gc
= f
->output_data
.mac
->white_relief
.gc
;
4219 gc
= f
->output_data
.mac
->black_relief
.gc
;
4220 mac_set_clip_rectangle (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), clip_rect
);
4223 for (i
= 0; i
< width
; ++i
)
4224 XDrawLine (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), gc
,
4225 left_x
+ i
* left_p
, top_y
+ i
,
4226 right_x
+ 1 - i
* right_p
, top_y
+ i
);
4230 for (i
= 0; i
< width
; ++i
)
4231 XDrawLine (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), gc
,
4232 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
4234 mac_reset_clipping (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
));
4236 gc
= f
->output_data
.mac
->black_relief
.gc
;
4238 gc
= f
->output_data
.mac
->white_relief
.gc
;
4239 mac_set_clip_rectangle (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
4243 for (i
= 0; i
< width
; ++i
)
4244 XDrawLine (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), gc
,
4245 left_x
+ i
* left_p
, bottom_y
- i
,
4246 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
4250 for (i
= 0; i
< width
; ++i
)
4251 XDrawLine (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), gc
,
4252 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
4254 mac_reset_clipping (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
));
4258 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
4259 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
4260 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
4261 left side of the rectangle. RIGHT_P non-zero means draw a line
4262 on the right side of the rectangle. CLIP_RECT is the clipping
4263 rectangle to use when drawing. */
4266 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
4267 left_p
, right_p
, clip_rect
)
4268 struct glyph_string
*s
;
4269 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
4274 xgcv
.foreground
= s
->face
->box_color
;
4275 mac_set_clip_rectangle (s
->display
, s
->window
, clip_rect
);
4278 XFillRectangle (s
->display
, s
->window
, &xgcv
,
4279 left_x
, top_y
, right_x
- left_x
, width
);
4283 XFillRectangle (s
->display
, s
->window
, &xgcv
,
4284 left_x
, top_y
, width
, bottom_y
- top_y
);
4287 XFillRectangle (s
->display
, s
->window
, &xgcv
,
4288 left_x
, bottom_y
- width
, right_x
- left_x
, width
);
4292 XFillRectangle (s
->display
, s
->window
, &xgcv
,
4293 right_x
- width
, top_y
, width
, bottom_y
- top_y
);
4295 mac_reset_clipping (s
->display
, s
->window
);
4299 /* Draw a box around glyph string S. */
4302 x_draw_glyph_string_box (s
)
4303 struct glyph_string
*s
;
4305 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
4306 int left_p
, right_p
;
4307 struct glyph
*last_glyph
;
4310 last_x
= window_box_right (s
->w
, s
->area
);
4311 if (s
->row
->full_width_p
4312 && !s
->w
->pseudo_window_p
)
4314 last_x
+= FRAME_X_RIGHT_FRINGE_WIDTH (s
->f
);
4315 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
4316 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
4319 /* The glyph that may have a right box line. */
4320 last_glyph
= (s
->cmp
|| s
->img
4322 : s
->first_glyph
+ s
->nchars
- 1);
4324 width
= abs (s
->face
->box_line_width
);
4325 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
4327 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
4329 : min (last_x
, s
->x
+ s
->background_width
) - 1));
4331 bottom_y
= top_y
+ s
->height
- 1;
4333 left_p
= (s
->first_glyph
->left_box_line_p
4334 || (s
->hl
== DRAW_MOUSE_FACE
4336 || s
->prev
->hl
!= s
->hl
)));
4337 right_p
= (last_glyph
->right_box_line_p
4338 || (s
->hl
== DRAW_MOUSE_FACE
4340 || s
->next
->hl
!= s
->hl
)));
4342 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4344 if (s
->face
->box
== FACE_SIMPLE_BOX
)
4345 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
4346 left_p
, right_p
, &clip_rect
);
4349 x_setup_relief_colors (s
);
4350 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
4351 width
, raised_p
, left_p
, right_p
, &clip_rect
);
4356 /* Draw foreground of image glyph string S. */
4359 x_draw_image_foreground (s
)
4360 struct glyph_string
*s
;
4363 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4365 /* If first glyph of S has a left box line, start drawing it to the
4366 right of that line. */
4367 if (s
->face
->box
!= FACE_NO_BOX
4368 && s
->first_glyph
->left_box_line_p
)
4369 x
= s
->x
+ abs (s
->face
->box_line_width
);
4373 /* If there is a margin around the image, adjust x- and y-position
4375 x
+= s
->img
->hmargin
;
4376 y
+= s
->img
->vmargin
;
4380 #if 0 /* MAC_TODO: image mask */
4383 /* We can't set both a clip mask and use XSetClipRectangles
4384 because the latter also sets a clip mask. We also can't
4385 trust on the shape extension to be available
4386 (XShapeCombineRegion). So, compute the rectangle to draw
4388 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4391 XRectangle clip_rect
, image_rect
, r
;
4393 xgcv
.clip_mask
= s
->img
->mask
;
4394 xgcv
.clip_x_origin
= x
;
4395 xgcv
.clip_y_origin
= y
;
4396 xgcv
.function
= GXcopy
;
4397 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4399 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4402 image_rect
.width
= s
->img
->width
;
4403 image_rect
.height
= s
->img
->height
;
4404 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4405 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4406 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4409 #endif /* MAC_TODO */
4411 mac_copy_area (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4412 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4414 /* When the image has a mask, we can expect that at
4415 least part of a mouse highlight or a block cursor will
4416 be visible. If the image doesn't have a mask, make
4417 a block cursor visible by drawing a rectangle around
4418 the image. I believe it's looking better if we do
4419 nothing here for mouse-face. */
4420 if (s
->hl
== DRAW_CURSOR
)
4422 int r
= s
->img
->relief
;
4424 mac_draw_rectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
4425 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
4430 /* Draw a rectangle if image could not be loaded. */
4431 mac_draw_rectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4432 s
->img
->width
- 1, s
->img
->height
- 1);
4437 /* Draw a relief around the image glyph string S. */
4440 x_draw_image_relief (s
)
4441 struct glyph_string
*s
;
4443 int x0
, y0
, x1
, y1
, thick
, raised_p
;
4446 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4448 /* If first glyph of S has a left box line, start drawing it to the
4449 right of that line. */
4450 if (s
->face
->box
!= FACE_NO_BOX
4451 && s
->first_glyph
->left_box_line_p
)
4452 x
= s
->x
+ abs (s
->face
->box_line_width
);
4456 /* If there is a margin around the image, adjust x- and y-position
4458 x
+= s
->img
->hmargin
;
4459 y
+= s
->img
->vmargin
;
4461 if (s
->hl
== DRAW_IMAGE_SUNKEN
4462 || s
->hl
== DRAW_IMAGE_RAISED
)
4464 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
4465 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
4469 thick
= abs (s
->img
->relief
);
4470 raised_p
= s
->img
->relief
> 0;
4475 x1
= x
+ s
->img
->width
+ thick
- 1;
4476 y1
= y
+ s
->img
->height
+ thick
- 1;
4478 x_setup_relief_colors (s
);
4479 x_get_glyph_string_clip_rect (s
, &r
);
4480 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
4484 /* Draw the foreground of image glyph string S to PIXMAP. */
4487 x_draw_image_foreground_1 (s
, pixmap
)
4488 struct glyph_string
*s
;
4492 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4494 /* If first glyph of S has a left box line, start drawing it to the
4495 right of that line. */
4496 if (s
->face
->box
!= FACE_NO_BOX
4497 && s
->first_glyph
->left_box_line_p
)
4498 x
= abs (s
->face
->box_line_width
);
4502 /* If there is a margin around the image, adjust x- and y-position
4504 x
+= s
->img
->hmargin
;
4505 y
+= s
->img
->vmargin
;
4509 #if 0 /* MAC_TODO: image mask */
4512 /* We can't set both a clip mask and use XSetClipRectangles
4513 because the latter also sets a clip mask. We also can't
4514 trust on the shape extension to be available
4515 (XShapeCombineRegion). So, compute the rectangle to draw
4517 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4521 xgcv
.clip_mask
= s
->img
->mask
;
4522 xgcv
.clip_x_origin
= x
;
4523 xgcv
.clip_y_origin
= y
;
4524 xgcv
.function
= GXcopy
;
4525 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4527 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4528 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4529 XSetClipMask (s
->display
, s
->gc
, None
);
4532 #endif /* MAC_TODO */
4534 mac_copy_area_to_pixmap (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4535 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4537 /* When the image has a mask, we can expect that at
4538 least part of a mouse highlight or a block cursor will
4539 be visible. If the image doesn't have a mask, make
4540 a block cursor visible by drawing a rectangle around
4541 the image. I believe it's looking better if we do
4542 nothing here for mouse-face. */
4543 if (s
->hl
== DRAW_CURSOR
)
4545 int r
= s
->img
->relief
;
4547 mac_draw_rectangle_to_pixmap (s
->display
, pixmap
, s
->gc
, x
- r
, y
- r
,
4548 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
4553 /* Draw a rectangle if image could not be loaded. */
4554 mac_draw_rectangle_to_pixmap (s
->display
, pixmap
, s
->gc
, x
, y
,
4555 s
->img
->width
- 1, s
->img
->height
- 1);
4559 /* Draw part of the background of glyph string S. X, Y, W, and H
4560 give the rectangle to draw. */
4563 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4564 struct glyph_string
*s
;
4567 #if 0 /* MAC_TODO: stipple */
4570 /* Fill background with a stipple pattern. */
4571 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4572 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4573 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4576 #endif /* MAC_TODO */
4577 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4581 /* Draw image glyph string S.
4584 s->x +-------------------------
4587 | +-------------------------
4590 | | +-------------------
4596 x_draw_image_glyph_string (s
)
4597 struct glyph_string
*s
;
4600 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4601 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4605 height
= s
->height
- 2 * box_line_vwidth
;
4607 /* Fill background with face under the image. Do it only if row is
4608 taller than image or if image has a clip mask to reduce
4610 s
->stippled_p
= s
->face
->stipple
!= 0;
4611 if (height
> s
->img
->height
4614 #if 0 /* TODO: image mask */
4617 || s
->img
->pixmap
== 0
4618 || s
->width
!= s
->background_width
)
4620 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4621 x
= s
->x
+ box_line_hwidth
;
4625 y
= s
->y
+ box_line_vwidth
;
4626 #if 0 /* TODO: image mask */
4629 /* Create a pixmap as large as the glyph string. Fill it
4630 with the background color. Copy the image to it, using
4631 its mask. Copy the temporary pixmap to the display. */
4632 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4633 int depth
= DefaultDepthOfScreen (screen
);
4635 /* Create a pixmap as large as the glyph string. */
4636 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4637 s
->background_width
,
4640 /* Don't clip in the following because we're working on the
4642 XSetClipMask (s
->display
, s
->gc
, None
);
4644 /* Fill the pixmap with the background color/stipple. */
4647 /* Fill background with a stipple pattern. */
4648 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4649 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4650 0, 0, s
->background_width
, s
->height
);
4651 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4656 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4658 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4659 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4660 0, 0, s
->background_width
, s
->height
);
4661 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4666 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4668 s
->background_filled_p
= 1;
4671 /* Draw the foreground. */
4674 x_draw_image_foreground_1 (s
, pixmap
);
4675 x_set_glyph_string_clipping (s
);
4676 mac_copy_area (s
->display
, pixmap
, s
->window
, s
->gc
,
4677 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4678 mac_reset_clipping (s
->display
, s
->window
);
4679 XFreePixmap (s
->display
, pixmap
);
4682 x_draw_image_foreground (s
);
4684 /* If we must draw a relief around the image, do it. */
4686 || s
->hl
== DRAW_IMAGE_RAISED
4687 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4688 x_draw_image_relief (s
);
4692 /* Draw stretch glyph string S. */
4695 x_draw_stretch_glyph_string (s
)
4696 struct glyph_string
*s
;
4698 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4699 s
->stippled_p
= s
->face
->stipple
!= 0;
4701 if (s
->hl
== DRAW_CURSOR
4702 && !x_stretch_cursor_p
)
4704 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4705 as wide as the stretch glyph. */
4706 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4709 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4711 /* Clear rest using the GC of the original non-cursor face. */
4712 if (width
< s
->background_width
)
4714 GC gc
= s
->face
->gc
;
4715 int x
= s
->x
+ width
, y
= s
->y
;
4716 int w
= s
->background_width
- width
, h
= s
->height
;
4719 if (s
->row
->mouse_face_p
4720 && cursor_in_mouse_face_p (s
->w
))
4722 x_set_mouse_face_gc (s
);
4728 x_get_glyph_string_clip_rect (s
, &r
);
4729 mac_set_clip_rectangle (s
->display
, s
->window
, &r
);
4731 #if 0 /* MAC_TODO: stipple */
4732 if (s
->face
->stipple
)
4734 /* Fill background with a stipple pattern. */
4735 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4736 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4737 XSetFillStyle (s
->display
, gc
, FillSolid
);
4740 #endif /* MAC_TODO */
4743 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4744 XSetForeground (s
->display
, gc
, xgcv
.background
);
4745 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4746 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4749 mac_reset_clipping (s
->display
, s
->window
);
4752 else if (!s
->background_filled_p
)
4753 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4756 s
->background_filled_p
= 1;
4760 /* Draw glyph string S. */
4763 x_draw_glyph_string (s
)
4764 struct glyph_string
*s
;
4766 int relief_drawn_p
= 0;
4768 /* If S draws into the background of its successor, draw the
4769 background of the successor first so that S can draw into it.
4770 This makes S->next use XDrawString instead of XDrawImageString. */
4771 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4773 xassert (s
->next
->img
== NULL
);
4774 x_set_glyph_string_gc (s
->next
);
4775 x_set_glyph_string_clipping (s
->next
);
4776 x_draw_glyph_string_background (s
->next
, 1);
4780 /* Set up S->gc, set clipping and draw S. */
4781 x_set_glyph_string_gc (s
);
4783 /* Draw relief (if any) in advance for char/composition so that the
4784 glyph string can be drawn over it. */
4785 if (!s
->for_overlaps_p
4786 && s
->face
->box
!= FACE_NO_BOX
4787 && (s
->first_glyph
->type
== CHAR_GLYPH
4788 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4791 x_set_glyph_string_clipping (s
);
4792 x_draw_glyph_string_background (s
, 1);
4793 x_draw_glyph_string_box (s
);
4794 x_set_glyph_string_clipping (s
);
4798 x_set_glyph_string_clipping (s
);
4800 switch (s
->first_glyph
->type
)
4803 x_draw_image_glyph_string (s
);
4807 x_draw_stretch_glyph_string (s
);
4811 if (s
->for_overlaps_p
)
4812 s
->background_filled_p
= 1;
4814 x_draw_glyph_string_background (s
, 0);
4815 x_draw_glyph_string_foreground (s
);
4818 case COMPOSITE_GLYPH
:
4819 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4820 s
->background_filled_p
= 1;
4822 x_draw_glyph_string_background (s
, 1);
4823 x_draw_composite_glyph_string_foreground (s
);
4830 if (!s
->for_overlaps_p
)
4832 /* Draw underline. */
4833 if (s
->face
->underline_p
)
4835 unsigned long h
= 1;
4836 unsigned long dy
= s
->height
- h
;
4838 if (s
->face
->underline_defaulted_p
)
4839 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4844 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4845 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4846 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4848 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4852 /* Draw overline. */
4853 if (s
->face
->overline_p
)
4855 unsigned long dy
= 0, h
= 1;
4857 if (s
->face
->overline_color_defaulted_p
)
4858 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4863 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4864 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4865 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4867 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4871 /* Draw strike-through. */
4872 if (s
->face
->strike_through_p
)
4874 unsigned long h
= 1;
4875 unsigned long dy
= (s
->height
- h
) / 2;
4877 if (s
->face
->strike_through_color_defaulted_p
)
4878 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4883 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4884 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4885 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4887 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4892 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4893 x_draw_glyph_string_box (s
);
4896 /* Reset clipping. */
4897 mac_reset_clipping (s
->display
, s
->window
);
4901 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4902 struct face
**, int));
4905 /* Fill glyph string S with composition components specified by S->cmp.
4907 FACES is an array of faces for all components of this composition.
4908 S->gidx is the index of the first component for S.
4909 OVERLAPS_P non-zero means S should draw the foreground only, and
4910 use its physical height for clipping.
4912 Value is the index of a component not in S. */
4915 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4916 struct glyph_string
*s
;
4917 struct face
**faces
;
4924 s
->for_overlaps_p
= overlaps_p
;
4926 s
->face
= faces
[s
->gidx
];
4927 s
->font
= s
->face
->font
;
4928 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4930 /* For all glyphs of this composition, starting at the offset
4931 S->gidx, until we reach the end of the definition or encounter a
4932 glyph that requires the different face, add it to S. */
4934 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4937 /* All glyph strings for the same composition has the same width,
4938 i.e. the width set for the first component of the composition. */
4940 s
->width
= s
->first_glyph
->pixel_width
;
4942 /* If the specified font could not be loaded, use the frame's
4943 default font, but record the fact that we couldn't load it in
4944 the glyph string so that we can draw rectangles for the
4945 characters of the glyph string. */
4946 if (s
->font
== NULL
)
4948 s
->font_not_found_p
= 1;
4949 s
->font
= FRAME_FONT (s
->f
);
4952 /* Adjust base line for subscript/superscript text. */
4953 s
->ybase
+= s
->first_glyph
->voffset
;
4955 xassert (s
->face
&& s
->face
->gc
);
4957 /* This glyph string must always be drawn with 16-bit functions. */
4960 return s
->gidx
+ s
->nchars
;
4964 /* Fill glyph string S from a sequence of character glyphs.
4966 FACE_ID is the face id of the string. START is the index of the
4967 first glyph to consider, END is the index of the last + 1.
4968 OVERLAPS_P non-zero means S should draw the foreground only, and
4969 use its physical height for clipping.
4971 Value is the index of the first glyph not in S. */
4974 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4975 struct glyph_string
*s
;
4977 int start
, end
, overlaps_p
;
4979 struct glyph
*glyph
, *last
;
4981 int glyph_not_available_p
;
4983 xassert (s
->f
== XFRAME (s
->w
->frame
));
4984 xassert (s
->nchars
== 0);
4985 xassert (start
>= 0 && end
> start
);
4987 s
->for_overlaps_p
= overlaps_p
;
4988 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4989 last
= s
->row
->glyphs
[s
->area
] + end
;
4990 voffset
= glyph
->voffset
;
4992 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4995 && glyph
->type
== CHAR_GLYPH
4996 && glyph
->voffset
== voffset
4997 /* Same face id implies same font, nowadays. */
4998 && glyph
->face_id
== face_id
4999 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
5003 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
5004 s
->char2b
+ s
->nchars
,
5006 s
->two_byte_p
= two_byte_p
;
5008 xassert (s
->nchars
<= end
- start
);
5009 s
->width
+= glyph
->pixel_width
;
5013 s
->font
= s
->face
->font
;
5014 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
5016 /* If the specified font could not be loaded, use the frame's font,
5017 but record the fact that we couldn't load it in
5018 S->font_not_found_p so that we can draw rectangles for the
5019 characters of the glyph string. */
5020 if (s
->font
== NULL
|| glyph_not_available_p
)
5022 s
->font_not_found_p
= 1;
5023 s
->font
= FRAME_FONT (s
->f
);
5026 /* Adjust base line for subscript/superscript text. */
5027 s
->ybase
+= voffset
;
5029 xassert (s
->face
&& s
->face
->gc
);
5030 return glyph
- s
->row
->glyphs
[s
->area
];
5034 /* Fill glyph string S from image glyph S->first_glyph. */
5037 x_fill_image_glyph_string (s
)
5038 struct glyph_string
*s
;
5040 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
5041 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
5043 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
5044 s
->font
= s
->face
->font
;
5045 s
->width
= s
->first_glyph
->pixel_width
;
5047 /* Adjust base line for subscript/superscript text. */
5048 s
->ybase
+= s
->first_glyph
->voffset
;
5052 /* Fill glyph string S from a sequence of stretch glyphs.
5054 ROW is the glyph row in which the glyphs are found, AREA is the
5055 area within the row. START is the index of the first glyph to
5056 consider, END is the index of the last + 1.
5058 Value is the index of the first glyph not in S. */
5061 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
5062 struct glyph_string
*s
;
5063 struct glyph_row
*row
;
5064 enum glyph_row_area area
;
5067 struct glyph
*glyph
, *last
;
5068 int voffset
, face_id
;
5070 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
5072 glyph
= s
->row
->glyphs
[s
->area
] + start
;
5073 last
= s
->row
->glyphs
[s
->area
] + end
;
5074 face_id
= glyph
->face_id
;
5075 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
5076 s
->font
= s
->face
->font
;
5077 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
5078 s
->width
= glyph
->pixel_width
;
5079 voffset
= glyph
->voffset
;
5083 && glyph
->type
== STRETCH_GLYPH
5084 && glyph
->voffset
== voffset
5085 && glyph
->face_id
== face_id
);
5087 s
->width
+= glyph
->pixel_width
;
5089 /* Adjust base line for subscript/superscript text. */
5090 s
->ybase
+= voffset
;
5093 return glyph
- s
->row
->glyphs
[s
->area
];
5097 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
5098 of XChar2b structures for S; it can't be allocated in
5099 x_init_glyph_string because it must be allocated via `alloca'. W
5100 is the window on which S is drawn. ROW and AREA are the glyph row
5101 and area within the row from which S is constructed. START is the
5102 index of the first glyph structure covered by S. HL is a
5103 face-override for drawing S. */
5106 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
5107 struct glyph_string
*s
;
5110 struct glyph_row
*row
;
5111 enum glyph_row_area area
;
5113 enum draw_glyphs_face hl
;
5115 bzero (s
, sizeof *s
);
5117 s
->f
= XFRAME (w
->frame
);
5118 s
->display
= FRAME_MAC_DISPLAY (s
->f
);
5119 s
->window
= FRAME_MAC_WINDOW (s
->f
);
5124 s
->first_glyph
= row
->glyphs
[area
] + start
;
5125 s
->height
= row
->height
;
5126 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
5128 /* Display the internal border below the tool-bar window. */
5129 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
5130 s
->y
-= s
->f
->output_data
.mac
->internal_border_width
;
5132 s
->ybase
= s
->y
+ row
->ascent
;
5136 /* Set background width of glyph string S. START is the index of the
5137 first glyph following S. LAST_X is the right-most x-position + 1
5138 in the drawing area. */
5141 x_set_glyph_string_background_width (s
, start
, last_x
)
5142 struct glyph_string
*s
;
5146 /* If the face of this glyph string has to be drawn to the end of
5147 the drawing area, set S->extends_to_end_of_line_p. */
5148 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
5150 if (start
== s
->row
->used
[s
->area
]
5151 && s
->area
== TEXT_AREA
5152 && ((s
->hl
== DRAW_NORMAL_TEXT
5153 && (s
->row
->fill_line_p
5154 || s
->face
->background
!= default_face
->background
5155 || s
->face
->stipple
!= default_face
->stipple
5156 || s
->row
->mouse_face_p
))
5157 || s
->hl
== DRAW_MOUSE_FACE
5158 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
5159 && s
->row
->fill_line_p
)))
5160 s
->extends_to_end_of_line_p
= 1;
5162 /* If S extends its face to the end of the line, set its
5163 background_width to the distance to the right edge of the drawing
5165 if (s
->extends_to_end_of_line_p
)
5166 s
->background_width
= last_x
- s
->x
+ 1;
5168 s
->background_width
= s
->width
;
5172 /* Add a glyph string for a stretch glyph to the list of strings
5173 between HEAD and TAIL. START is the index of the stretch glyph in
5174 row area AREA of glyph row ROW. END is the index of the last glyph
5175 in that glyph row area. X is the current output position assigned
5176 to the new glyph string constructed. HL overrides that face of the
5177 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
5178 is the right-most x-position of the drawing area. */
5180 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
5181 and below -- keep them on one line. */
5182 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
5185 s = (struct glyph_string *) alloca (sizeof *s); \
5186 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
5187 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
5188 x_append_glyph_string (&HEAD, &TAIL, s); \
5194 /* Add a glyph string for an image glyph to the list of strings
5195 between HEAD and TAIL. START is the index of the image glyph in
5196 row area AREA of glyph row ROW. END is the index of the last glyph
5197 in that glyph row area. X is the current output position assigned
5198 to the new glyph string constructed. HL overrides that face of the
5199 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
5200 is the right-most x-position of the drawing area. */
5202 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
5205 s = (struct glyph_string *) alloca (sizeof *s); \
5206 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
5207 x_fill_image_glyph_string (s); \
5208 x_append_glyph_string (&HEAD, &TAIL, s); \
5215 /* Add a glyph string for a sequence of character glyphs to the list
5216 of strings between HEAD and TAIL. START is the index of the first
5217 glyph in row area AREA of glyph row ROW that is part of the new
5218 glyph string. END is the index of the last glyph in that glyph row
5219 area. X is the current output position assigned to the new glyph
5220 string constructed. HL overrides that face of the glyph; e.g. it
5221 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
5222 right-most x-position of the drawing area. */
5224 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
5230 c = (ROW)->glyphs[AREA][START].u.ch; \
5231 face_id = (ROW)->glyphs[AREA][START].face_id; \
5233 s = (struct glyph_string *) alloca (sizeof *s); \
5234 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
5235 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
5236 x_append_glyph_string (&HEAD, &TAIL, s); \
5238 START = x_fill_glyph_string (s, face_id, START, END, \
5244 /* Add a glyph string for a composite sequence to the list of strings
5245 between HEAD and TAIL. START is the index of the first glyph in
5246 row area AREA of glyph row ROW that is part of the new glyph
5247 string. END is the index of the last glyph in that glyph row area.
5248 X is the current output position assigned to the new glyph string
5249 constructed. HL overrides that face of the glyph; e.g. it is
5250 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
5251 x-position of the drawing area. */
5253 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
5255 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
5256 int face_id = (ROW)->glyphs[AREA][START].face_id; \
5257 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
5258 struct composition *cmp = composition_table[cmp_id]; \
5259 int glyph_len = cmp->glyph_len; \
5261 struct face **faces; \
5262 struct glyph_string *first_s = NULL; \
5265 base_face = base_face->ascii_face; \
5266 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
5267 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
5268 /* At first, fill in `char2b' and `faces'. */ \
5269 for (n = 0; n < glyph_len; n++) \
5271 int c = COMPOSITION_GLYPH (cmp, n); \
5272 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
5273 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
5274 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
5275 this_face_id, char2b + n, 1); \
5278 /* Make glyph_strings for each glyph sequence that is drawable by \
5279 the same face, and append them to HEAD/TAIL. */ \
5280 for (n = 0; n < cmp->glyph_len;) \
5282 s = (struct glyph_string *) alloca (sizeof *s); \
5283 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
5284 x_append_glyph_string (&(HEAD), &(TAIL), s); \
5292 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
5300 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
5301 of AREA of glyph row ROW on window W between indices START and END.
5302 HL overrides the face for drawing glyph strings, e.g. it is
5303 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
5304 x-positions of the drawing area.
5306 This is an ugly monster macro construct because we must use alloca
5307 to allocate glyph strings (because x_draw_glyphs can be called
5310 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
5313 HEAD = TAIL = NULL; \
5314 while (START < END) \
5316 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
5317 switch (first_glyph->type) \
5320 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
5321 TAIL, HL, X, LAST_X, \
5325 case COMPOSITE_GLYPH: \
5326 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
5327 HEAD, TAIL, HL, X, LAST_X,\
5331 case STRETCH_GLYPH: \
5332 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
5333 HEAD, TAIL, HL, X, LAST_X); \
5337 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
5338 TAIL, HL, X, LAST_X); \
5345 x_set_glyph_string_background_width (s, START, LAST_X); \
5352 /* Draw glyphs between START and END in AREA of ROW on window W,
5353 starting at x-position X. X is relative to AREA in W. HL is a
5354 face-override with the following meaning:
5356 DRAW_NORMAL_TEXT draw normally
5357 DRAW_CURSOR draw in cursor face
5358 DRAW_MOUSE_FACE draw in mouse face.
5359 DRAW_INVERSE_VIDEO draw in mode line face
5360 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
5361 DRAW_IMAGE_RAISED draw an image with a raised relief around it
5363 If OVERLAPS_P is non-zero, draw only the foreground of characters
5364 and clip to the physical height of ROW.
5366 Value is the x-position reached, relative to AREA of W. */
5369 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
5372 struct glyph_row
*row
;
5373 enum glyph_row_area area
;
5375 enum draw_glyphs_face hl
;
5378 struct glyph_string
*head
, *tail
;
5379 struct glyph_string
*s
;
5380 int last_x
, area_width
;
5384 /* Let's rather be paranoid than getting a SEGV. */
5385 end
= min (end
, row
->used
[area
]);
5386 start
= max (0, start
);
5387 start
= min (end
, start
);
5389 /* Translate X to frame coordinates. Set last_x to the right
5390 end of the drawing area. */
5391 if (row
->full_width_p
)
5393 /* X is relative to the left edge of W, without scroll bars
5395 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5396 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
5399 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5400 last_x
= window_left_x
+ area_width
;
5402 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5404 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5405 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5411 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5412 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
5416 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
5417 area_width
= window_box_width (w
, area
);
5418 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
5421 /* Build a doubly-linked list of glyph_string structures between
5422 head and tail from what we have to draw. Note that the macro
5423 BUILD_GLYPH_STRINGS will modify its start parameter. That's
5424 the reason we use a separate variable `i'. */
5426 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
5429 x_reached
= tail
->x
+ tail
->background_width
;
5433 /* If there are any glyphs with lbearing < 0 or rbearing > width in
5434 the row, redraw some glyphs in front or following the glyph
5435 strings built above. */
5436 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
5439 struct glyph_string
*h
, *t
;
5441 /* Compute overhangs for all glyph strings. */
5442 for (s
= head
; s
; s
= s
->next
)
5443 x_compute_glyph_string_overhangs (s
);
5445 /* Prepend glyph strings for glyphs in front of the first glyph
5446 string that are overwritten because of the first glyph
5447 string's left overhang. The background of all strings
5448 prepended must be drawn because the first glyph string
5450 i
= x_left_overwritten (head
);
5454 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
5455 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5458 x_compute_overhangs_and_x (t
, head
->x
, 1);
5459 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5462 /* Prepend glyph strings for glyphs in front of the first glyph
5463 string that overwrite that glyph string because of their
5464 right overhang. For these strings, only the foreground must
5465 be drawn, because it draws over the glyph string at `head'.
5466 The background must not be drawn because this would overwrite
5467 right overhangs of preceding glyphs for which no glyph
5469 i
= x_left_overwriting (head
);
5472 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
5473 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5475 for (s
= h
; s
; s
= s
->next
)
5476 s
->background_filled_p
= 1;
5477 x_compute_overhangs_and_x (t
, head
->x
, 1);
5478 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5481 /* Append glyphs strings for glyphs following the last glyph
5482 string tail that are overwritten by tail. The background of
5483 these strings has to be drawn because tail's foreground draws
5485 i
= x_right_overwritten (tail
);
5488 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5489 DRAW_NORMAL_TEXT
, x
, last_x
,
5491 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5492 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5495 /* Append glyph strings for glyphs following the last glyph
5496 string tail that overwrite tail. The foreground of such
5497 glyphs has to be drawn because it writes into the background
5498 of tail. The background must not be drawn because it could
5499 paint over the foreground of following glyphs. */
5500 i
= x_right_overwriting (tail
);
5503 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5504 DRAW_NORMAL_TEXT
, x
, last_x
,
5506 for (s
= h
; s
; s
= s
->next
)
5507 s
->background_filled_p
= 1;
5508 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5509 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5513 /* Draw all strings. */
5514 for (s
= head
; s
; s
= s
->next
)
5515 x_draw_glyph_string (s
);
5517 if (area
== TEXT_AREA
5518 && !row
->full_width_p
5519 /* When drawing overlapping rows, only the glyph strings'
5520 foreground is drawn, which doesn't erase a cursor
5524 int x0
= head
? head
->x
: x
;
5525 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
5527 x0
= FRAME_TO_WINDOW_PIXEL_X (w
, x0
);
5528 x1
= FRAME_TO_WINDOW_PIXEL_X (w
, x1
);
5530 if (!row
->full_width_p
&& XFASTINT (w
->left_margin_width
) != 0)
5532 int left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
5533 x0
-= left_area_width
;
5534 x1
-= left_area_width
;
5537 notice_overwritten_cursor (w
, area
, x0
, x1
,
5538 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
5541 /* Value is the x-position up to which drawn, relative to AREA of W.
5542 This doesn't include parts drawn because of overhangs. */
5543 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5544 if (!row
->full_width_p
)
5546 if (area
> LEFT_MARGIN_AREA
)
5547 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5548 if (area
> TEXT_AREA
)
5549 x_reached
-= window_box_width (w
, TEXT_AREA
);
5556 /* Fix the display of area AREA of overlapping row ROW in window W. */
5559 x_fix_overlapping_area (w
, row
, area
)
5561 struct glyph_row
*row
;
5562 enum glyph_row_area area
;
5568 if (area
== LEFT_MARGIN_AREA
)
5570 else if (area
== TEXT_AREA
)
5571 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5573 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5574 + window_box_width (w
, TEXT_AREA
));
5576 for (i
= 0; i
< row
->used
[area
];)
5578 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5580 int start
= i
, start_x
= x
;
5584 x
+= row
->glyphs
[area
][i
].pixel_width
;
5587 while (i
< row
->used
[area
]
5588 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5590 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5591 DRAW_NORMAL_TEXT
, 1);
5595 x
+= row
->glyphs
[area
][i
].pixel_width
;
5604 /* Output LEN glyphs starting at START at the nominal cursor position.
5605 Advance the nominal cursor over the text. The global variable
5606 updated_window contains the window being updated, updated_row is
5607 the glyph row being updated, and updated_area is the area of that
5608 row being updated. */
5611 x_write_glyphs (start
, len
)
5612 struct glyph
*start
;
5617 xassert (updated_window
&& updated_row
);
5622 hpos
= start
- updated_row
->glyphs
[updated_area
];
5623 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5624 updated_row
, updated_area
,
5626 DRAW_NORMAL_TEXT
, 0);
5630 /* Advance the output cursor. */
5631 output_cursor
.hpos
+= len
;
5632 output_cursor
.x
= x
;
5636 /* Insert LEN glyphs from START at the nominal cursor position. */
5639 x_insert_glyphs (start
, len
)
5640 struct glyph
*start
;
5645 int line_height
, shift_by_width
, shifted_region_width
;
5646 struct glyph_row
*row
;
5647 struct glyph
*glyph
;
5648 int frame_x
, frame_y
, hpos
;
5650 xassert (updated_window
&& updated_row
);
5653 f
= XFRAME (WINDOW_FRAME (w
));
5655 /* Get the height of the line we are in. */
5657 line_height
= row
->height
;
5659 /* Get the width of the glyphs to insert. */
5661 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5662 shift_by_width
+= glyph
->pixel_width
;
5664 /* Get the width of the region to shift right. */
5665 shifted_region_width
= (window_box_width (w
, updated_area
)
5670 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5671 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5673 mac_scroll_area (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
5674 f
->output_data
.mac
->normal_gc
,
5676 shifted_region_width
, line_height
,
5677 frame_x
+ shift_by_width
, frame_y
);
5679 /* Write the glyphs. */
5680 hpos
= start
- row
->glyphs
[updated_area
];
5681 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5682 DRAW_NORMAL_TEXT
, 0);
5684 /* Advance the output cursor. */
5685 output_cursor
.hpos
+= len
;
5686 output_cursor
.x
+= shift_by_width
;
5691 /* Delete N glyphs at the nominal cursor position. Not implemented
5702 /* Erase the current text line from the nominal cursor position
5703 (inclusive) to pixel column TO_X (exclusive). The idea is that
5704 everything from TO_X onward is already erased.
5706 TO_X is a pixel position relative to updated_area of
5707 updated_window. TO_X == -1 means clear to the end of this area. */
5710 x_clear_end_of_line (to_x
)
5714 struct window
*w
= updated_window
;
5715 int max_x
, min_y
, max_y
;
5716 int from_x
, from_y
, to_y
;
5718 xassert (updated_window
&& updated_row
);
5719 f
= XFRAME (w
->frame
);
5721 if (updated_row
->full_width_p
)
5723 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5724 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5725 && !w
->pseudo_window_p
)
5726 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5729 max_x
= window_box_width (w
, updated_area
);
5730 max_y
= window_text_bottom_y (w
);
5732 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5733 of window. For TO_X > 0, truncate to end of drawing area. */
5739 to_x
= min (to_x
, max_x
);
5741 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5743 /* Notice if the cursor will be cleared by this operation. */
5744 if (!updated_row
->full_width_p
)
5745 notice_overwritten_cursor (w
, updated_area
,
5746 output_cursor
.x
, -1,
5748 MATRIX_ROW_BOTTOM_Y (updated_row
));
5750 from_x
= output_cursor
.x
;
5752 /* Translate to frame coordinates. */
5753 if (updated_row
->full_width_p
)
5755 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5756 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5760 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5761 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5764 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5765 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5766 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5768 /* Prevent inadvertently clearing to end of the X window. */
5769 if (to_x
> from_x
&& to_y
> from_y
)
5772 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
5773 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5780 /* Clear entire frame. If updating_frame is non-null, clear that
5781 frame. Otherwise clear the selected frame. */
5791 f
= SELECTED_FRAME ();
5793 /* Clearing the frame will erase any cursor, so mark them all as no
5795 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5796 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5797 output_cursor
.x
= -1;
5799 /* We don't set the output cursor here because there will always
5800 follow an explicit cursor_to. */
5802 XClearWindow (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
));
5804 #if 0 /* Clearing frame on Mac OS clears scroll bars. */
5805 /* We have to clear the scroll bars, too. If we have changed
5806 colors or something like that, then they should be notified. */
5807 x_scroll_bar_clear (f
);
5810 XFlush (FRAME_MAC_DISPLAY (f
));
5816 /* Invert the middle quarter of the frame for .15 sec. */
5818 /* We use the select system call to do the waiting, so we have to make
5819 sure it's available. If it isn't, we just won't do visual bells. */
5821 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5823 /* Subtract the `struct timeval' values X and Y, storing the result in
5824 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5827 timeval_subtract (result
, x
, y
)
5828 struct timeval
*result
, x
, y
;
5830 /* Perform the carry for the later subtraction by updating y. This
5831 is safer because on some systems the tv_sec member is unsigned. */
5832 if (x
.tv_usec
< y
.tv_usec
)
5834 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5835 y
.tv_usec
-= 1000000 * nsec
;
5839 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5841 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5842 y
.tv_usec
+= 1000000 * nsec
;
5846 /* Compute the time remaining to wait. tv_usec is certainly
5848 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5849 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5851 /* Return indication of whether the result should be considered
5853 return x
.tv_sec
< y
.tv_sec
;
5865 struct timeval wakeup
;
5867 EMACS_GET_TIME (wakeup
);
5869 /* Compute time to wait until, propagating carry from usecs. */
5870 wakeup
.tv_usec
+= 150000;
5871 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5872 wakeup
.tv_usec
%= 1000000;
5874 /* Keep waiting until past the time wakeup. */
5877 struct timeval timeout
;
5879 EMACS_GET_TIME (timeout
);
5881 /* In effect, timeout = wakeup - timeout.
5882 Break if result would be negative. */
5883 if (timeval_subtract (&timeout
, wakeup
, timeout
))
5886 /* Try to wait that long--but we might wake up sooner. */
5887 select (0, NULL
, NULL
, NULL
, &timeout
);
5896 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5899 /* Make audible bell. */
5904 struct frame
*f
= SELECTED_FRAME ();
5906 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5914 XFlush (FRAME_MAC_DISPLAY (f
));
5921 /* Specify how many text lines, from the top of the window,
5922 should be affected by insert-lines and delete-lines operations.
5923 This, and those operations, are used only within an update
5924 that is bounded by calls to x_update_begin and x_update_end. */
5927 XTset_terminal_window (n
)
5930 /* This function intentionally left blank. */
5935 /***********************************************************************
5937 ***********************************************************************/
5939 /* Perform an insert-lines or delete-lines operation, inserting N
5940 lines or deleting -N lines at vertical position VPOS. */
5943 x_ins_del_lines (vpos
, n
)
5950 /* Scroll part of the display as described by RUN. */
5953 x_scroll_run (w
, run
)
5957 struct frame
*f
= XFRAME (w
->frame
);
5958 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5960 /* Get frame-relative bounding box of the text display area of W,
5961 without mode lines. Include in this box the left and right
5963 window_box (w
, -1, &x
, &y
, &width
, &height
);
5964 width
+= FRAME_X_FRINGE_WIDTH (f
);
5965 x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
5967 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5968 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5969 bottom_y
= y
+ height
;
5973 /* Scrolling up. Make sure we don't copy part of the mode
5974 line at the bottom. */
5975 if (from_y
+ run
->height
> bottom_y
)
5976 height
= bottom_y
- from_y
;
5978 height
= run
->height
;
5982 /* Scolling down. Make sure we don't copy over the mode line.
5984 if (to_y
+ run
->height
> bottom_y
)
5985 height
= bottom_y
- to_y
;
5987 height
= run
->height
;
5992 /* Cursor off. Will be switched on again in x_update_window_end. */
5996 mac_scroll_area (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
5997 f
->output_data
.mac
->normal_gc
,
6007 /***********************************************************************
6009 ***********************************************************************/
6011 /* Redisplay an exposed area of frame F. X and Y are the upper-left
6012 corner of the exposed rectangle. W and H are width and height of
6013 the exposed area. All are pixel values. W or H zero means redraw
6014 the entire frame. */
6017 expose_frame (f
, x
, y
, w
, h
)
6022 int mouse_face_overwritten_p
= 0;
6024 TRACE ((stderr
, "expose_frame "));
6026 /* No need to redraw if frame will be redrawn soon. */
6027 if (FRAME_GARBAGED_P (f
))
6029 TRACE ((stderr
, " garbaged\n"));
6033 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
6034 or deactivated here, for unknown reasons, activated scroll bars
6035 are shown in deactivated frames in some instances. */
6036 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
6037 activate_scroll_bars (f
);
6039 deactivate_scroll_bars (f
);
6041 /* If basic faces haven't been realized yet, there is no point in
6042 trying to redraw anything. This can happen when we get an expose
6043 event while Emacs is starting, e.g. by moving another window. */
6044 if (FRAME_FACE_CACHE (f
) == NULL
6045 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
6047 TRACE ((stderr
, " no faces\n"));
6051 if (w
== 0 || h
== 0)
6054 r
.right
= CANON_X_UNIT (f
) * f
->width
;
6055 r
.bottom
= CANON_Y_UNIT (f
) * f
->height
;
6065 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.left
, r
.top
, r
.right
, r
.bottom
));
6066 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
6068 if (WINDOWP (f
->tool_bar_window
))
6069 mouse_face_overwritten_p
6070 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
6072 /* Some window managers support a focus-follows-mouse style with
6073 delayed raising of frames. Imagine a partially obscured frame,
6074 and moving the mouse into partially obscured mouse-face on that
6075 frame. The visible part of the mouse-face will be highlighted,
6076 then the WM raises the obscured frame. With at least one WM, KDE
6077 2.1, Emacs is not getting any event for the raising of the frame
6078 (even tried with SubstructureRedirectMask), only Expose events.
6079 These expose events will draw text normally, i.e. not
6080 highlighted. Which means we must redo the highlight here.
6081 Subsume it under ``we love X''. --gerd 2001-08-15 */
6082 /* Included in Windows version because Windows most likely does not
6083 do the right thing if any third party tool offers
6084 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
6085 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
6087 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6088 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6090 int x
= dpyinfo
->mouse_face_mouse_x
;
6091 int y
= dpyinfo
->mouse_face_mouse_y
;
6092 clear_mouse_face (dpyinfo
);
6093 note_mouse_highlight (f
, x
, y
);
6099 /* Redraw (parts) of all windows in the window tree rooted at W that
6100 intersect R. R contains frame pixel coordinates. */
6103 expose_window_tree (w
, r
)
6107 struct frame
*f
= XFRAME (w
->frame
);
6108 int mouse_face_overwritten_p
= 0;
6110 while (w
&& !FRAME_GARBAGED_P (f
))
6112 if (!NILP (w
->hchild
))
6113 mouse_face_overwritten_p
6114 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
6115 else if (!NILP (w
->vchild
))
6116 mouse_face_overwritten_p
6117 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
6119 mouse_face_overwritten_p
|= expose_window (w
, r
);
6121 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
6124 return mouse_face_overwritten_p
;
6128 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
6129 which intersects rectangle R. R is in window-relative coordinates. */
6132 expose_area (w
, row
, r
, area
)
6134 struct glyph_row
*row
;
6136 enum glyph_row_area area
;
6138 struct glyph
*first
= row
->glyphs
[area
];
6139 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
6141 int first_x
, start_x
, x
;
6143 if (area
== TEXT_AREA
&& row
->fill_line_p
)
6144 /* If row extends face to end of line write the whole line. */
6145 x_draw_glyphs (w
, 0, row
, area
,
6147 DRAW_NORMAL_TEXT
, 0);
6150 /* Set START_X to the window-relative start position for drawing glyphs of
6151 AREA. The first glyph of the text area can be partially visible.
6152 The first glyphs of other areas cannot. */
6153 if (area
== LEFT_MARGIN_AREA
)
6155 else if (area
== TEXT_AREA
)
6156 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
6158 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
6159 + window_box_width (w
, TEXT_AREA
));
6162 /* Find the first glyph that must be redrawn. */
6164 && x
+ first
->pixel_width
< r
->left
)
6166 x
+= first
->pixel_width
;
6170 /* Find the last one. */
6176 x
+= last
->pixel_width
;
6182 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
6183 first
- row
->glyphs
[area
],
6184 last
- row
->glyphs
[area
],
6185 DRAW_NORMAL_TEXT
, 0);
6190 /* Redraw the parts of the glyph row ROW on window W intersecting
6191 rectangle R. R is in window-relative coordinates. Value is
6192 non-zero if mouse face was overwritten. */
6195 expose_line (w
, row
, r
)
6197 struct glyph_row
*row
;
6200 xassert (row
->enabled_p
);
6202 if (row
->mode_line_p
|| w
->pseudo_window_p
)
6203 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
6204 DRAW_NORMAL_TEXT
, 0);
6207 if (row
->used
[LEFT_MARGIN_AREA
])
6208 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
6209 if (row
->used
[TEXT_AREA
])
6210 expose_area (w
, row
, r
, TEXT_AREA
);
6211 if (row
->used
[RIGHT_MARGIN_AREA
])
6212 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
6213 x_draw_row_fringe_bitmaps (w
, row
);
6216 return row
->mouse_face_p
;
6220 /* Return non-zero if W's cursor intersects rectangle R. */
6223 x_phys_cursor_in_rect_p (w
, r
)
6228 struct glyph
*cursor_glyph
;
6230 cursor_glyph
= get_phys_cursor_glyph (w
);
6233 cr
.left
= w
->phys_cursor
.x
;
6234 cr
.top
= w
->phys_cursor
.y
;
6235 cr
.right
= cr
.left
+ cursor_glyph
->pixel_width
;
6236 cr
.bottom
= cr
.top
+ w
->phys_cursor_height
;
6237 return x_intersect_rectangles (&cr
, r
, &result
);
6244 /* Redraw the part of window W intersection rectagle FR. Pixel
6245 coordinates in FR are frame relative. Call this function with
6246 input blocked. Value is non-zero if the exposure overwrites
6250 expose_window (w
, fr
)
6254 struct frame
*f
= XFRAME (w
->frame
);
6256 int mouse_face_overwritten_p
= 0;
6258 /* If window is not yet fully initialized, do nothing. This can
6259 happen when toolkit scroll bars are used and a window is split.
6260 Reconfiguring the scroll bar will generate an expose for a newly
6262 if (w
->current_matrix
== NULL
)
6265 /* When we're currently updating the window, display and current
6266 matrix usually don't agree. Arrange for a thorough display
6268 if (w
== updated_window
)
6270 SET_FRAME_GARBAGED (f
);
6274 /* Frame-relative pixel rectangle of W. */
6275 wr
.left
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
6276 wr
.top
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
6277 wr
.right
= wr
.left
+ XFASTINT (w
->width
) * CANON_X_UNIT (f
);
6278 wr
.bottom
= wr
.top
+ XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
6280 if (x_intersect_rectangles (fr
, &wr
, &r
))
6282 int yb
= window_text_bottom_y (w
);
6283 struct glyph_row
*row
;
6284 int cursor_cleared_p
;
6286 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
6287 r
.left
, r
.top
, r
.right
, r
.bottom
));
6289 /* Convert to window coordinates. */
6290 r
.left
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.left
);
6291 r
.right
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.right
);
6292 r
.top
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.top
);
6293 r
.bottom
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.bottom
);
6295 /* Turn off the cursor. */
6296 if (!w
->pseudo_window_p
6297 && x_phys_cursor_in_rect_p (w
, &r
))
6300 cursor_cleared_p
= 1;
6303 cursor_cleared_p
= 0;
6305 /* Find the first row intersecting the rectangle R. */
6306 for (row
= w
->current_matrix
->rows
;
6311 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
6313 if ((y0
>= r
.top
&& y0
< r
.bottom
)
6314 || (y1
> r
.top
&& y1
< r
.bottom
)
6315 || (r
.top
>= y0
&& r
.top
< y1
)
6316 || (r
.bottom
> y0
&& r
.bottom
< y1
))
6318 if (expose_line (w
, row
, &r
))
6319 mouse_face_overwritten_p
= 1;
6326 /* Display the mode line if there is one. */
6327 if (WINDOW_WANTS_MODELINE_P (w
)
6328 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
6330 && row
->y
< r
.bottom
)
6332 if (expose_line (w
, row
, &r
))
6333 mouse_face_overwritten_p
= 1;
6336 if (!w
->pseudo_window_p
)
6338 /* Draw border between windows. */
6339 x_draw_vertical_border (w
);
6341 /* Turn the cursor on again. */
6342 if (cursor_cleared_p
)
6343 x_update_window_cursor (w
, 1);
6347 /* Display scroll bar for this window. */
6348 if (!NILP (w
->vertical_scroll_bar
))
6351 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w
->vertical_scroll_bar
));
6356 return mouse_face_overwritten_p
;
6360 x_intersect_rectangles (r1
, r2
, result
)
6361 Rect
*r1
, *r2
, *result
;
6364 Rect
*upper
, *lower
;
6365 int intersection_p
= 0;
6367 /* Rerrange so that R1 is the left-most rectangle. */
6368 if (r1
->left
< r2
->left
)
6369 left
= r1
, right
= r2
;
6371 left
= r2
, right
= r1
;
6373 /* X0 of the intersection is right.x0, if this is inside R1,
6374 otherwise there is no intersection. */
6375 if (right
->left
<= left
->right
)
6377 result
->left
= right
->left
;
6379 /* The right end of the intersection is the minimum of the
6380 the right ends of left and right. */
6381 result
->right
= min (left
->right
, right
->right
);
6383 /* Same game for Y. */
6384 if (r1
->top
< r2
->top
)
6385 upper
= r1
, lower
= r2
;
6387 upper
= r2
, lower
= r1
;
6389 /* The upper end of the intersection is lower.y0, if this is inside
6390 of upper. Otherwise, there is no intersection. */
6391 if (lower
->top
<= upper
->bottom
)
6393 result
->top
= lower
->top
;
6395 /* The lower end of the intersection is the minimum of the lower
6396 ends of upper and lower. */
6397 result
->bottom
= min (lower
->bottom
, upper
->bottom
);
6402 return intersection_p
;
6413 x_update_cursor (f
, 1);
6417 frame_unhighlight (f
)
6420 x_update_cursor (f
, 1);
6423 /* The focus has changed. Update the frames as necessary to reflect
6424 the new situation. Note that we can't change the selected frame
6425 here, because the Lisp code we are interrupting might become confused.
6426 Each event gets marked with the frame in which it occurred, so the
6427 Lisp code can tell when the switch took place by examining the events. */
6430 x_new_focus_frame (dpyinfo
, frame
)
6431 struct x_display_info
*dpyinfo
;
6432 struct frame
*frame
;
6434 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
6436 if (frame
!= dpyinfo
->x_focus_frame
)
6438 /* Set this before calling other routines, so that they see
6439 the correct value of x_focus_frame. */
6440 dpyinfo
->x_focus_frame
= frame
;
6442 if (old_focus
&& old_focus
->auto_lower
)
6443 x_lower_frame (old_focus
);
6446 selected_frame
= frame
;
6447 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6449 Fselect_window (selected_frame
->selected_window
);
6450 choose_minibuf_frame ();
6453 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6454 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6456 pending_autoraise_frame
= 0;
6459 x_frame_rehighlight (dpyinfo
);
6462 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6465 x_mouse_leave (dpyinfo
)
6466 struct x_display_info
*dpyinfo
;
6468 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6471 /* The focus has changed, or we have redirected a frame's focus to
6472 another frame (this happens when a frame uses a surrogate
6473 mini-buffer frame). Shift the highlight as appropriate.
6475 The FRAME argument doesn't necessarily have anything to do with which
6476 frame is being highlighted or un-highlighted; we only use it to find
6477 the appropriate X display info. */
6480 XTframe_rehighlight (frame
)
6481 struct frame
*frame
;
6483 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6487 x_frame_rehighlight (dpyinfo
)
6488 struct x_display_info
*dpyinfo
;
6490 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6492 if (dpyinfo
->x_focus_frame
)
6494 dpyinfo
->x_highlight_frame
6495 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6496 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6497 : dpyinfo
->x_focus_frame
);
6498 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6500 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6501 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6505 dpyinfo
->x_highlight_frame
= 0;
6507 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6510 frame_unhighlight (old_highlight
);
6511 if (dpyinfo
->x_highlight_frame
)
6512 frame_highlight (dpyinfo
->x_highlight_frame
);
6518 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6520 #if 0 /* MAC_TODO */
6521 /* Initialize mode_switch_bit and modifier_meaning. */
6523 x_find_modifier_meanings (dpyinfo
)
6524 struct x_display_info
*dpyinfo
;
6526 int min_code
, max_code
;
6529 XModifierKeymap
*mods
;
6531 dpyinfo
->meta_mod_mask
= 0;
6532 dpyinfo
->shift_lock_mask
= 0;
6533 dpyinfo
->alt_mod_mask
= 0;
6534 dpyinfo
->super_mod_mask
= 0;
6535 dpyinfo
->hyper_mod_mask
= 0;
6538 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6540 min_code
= dpyinfo
->display
->min_keycode
;
6541 max_code
= dpyinfo
->display
->max_keycode
;
6544 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6545 min_code
, max_code
- min_code
+ 1,
6547 mods
= XGetModifierMapping (dpyinfo
->display
);
6549 /* Scan the modifier table to see which modifier bits the Meta and
6550 Alt keysyms are on. */
6552 int row
, col
; /* The row and column in the modifier table. */
6554 for (row
= 3; row
< 8; row
++)
6555 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6558 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6560 /* Zeroes are used for filler. Skip them. */
6564 /* Are any of this keycode's keysyms a meta key? */
6568 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6570 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6576 dpyinfo
->meta_mod_mask
|= (1 << row
);
6581 dpyinfo
->alt_mod_mask
|= (1 << row
);
6586 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6591 dpyinfo
->super_mod_mask
|= (1 << row
);
6595 /* Ignore this if it's not on the lock modifier. */
6596 if ((1 << row
) == LockMask
)
6597 dpyinfo
->shift_lock_mask
= LockMask
;
6605 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6606 if (! dpyinfo
->meta_mod_mask
)
6608 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6609 dpyinfo
->alt_mod_mask
= 0;
6612 /* If some keys are both alt and meta,
6613 make them just meta, not alt. */
6614 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6616 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6619 XFree ((char *) syms
);
6620 XFreeModifiermap (mods
);
6623 #endif /* MAC_TODO */
6625 /* Convert between the modifier bits X uses and the modifier bits
6629 x_mac_to_emacs_modifiers (dpyinfo
, state
)
6630 struct x_display_info
*dpyinfo
;
6631 unsigned short state
;
6633 return (((state
& shiftKey
) ? shift_modifier
: 0)
6634 | ((state
& controlKey
) ? ctrl_modifier
: 0)
6635 | ((state
& cmdKey
) ? meta_modifier
: 0)
6636 | ((state
& optionKey
) ? alt_modifier
: 0));
6639 #if 0 /* MAC_TODO */
6640 static unsigned short
6641 x_emacs_to_x_modifiers (dpyinfo
, state
)
6642 struct x_display_info
*dpyinfo
;
6645 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
6646 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
6647 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
6648 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6649 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6650 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
6652 #endif /* MAC_TODO */
6654 /* Convert a keysym to its name. */
6657 x_get_keysym_name (keysym
)
6664 value
= XKeysymToString (keysym
);
6675 /* Mouse clicks and mouse movement. Rah. */
6677 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6678 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6679 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6680 not force the value into range. */
6683 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6685 register int pix_x
, pix_y
;
6686 register int *x
, *y
;
6690 /* Support tty mode: if Vwindow_system is nil, behave correctly. */
6691 if (NILP (Vwindow_system
))
6698 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6699 even for negative values. */
6701 pix_x
-= FONT_WIDTH (FRAME_FONT (f
)) - 1;
6703 pix_y
-= (f
)->output_data
.mac
->line_height
- 1;
6705 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6706 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6710 bounds
->left
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6711 bounds
->top
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6712 bounds
->right
= bounds
->left
+ FONT_WIDTH (FRAME_FONT (f
)) - 1;
6713 bounds
->bottom
= bounds
->top
+ f
->output_data
.mac
->line_height
- 1;
6720 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6721 pix_x
= FRAME_WINDOW_WIDTH (f
);
6725 else if (pix_y
> f
->height
)
6734 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6735 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6736 can't tell the positions because W's display is not up to date,
6740 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6743 int *frame_x
, *frame_y
;
6747 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6748 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6750 if (display_completed
)
6752 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6753 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6754 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6760 *frame_x
+= glyph
->pixel_width
;
6768 *frame_y
= *frame_x
= 0;
6772 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6773 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6778 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6780 If the event is a button press, then note that we have grabbed
6784 construct_mouse_click (result
, event
, f
)
6785 struct input_event
*result
;
6791 result
->kind
= MOUSE_CLICK_EVENT
;
6792 result
->code
= 0; /* only one mouse button */
6793 result
->timestamp
= event
->when
;
6794 result
->modifiers
= event
->what
== mouseDown
? down_modifier
: up_modifier
;
6796 mouseLoc
= event
->where
;
6798 #if TARGET_API_MAC_CARBON
6799 SetPort (GetWindowPort (FRAME_MAC_WINDOW (f
)));
6801 SetPort (FRAME_MAC_WINDOW (f
));
6804 GlobalToLocal (&mouseLoc
);
6805 XSETINT (result
->x
, mouseLoc
.h
);
6806 XSETINT (result
->y
, mouseLoc
.v
);
6808 XSETFRAME (result
->frame_or_window
, f
);
6815 /* Function to report a mouse movement to the mainstream Emacs code.
6816 The input handler calls this.
6818 We have received a mouse movement event, which is given in *event.
6819 If the mouse is over a different glyph than it was last time, tell
6820 the mainstream emacs code by setting mouse_moved. If not, ask for
6821 another motion event, so we can check again the next time it moves. */
6823 static Point last_mouse_motion_position
;
6824 static Lisp_Object last_mouse_motion_frame
;
6827 note_mouse_movement (frame
, pos
)
6831 #if TARGET_API_MAC_CARBON
6835 last_mouse_movement_time
= TickCount () * (1000 / 60); /* to milliseconds */
6836 last_mouse_motion_position
= *pos
;
6837 XSETFRAME (last_mouse_motion_frame
, frame
);
6839 #if TARGET_API_MAC_CARBON
6840 if (!PtInRect (*pos
, GetWindowPortBounds (FRAME_MAC_WINDOW (frame
), &r
)))
6842 if (!PtInRect (*pos
, &FRAME_MAC_WINDOW (frame
)->portRect
))
6845 frame
->mouse_moved
= 1;
6846 last_mouse_scroll_bar
= Qnil
;
6847 note_mouse_highlight (frame
, -1, -1);
6849 /* Has the mouse moved off the glyph it was on at the last sighting? */
6850 else if (pos
->h
< last_mouse_glyph
.left
6851 || pos
->h
>= last_mouse_glyph
.right
6852 || pos
->v
< last_mouse_glyph
.top
6853 || pos
->v
>= last_mouse_glyph
.bottom
)
6855 frame
->mouse_moved
= 1;
6856 last_mouse_scroll_bar
= Qnil
;
6857 note_mouse_highlight (frame
, pos
->h
, pos
->v
);
6861 /* This is used for debugging, to turn off note_mouse_highlight. */
6863 int disable_mouse_highlight
;
6867 /************************************************************************
6869 ************************************************************************/
6871 /* Find the glyph under window-relative coordinates X/Y in window W.
6872 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6873 strings. Return in *HPOS and *VPOS the row and column number of
6874 the glyph found. Return in *AREA the glyph area containing X.
6875 Value is a pointer to the glyph found or null if X/Y is not on
6876 text, or we can't tell because W's current matrix is not up to
6879 static struct glyph
*
6880 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6883 int *hpos
, *vpos
, *area
;
6886 struct glyph
*glyph
, *end
;
6887 struct glyph_row
*row
= NULL
;
6888 int x0
, i
, left_area_width
;
6890 /* Find row containing Y. Give up if some row is not enabled. */
6891 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6893 row
= MATRIX_ROW (w
->current_matrix
, i
);
6894 if (!row
->enabled_p
)
6896 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6903 /* Give up if Y is not in the window. */
6904 if (i
== w
->current_matrix
->nrows
)
6907 /* Get the glyph area containing X. */
6908 if (w
->pseudo_window_p
)
6915 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6916 if (x
< left_area_width
)
6918 *area
= LEFT_MARGIN_AREA
;
6921 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6924 x0
= row
->x
+ left_area_width
;
6928 *area
= RIGHT_MARGIN_AREA
;
6929 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6933 /* Find glyph containing X. */
6934 glyph
= row
->glyphs
[*area
];
6935 end
= glyph
+ row
->used
[*area
];
6938 if (x
< x0
+ glyph
->pixel_width
)
6940 if (w
->pseudo_window_p
)
6942 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6946 x0
+= glyph
->pixel_width
;
6953 *hpos
= glyph
- row
->glyphs
[*area
];
6958 /* Convert frame-relative x/y to coordinates relative to window W.
6959 Takes pseudo-windows into account. */
6962 frame_to_window_pixel_xy (w
, x
, y
)
6966 if (w
->pseudo_window_p
)
6968 /* A pseudo-window is always full-width, and starts at the
6969 left edge of the frame, plus a frame border. */
6970 struct frame
*f
= XFRAME (w
->frame
);
6971 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6972 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6976 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6977 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6982 /* Take proper action when mouse has moved to the mode or header line of
6983 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6984 mode line. X is relative to the start of the text display area of
6985 W, so the width of fringes and scroll bars must be subtracted
6986 to get a position relative to the start of the mode line. */
6989 note_mode_line_highlight (w
, x
, mode_line_p
)
6993 struct frame
*f
= XFRAME (w
->frame
);
6994 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6995 struct Cursor
*cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6996 struct glyph_row
*row
;
6999 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
7001 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
7005 struct glyph
*glyph
, *end
;
7006 Lisp_Object help
, map
;
7009 /* Find the glyph under X. */
7010 glyph
= row
->glyphs
[TEXT_AREA
];
7011 end
= glyph
+ row
->used
[TEXT_AREA
];
7012 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
7013 + FRAME_X_LEFT_FRINGE_WIDTH (f
));
7016 && x
>= x0
+ glyph
->pixel_width
)
7018 x0
+= glyph
->pixel_width
;
7023 && STRINGP (glyph
->object
)
7024 && STRING_INTERVALS (glyph
->object
)
7025 && glyph
->charpos
>= 0
7026 && glyph
->charpos
< SCHARS (glyph
->object
))
7028 /* If we're on a string with `help-echo' text property,
7029 arrange for the help to be displayed. This is done by
7030 setting the global variable help_echo to the help string. */
7031 help
= Fget_text_property (make_number (glyph
->charpos
),
7032 Qhelp_echo
, glyph
->object
);
7036 XSETWINDOW (help_echo_window
, w
);
7037 help_echo_object
= glyph
->object
;
7038 help_echo_pos
= glyph
->charpos
;
7041 /* Change the mouse pointer according to what is under X/Y. */
7042 map
= Fget_text_property (make_number (glyph
->charpos
),
7043 Qlocal_map
, glyph
->object
);
7045 cursor
= f
->output_data
.mac
->nontext_cursor
;
7048 map
= Fget_text_property (make_number (glyph
->charpos
),
7049 Qkeymap
, glyph
->object
);
7051 cursor
= f
->output_data
.mac
->nontext_cursor
;
7056 #if 0 /* MAC_TODO: mouse cursor */
7057 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7062 /* Take proper action when the mouse has moved to position X, Y on
7063 frame F as regards highlighting characters that have mouse-face
7064 properties. Also de-highlighting chars where the mouse was before.
7065 X and Y can be negative or out of range. */
7068 note_mouse_highlight (f
, x
, y
)
7072 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7079 /* When a menu is active, don't highlight because this looks odd. */
7080 if (popup_activated ())
7084 if (NILP (Vmouse_highlight
)
7085 || !f
->glyphs_initialized_p
)
7088 dpyinfo
->mouse_face_mouse_x
= x
;
7089 dpyinfo
->mouse_face_mouse_y
= y
;
7090 dpyinfo
->mouse_face_mouse_frame
= f
;
7092 if (dpyinfo
->mouse_face_defer
)
7097 dpyinfo
->mouse_face_deferred_gc
= 1;
7101 /* Which window is that in? */
7102 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
7104 /* If we were displaying active text in another window, clear that. */
7105 if (! EQ (window
, dpyinfo
->mouse_face_window
))
7106 clear_mouse_face (dpyinfo
);
7108 /* Not on a window -> return. */
7109 if (!WINDOWP (window
))
7112 /* Reset help_echo. It will get recomputed below. */
7115 /* Convert to window-relative pixel coordinates. */
7116 w
= XWINDOW (window
);
7117 frame_to_window_pixel_xy (w
, &x
, &y
);
7119 /* Handle tool-bar window differently since it doesn't display a
7121 if (EQ (window
, f
->tool_bar_window
))
7123 note_tool_bar_highlight (f
, x
, y
);
7127 /* Mouse is on the mode or header line? */
7128 if (portion
== 1 || portion
== 3)
7130 note_mode_line_highlight (w
, x
, portion
== 1);
7133 #if 0 /* TODO: mouse cursor */
7135 cursor
= f
->output_data
.x
->horizontal_drag_cursor
;
7137 cursor
= f
->output_data
.x
->text_cursor
;
7139 /* Are we in a window whose display is up to date?
7140 And verify the buffer's text has not changed. */
7141 b
= XBUFFER (w
->buffer
);
7142 if (/* Within text portion of the window. */
7144 && EQ (w
->window_end_valid
, w
->buffer
)
7145 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
7146 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
7148 int hpos
, vpos
, pos
, i
, area
;
7149 struct glyph
*glyph
;
7151 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
7152 Lisp_Object
*overlay_vec
= NULL
;
7154 struct buffer
*obuf
;
7155 int obegv
, ozv
, same_region
;
7157 /* Find the glyph under X/Y. */
7158 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
7160 /* Clear mouse face if X/Y not over text. */
7162 || area
!= TEXT_AREA
7163 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
7165 clear_mouse_face (dpyinfo
);
7166 /* TODO: mouse cursor */
7170 pos
= glyph
->charpos
;
7171 object
= glyph
->object
;
7172 if (!STRINGP (object
) && !BUFFERP (object
))
7175 /* If we get an out-of-range value, return now; avoid an error. */
7176 if (BUFFERP (object
) && pos
> BUF_Z (b
))
7179 /* Make the window's buffer temporarily current for
7180 overlays_at and compute_char_face. */
7181 obuf
= current_buffer
;
7188 /* Is this char mouse-active or does it have help-echo? */
7189 position
= make_number (pos
);
7191 if (BUFFERP (object
))
7193 /* Put all the overlays we want in a vector in overlay_vec.
7194 Store the length in len. If there are more than 10, make
7195 enough space for all, and try again. */
7197 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7198 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
7199 if (noverlays
> len
)
7202 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7203 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
7206 /* Sort overlays into increasing priority order. */
7207 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
7212 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
7213 && vpos
>= dpyinfo
->mouse_face_beg_row
7214 && vpos
<= dpyinfo
->mouse_face_end_row
7215 && (vpos
> dpyinfo
->mouse_face_beg_row
7216 || hpos
>= dpyinfo
->mouse_face_beg_col
)
7217 && (vpos
< dpyinfo
->mouse_face_end_row
7218 || hpos
< dpyinfo
->mouse_face_end_col
7219 || dpyinfo
->mouse_face_past_end
));
7221 /* TODO: if (same_region)
7224 /* Check mouse-face highlighting. */
7226 /* If there exists an overlay with mouse-face overlapping
7227 the one we are currently highlighting, we have to
7228 check if we enter the overlapping overlay, and then
7230 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
7231 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
7233 /* Find the highest priority overlay that has a mouse-face
7236 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
7238 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
7239 if (!NILP (mouse_face
))
7240 overlay
= overlay_vec
[i
];
7243 /* If we're actually highlighting the same overlay as
7244 before, there's no need to do that again. */
7246 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
7247 goto check_help_echo
;
7249 dpyinfo
->mouse_face_overlay
= overlay
;
7251 /* Clear the display of the old active region, if any. */
7252 clear_mouse_face (dpyinfo
);
7253 /* TODO: mouse cursor changes. */
7255 /* If no overlay applies, get a text property. */
7257 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
7259 /* Handle the overlay case. */
7260 if (!NILP (overlay
))
7262 /* Find the range of text around this char that
7263 should be active. */
7264 Lisp_Object before
, after
;
7267 before
= Foverlay_start (overlay
);
7268 after
= Foverlay_end (overlay
);
7269 /* Record this as the current active region. */
7270 fast_find_position (w
, XFASTINT (before
),
7271 &dpyinfo
->mouse_face_beg_col
,
7272 &dpyinfo
->mouse_face_beg_row
,
7273 &dpyinfo
->mouse_face_beg_x
,
7274 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7276 dpyinfo
->mouse_face_past_end
7277 = !fast_find_position (w
, XFASTINT (after
),
7278 &dpyinfo
->mouse_face_end_col
,
7279 &dpyinfo
->mouse_face_end_row
,
7280 &dpyinfo
->mouse_face_end_x
,
7281 &dpyinfo
->mouse_face_end_y
, Qnil
);
7282 dpyinfo
->mouse_face_window
= window
;
7284 dpyinfo
->mouse_face_face_id
7285 = face_at_buffer_position (w
, pos
, 0, 0,
7286 &ignore
, pos
+ 1, 1);
7288 /* Display it as active. */
7289 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7290 /* TODO: mouse cursor changes. */
7292 /* Handle the text property case. */
7293 else if (! NILP (mouse_face
) && BUFFERP (object
))
7295 /* Find the range of text around this char that
7296 should be active. */
7297 Lisp_Object before
, after
, beginning
, end
;
7300 beginning
= Fmarker_position (w
->start
);
7301 end
= make_number (BUF_Z (XBUFFER (object
))
7302 - XFASTINT (w
->window_end_pos
));
7304 = Fprevious_single_property_change (make_number (pos
+ 1),
7308 = Fnext_single_property_change (position
, Qmouse_face
,
7311 /* Record this as the current active region. */
7312 fast_find_position (w
, XFASTINT (before
),
7313 &dpyinfo
->mouse_face_beg_col
,
7314 &dpyinfo
->mouse_face_beg_row
,
7315 &dpyinfo
->mouse_face_beg_x
,
7316 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7317 dpyinfo
->mouse_face_past_end
7318 = !fast_find_position (w
, XFASTINT (after
),
7319 &dpyinfo
->mouse_face_end_col
,
7320 &dpyinfo
->mouse_face_end_row
,
7321 &dpyinfo
->mouse_face_end_x
,
7322 &dpyinfo
->mouse_face_end_y
, Qnil
);
7323 dpyinfo
->mouse_face_window
= window
;
7325 if (BUFFERP (object
))
7326 dpyinfo
->mouse_face_face_id
7327 = face_at_buffer_position (w
, pos
, 0, 0,
7328 &ignore
, pos
+ 1, 1);
7330 /* Display it as active. */
7331 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7332 /* TODO: mouse cursor changes. */
7334 else if (!NILP (mouse_face
) && STRINGP (object
))
7339 b
= Fprevious_single_property_change (make_number (pos
+ 1),
7342 e
= Fnext_single_property_change (position
, Qmouse_face
,
7345 b
= make_number (0);
7347 e
= make_number (SCHARS (object
) - 1);
7348 fast_find_string_pos (w
, XINT (b
), object
,
7349 &dpyinfo
->mouse_face_beg_col
,
7350 &dpyinfo
->mouse_face_beg_row
,
7351 &dpyinfo
->mouse_face_beg_x
,
7352 &dpyinfo
->mouse_face_beg_y
, 0);
7353 fast_find_string_pos (w
, XINT (e
), object
,
7354 &dpyinfo
->mouse_face_end_col
,
7355 &dpyinfo
->mouse_face_end_row
,
7356 &dpyinfo
->mouse_face_end_x
,
7357 &dpyinfo
->mouse_face_end_y
, 1);
7358 dpyinfo
->mouse_face_past_end
= 0;
7359 dpyinfo
->mouse_face_window
= window
;
7360 dpyinfo
->mouse_face_face_id
7361 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
7363 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7364 /* TODO: mouse cursor changes. */
7366 else if (STRINGP (object
) && NILP (mouse_face
))
7368 /* A string which doesn't have mouse-face, but
7369 the text ``under'' it might have. */
7370 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
7371 int start
= MATRIX_ROW_START_CHARPOS (r
);
7373 pos
= string_buffer_position (w
, object
, start
);
7375 mouse_face
= get_char_property_and_overlay (make_number (pos
),
7379 if (!NILP (mouse_face
) && !NILP (overlay
))
7381 Lisp_Object before
= Foverlay_start (overlay
);
7382 Lisp_Object after
= Foverlay_end (overlay
);
7385 /* Note that we might not be able to find position
7386 BEFORE in the glyph matrix if the overlay is
7387 entirely covered by a `display' property. In
7388 this case, we overshoot. So let's stop in
7389 the glyph matrix before glyphs for OBJECT. */
7390 fast_find_position (w
, XFASTINT (before
),
7391 &dpyinfo
->mouse_face_beg_col
,
7392 &dpyinfo
->mouse_face_beg_row
,
7393 &dpyinfo
->mouse_face_beg_x
,
7394 &dpyinfo
->mouse_face_beg_y
,
7397 dpyinfo
->mouse_face_past_end
7398 = !fast_find_position (w
, XFASTINT (after
),
7399 &dpyinfo
->mouse_face_end_col
,
7400 &dpyinfo
->mouse_face_end_row
,
7401 &dpyinfo
->mouse_face_end_x
,
7402 &dpyinfo
->mouse_face_end_y
,
7404 dpyinfo
->mouse_face_window
= window
;
7405 dpyinfo
->mouse_face_face_id
7406 = face_at_buffer_position (w
, pos
, 0, 0,
7407 &ignore
, pos
+ 1, 1);
7409 /* Display it as active. */
7410 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7411 /* TODO: mouse cursor changes. */
7418 /* Look for a `help-echo' property. */
7420 Lisp_Object help
, overlay
;
7422 /* Check overlays first. */
7423 help
= overlay
= Qnil
;
7424 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
7426 overlay
= overlay_vec
[i
];
7427 help
= Foverlay_get (overlay
, Qhelp_echo
);
7433 help_echo_window
= window
;
7434 help_echo_object
= overlay
;
7435 help_echo_pos
= pos
;
7439 Lisp_Object object
= glyph
->object
;
7440 int charpos
= glyph
->charpos
;
7442 /* Try text properties. */
7443 if (STRINGP (object
)
7445 && charpos
< SCHARS (object
))
7447 help
= Fget_text_property (make_number (charpos
),
7448 Qhelp_echo
, object
);
7451 /* If the string itself doesn't specify a help-echo,
7452 see if the buffer text ``under'' it does. */
7454 = MATRIX_ROW (w
->current_matrix
, vpos
);
7455 int start
= MATRIX_ROW_START_CHARPOS (r
);
7456 int pos
= string_buffer_position (w
, object
, start
);
7459 help
= Fget_char_property (make_number (pos
),
7460 Qhelp_echo
, w
->buffer
);
7469 else if (BUFFERP (object
)
7472 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
7478 help_echo_window
= window
;
7479 help_echo_object
= object
;
7480 help_echo_pos
= charpos
;
7487 current_buffer
= obuf
;
7491 /* TODO: mouse cursor changes. */
7496 redo_mouse_highlight ()
7498 if (!NILP (last_mouse_motion_frame
)
7499 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
7500 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
7501 last_mouse_motion_position
.h
,
7502 last_mouse_motion_position
.v
);
7507 /***********************************************************************
7509 ***********************************************************************/
7511 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
7512 struct glyph
**, int *, int *, int *));
7514 /* Tool-bar item index of the item on which a mouse button was pressed
7517 static int last_tool_bar_item
;
7520 /* Get information about the tool-bar item at position X/Y on frame F.
7521 Return in *GLYPH a pointer to the glyph of the tool-bar item in
7522 the current matrix of the tool-bar window of F, or NULL if not
7523 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
7524 item in F->current_tool_bar_items. Value is
7526 -1 if X/Y is not on a tool-bar item
7527 0 if X/Y is on the same item that was highlighted before.
7531 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
7534 struct glyph
**glyph
;
7535 int *hpos
, *vpos
, *prop_idx
;
7537 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7538 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7541 /* Find the glyph under X/Y. */
7542 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
7546 /* Get the start of this tool-bar item's properties in
7547 f->current_tool_bar_items. */
7548 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
7551 /* Is mouse on the highlighted item? */
7552 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
7553 && *vpos
>= dpyinfo
->mouse_face_beg_row
7554 && *vpos
<= dpyinfo
->mouse_face_end_row
7555 && (*vpos
> dpyinfo
->mouse_face_beg_row
7556 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
7557 && (*vpos
< dpyinfo
->mouse_face_end_row
7558 || *hpos
< dpyinfo
->mouse_face_end_col
7559 || dpyinfo
->mouse_face_past_end
))
7566 /* Handle mouse button event on the tool-bar of frame F, at
7567 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
7571 x_handle_tool_bar_click (f
, button_event
)
7573 EventRecord
*button_event
;
7575 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7576 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7577 int hpos
, vpos
, prop_idx
;
7578 struct glyph
*glyph
;
7579 Lisp_Object enabled_p
;
7580 int x
= button_event
->where
.h
;
7581 int y
= button_event
->where
.v
;
7583 /* If not on the highlighted tool-bar item, return. */
7584 frame_to_window_pixel_xy (w
, &x
, &y
);
7585 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
7588 /* If item is disabled, do nothing. */
7589 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7590 if (NILP (enabled_p
))
7593 if (button_event
->what
== mouseDown
)
7595 /* Show item in pressed state. */
7596 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7597 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7598 last_tool_bar_item
= prop_idx
;
7602 Lisp_Object key
, frame
;
7603 struct input_event event
;
7605 /* Show item in released state. */
7606 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7607 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7609 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7611 XSETFRAME (frame
, f
);
7612 event
.kind
= TOOL_BAR_EVENT
;
7613 event
.frame_or_window
= frame
;
7615 kbd_buffer_store_event (&event
);
7617 event
.kind
= TOOL_BAR_EVENT
;
7618 event
.frame_or_window
= frame
;
7620 event
.modifiers
= x_mac_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
7621 button_event
->modifiers
);
7622 kbd_buffer_store_event (&event
);
7623 last_tool_bar_item
= -1;
7628 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7629 tool-bar window-relative coordinates X/Y. Called from
7630 note_mouse_highlight. */
7633 note_tool_bar_highlight (f
, x
, y
)
7637 Lisp_Object window
= f
->tool_bar_window
;
7638 struct window
*w
= XWINDOW (window
);
7639 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7641 struct glyph
*glyph
;
7642 struct glyph_row
*row
;
7644 Lisp_Object enabled_p
;
7646 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
7647 int mouse_down_p
, rc
;
7649 /* Function note_mouse_highlight is called with negative x(y
7650 values when mouse moves outside of the frame. */
7651 if (x
<= 0 || y
<= 0)
7653 clear_mouse_face (dpyinfo
);
7657 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7660 /* Not on tool-bar item. */
7661 clear_mouse_face (dpyinfo
);
7665 /* On same tool-bar item as before. */
7668 clear_mouse_face (dpyinfo
);
7670 /* Mouse is down, but on different tool-bar item? */
7671 mouse_down_p
= (dpyinfo
->grabbed
7672 && f
== last_mouse_frame
7673 && FRAME_LIVE_P (f
));
7675 && last_tool_bar_item
!= prop_idx
)
7678 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7679 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7681 /* If tool-bar item is not enabled, don't highlight it. */
7682 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7683 if (!NILP (enabled_p
))
7685 /* Compute the x-position of the glyph. In front and past the
7686 image is a space. We include this is the highlighted area. */
7687 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7688 for (i
= x
= 0; i
< hpos
; ++i
)
7689 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7691 /* Record this as the current active region. */
7692 dpyinfo
->mouse_face_beg_col
= hpos
;
7693 dpyinfo
->mouse_face_beg_row
= vpos
;
7694 dpyinfo
->mouse_face_beg_x
= x
;
7695 dpyinfo
->mouse_face_beg_y
= row
->y
;
7696 dpyinfo
->mouse_face_past_end
= 0;
7698 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7699 dpyinfo
->mouse_face_end_row
= vpos
;
7700 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7701 dpyinfo
->mouse_face_end_y
= row
->y
;
7702 dpyinfo
->mouse_face_window
= window
;
7703 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7705 /* Display it as active. */
7706 show_mouse_face (dpyinfo
, draw
);
7707 dpyinfo
->mouse_face_image_state
= draw
;
7712 /* Set help_echo to a help string.to display for this tool-bar item.
7713 XTread_socket does the rest. */
7714 help_echo_object
= help_echo_window
= Qnil
;
7716 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7717 if (NILP (help_echo
))
7718 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7723 /* Find the glyph matrix position of buffer position CHARPOS in window
7724 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7725 current glyphs must be up to date. If CHARPOS is above window
7726 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
7727 of last line in W. In the row containing CHARPOS, stop before glyphs
7728 having STOP as object. */
7730 #if 0 /* This is a version of fast_find_position that's more correct
7731 in the presence of hscrolling, for example. I didn't install
7732 it right away because the problem fixed is minor, it failed
7733 in 20.x as well, and I think it's too risky to install
7734 so near the release of 21.1. 2001-09-25 gerd. */
7737 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
7740 int *hpos
, *vpos
, *x
, *y
;
7743 struct glyph_row
*row
, *first
;
7744 struct glyph
*glyph
, *end
;
7745 int i
, past_end
= 0;
7747 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7748 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
7751 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
7753 *x
= *y
= *hpos
= *vpos
= 0;
7758 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
7765 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7767 glyph
= row
->glyphs
[TEXT_AREA
];
7768 end
= glyph
+ row
->used
[TEXT_AREA
];
7770 /* Skip over glyphs not having an object at the start of the row.
7771 These are special glyphs like truncation marks on terminal
7773 if (row
->displays_text_p
)
7775 && INTEGERP (glyph
->object
)
7776 && !EQ (stop
, glyph
->object
)
7777 && glyph
->charpos
< 0)
7779 *x
+= glyph
->pixel_width
;
7784 && !INTEGERP (glyph
->object
)
7785 && !EQ (stop
, glyph
->object
)
7786 && (!BUFFERP (glyph
->object
)
7787 || glyph
->charpos
< charpos
))
7789 *x
+= glyph
->pixel_width
;
7793 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7800 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
7803 int *hpos
, *vpos
, *x
, *y
;
7808 int maybe_next_line_p
= 0;
7809 int line_start_position
;
7810 int yb
= window_text_bottom_y (w
);
7811 struct glyph_row
*row
, *best_row
;
7812 int row_vpos
, best_row_vpos
;
7815 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7816 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7820 if (row
->used
[TEXT_AREA
])
7821 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7823 line_start_position
= 0;
7825 if (line_start_position
> pos
)
7827 /* If the position sought is the end of the buffer,
7828 don't include the blank lines at the bottom of the window. */
7829 else if (line_start_position
== pos
7830 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7832 maybe_next_line_p
= 1;
7835 else if (line_start_position
> 0)
7838 best_row_vpos
= row_vpos
;
7841 if (row
->y
+ row
->height
>= yb
)
7848 /* Find the right column within BEST_ROW. */
7850 current_x
= best_row
->x
;
7851 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7853 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7854 int charpos
= glyph
->charpos
;
7856 if (BUFFERP (glyph
->object
))
7861 *vpos
= best_row_vpos
;
7866 else if (charpos
> pos
)
7869 else if (EQ (glyph
->object
, stop
))
7874 current_x
+= glyph
->pixel_width
;
7877 /* If we're looking for the end of the buffer,
7878 and we didn't find it in the line we scanned,
7879 use the start of the following line. */
7880 if (maybe_next_line_p
)
7885 current_x
= best_row
->x
;
7888 *vpos
= best_row_vpos
;
7889 *hpos
= lastcol
+ 1;
7898 /* Find the position of the glyph for position POS in OBJECT in
7899 window W's current matrix, and return in *X/*Y the pixel
7900 coordinates, and return in *HPOS/*VPOS the column/row of the glyph.
7902 RIGHT_P non-zero means return the position of the right edge of the
7903 glyph, RIGHT_P zero means return the left edge position.
7905 If no glyph for POS exists in the matrix, return the position of
7906 the glyph with the next smaller position that is in the matrix, if
7907 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7908 exists in the matrix, return the position of the glyph with the
7909 next larger position in OBJECT.
7911 Value is non-zero if a glyph was found. */
7914 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7918 int *hpos
, *vpos
, *x
, *y
;
7921 int yb
= window_text_bottom_y (w
);
7922 struct glyph_row
*r
;
7923 struct glyph
*best_glyph
= NULL
;
7924 struct glyph_row
*best_row
= NULL
;
7927 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7928 r
->enabled_p
&& r
->y
< yb
;
7931 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7932 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7935 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7936 if (EQ (g
->object
, object
))
7938 if (g
->charpos
== pos
)
7945 else if (best_glyph
== NULL
7946 || ((abs (g
->charpos
- pos
)
7947 < abs (best_glyph
->charpos
- pos
))
7950 : g
->charpos
> pos
)))
7964 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7968 *x
+= best_glyph
->pixel_width
;
7973 *vpos
= best_row
- w
->current_matrix
->rows
;
7976 return best_glyph
!= NULL
;
7980 /* Display the active region described by mouse_face_*
7981 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7984 show_mouse_face (dpyinfo
, draw
)
7985 struct mac_display_info
*dpyinfo
;
7986 enum draw_glyphs_face draw
;
7988 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7989 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7991 if (/* If window is in the process of being destroyed, don't bother
7993 w
->current_matrix
!= NULL
7994 /* Don't update mouse highlight if hidden */
7995 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
7996 /* Recognize when we are called to operate on rows that don't exist
7997 anymore. This can happen when a window is split. */
7998 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
8000 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
8001 struct glyph_row
*row
, *first
, *last
;
8003 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
8004 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
8006 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
8008 int start_hpos
, end_hpos
, start_x
;
8010 /* For all but the first row, the highlight starts at column 0. */
8013 start_hpos
= dpyinfo
->mouse_face_beg_col
;
8014 start_x
= dpyinfo
->mouse_face_beg_x
;
8023 end_hpos
= dpyinfo
->mouse_face_end_col
;
8025 end_hpos
= row
->used
[TEXT_AREA
];
8027 if (end_hpos
> start_hpos
)
8029 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
8030 start_hpos
, end_hpos
, draw
, 0);
8033 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
8037 /* When we've written over the cursor, arrange for it to
8038 be displayed again. */
8039 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
8040 x_display_cursor (w
, 1,
8041 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
8042 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
8045 #if 0 /* MAC_TODO: mouse cursor */
8046 /* Change the mouse cursor. */
8047 if (draw
== DRAW_NORMAL_TEXT
)
8048 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8049 f
->output_data
.x
->text_cursor
);
8050 else if (draw
== DRAW_MOUSE_FACE
)
8051 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8052 f
->output_data
.x
->cross_cursor
);
8054 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8055 f
->output_data
.x
->nontext_cursor
);
8059 /* Clear out the mouse-highlighted active region.
8060 Redraw it un-highlighted first. */
8063 clear_mouse_face (dpyinfo
)
8064 struct mac_display_info
*dpyinfo
;
8068 if (! NILP (dpyinfo
->mouse_face_window
))
8070 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
8074 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
8075 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
8076 dpyinfo
->mouse_face_window
= Qnil
;
8077 dpyinfo
->mouse_face_overlay
= Qnil
;
8082 /* Clear any mouse-face on window W. This function is part of the
8083 redisplay interface, and is called from try_window_id and similar
8084 functions to ensure the mouse-highlight is off. */
8087 x_clear_mouse_face (w
)
8090 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (XFRAME (w
->frame
));
8094 XSETWINDOW (window
, w
);
8095 if (EQ (window
, dpyinfo
->mouse_face_window
))
8096 clear_mouse_face (dpyinfo
);
8101 /* Just discard the mouse face information for frame F, if any.
8102 This is used when the size of F is changed. */
8105 cancel_mouse_face (f
)
8109 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
8111 window
= dpyinfo
->mouse_face_window
;
8112 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
8114 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
8115 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
8116 dpyinfo
->mouse_face_window
= Qnil
;
8120 static struct scroll_bar
*x_window_to_scroll_bar ();
8121 static void x_scroll_bar_report_motion ();
8122 static void x_check_fullscreen
P_ ((struct frame
*));
8123 static void x_check_fullscreen_move
P_ ((struct frame
*));
8124 static int glyph_rect
P_ ((struct frame
*f
, int, int, Rect
*));
8127 /* Try to determine frame pixel position and size of the glyph under
8128 frame pixel coordinates X/Y on frame F . Return the position and
8129 size in *RECT. Value is non-zero if we could compute these
8133 glyph_rect (f
, x
, y
, rect
)
8141 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
8144 struct window
*w
= XWINDOW (window
);
8145 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8146 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
8148 frame_to_window_pixel_xy (w
, &x
, &y
);
8150 for (; r
< end
&& r
->enabled_p
; ++r
)
8151 if (r
->y
<= y
&& r
->y
+ r
->height
> y
)
8153 /* Found the row at y. */
8154 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
8155 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
8158 rect
->top
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
8159 rect
->bottom
= rect
->top
+ r
->height
;
8163 /* x is to the left of the first glyph in the row. */
8164 rect
->left
= XINT (w
->left
);
8165 rect
->right
= WINDOW_TO_FRAME_PIXEL_X (w
, r
->x
);
8169 for (gx
= r
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
8170 if (gx
<= x
&& gx
+ g
->pixel_width
> x
)
8172 /* x is on a glyph. */
8173 rect
->left
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
8174 rect
->right
= rect
->left
+ g
->pixel_width
;
8178 /* x is to the right of the last glyph in the row. */
8179 rect
->left
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
8180 rect
->right
= XINT (w
->left
) + XINT (w
->width
);
8185 /* The y is not on any row. */
8189 /* Record the position of the mouse in last_mouse_glyph. */
8191 remember_mouse_glyph (f1
, gx
, gy
)
8195 if (!glyph_rect (f1
, gx
, gy
, &last_mouse_glyph
))
8197 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
8198 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
8200 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
8201 round down even for negative values. */
8207 /* This was the original code from XTmouse_position, but it seems
8208 to give the position of the glyph diagonally next to the one
8209 the mouse is over. */
8210 gx
= (gx
+ width
- 1) / width
* width
;
8211 gy
= (gy
+ height
- 1) / height
* height
;
8213 gx
= gx
/ width
* width
;
8214 gy
= gy
/ height
* height
;
8217 last_mouse_glyph
.left
= gx
;
8218 last_mouse_glyph
.top
= gy
;
8219 last_mouse_glyph
.right
= gx
+ width
;
8220 last_mouse_glyph
.bottom
= gy
+ height
;
8224 /* Return the current position of the mouse.
8225 *fp should be a frame which indicates which display to ask about.
8227 If the mouse movement started in a scroll bar, set *fp, *bar_window,
8228 and *part to the frame, window, and scroll bar part that the mouse
8229 is over. Set *x and *y to the portion and whole of the mouse's
8230 position on the scroll bar.
8232 If the mouse movement started elsewhere, set *fp to the frame the
8233 mouse is on, *bar_window to nil, and *x and *y to the character cell
8236 Set *time to the server time-stamp for the time at which the mouse
8237 was at this position.
8239 Don't store anything if we don't have a valid set of values to report.
8241 This clears the mouse_moved flag, so we can wait for the next mouse
8245 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
8248 Lisp_Object
*bar_window
;
8249 enum scroll_bar_part
*part
;
8251 unsigned long *time
;
8254 int ignore1
, ignore2
;
8255 WindowPtr wp
= FrontWindow ();
8257 Lisp_Object frame
, tail
;
8259 if (is_emacs_window(wp
))
8260 f
= ((mac_output
*) GetWRefCon (wp
))->mFP
;
8264 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
8265 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
8268 /* Clear the mouse-moved flag for every frame on this display. */
8269 FOR_EACH_FRAME (tail
, frame
)
8270 XFRAME (frame
)->mouse_moved
= 0;
8272 last_mouse_scroll_bar
= Qnil
;
8274 #if TARGET_API_MAC_CARBON
8275 SetPort (GetWindowPort (wp
));
8280 GetMouse (&mouse_pos
);
8282 pixel_to_glyph_coords (f
, mouse_pos
.h
, mouse_pos
.v
, &ignore1
, &ignore2
,
8283 &last_mouse_glyph
, insist
);
8286 *part
= scroll_bar_handle
;
8288 XSETINT (*x
, mouse_pos
.h
);
8289 XSETINT (*y
, mouse_pos
.v
);
8290 *time
= last_mouse_movement_time
;
8297 /************************************************************************
8298 Scroll bars, general
8299 ************************************************************************/
8301 /* Create a scroll bar and return the scroll bar vector for it. W is
8302 the Emacs window on which to create the scroll bar. TOP, LEFT,
8303 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
8306 static struct scroll_bar
*
8307 x_scroll_bar_create (w
, top
, left
, width
, height
, disp_top
, disp_height
)
8309 int top
, left
, width
, height
, disp_top
, disp_height
;
8311 struct frame
*f
= XFRAME (w
->frame
);
8312 struct scroll_bar
*bar
8313 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8321 r
.right
= left
+ width
;
8322 r
.bottom
= disp_top
+ disp_height
;
8324 #ifdef TARGET_API_MAC_CARBON
8325 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p", 1, 0, 0, 0,
8326 kControlScrollBarProc
, 0L);
8328 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p", 1, 0, 0, 0, scrollBarProc
,
8331 SET_SCROLL_BAR_CONTROL_HANDLE (bar
, ch
);
8332 SetControlReference (ch
, (long) bar
);
8334 XSETWINDOW (bar
->window
, w
);
8335 XSETINT (bar
->top
, top
);
8336 XSETINT (bar
->left
, left
);
8337 XSETINT (bar
->width
, width
);
8338 XSETINT (bar
->height
, height
);
8339 XSETINT (bar
->start
, 0);
8340 XSETINT (bar
->end
, 0);
8341 bar
->dragging
= Qnil
;
8343 /* Add bar to its frame's list of scroll bars. */
8344 bar
->next
= FRAME_SCROLL_BARS (f
);
8346 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8347 if (!NILP (bar
->next
))
8348 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8355 /* Draw BAR's handle in the proper position.
8357 If the handle is already drawn from START to END, don't bother
8358 redrawing it, unless REBUILD is non-zero; in that case, always
8359 redraw it. (REBUILD is handy for drawing the handle after expose
8362 Normally, we want to constrain the start and end of the handle to
8363 fit inside its rectangle, but if the user is dragging the scroll
8364 bar handle, we want to let them drag it down all the way, so that
8365 the bar's top is as far down as it goes; otherwise, there's no way
8366 to move to the very end of the buffer. */
8369 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8370 struct scroll_bar
*bar
;
8374 int dragging
= ! NILP (bar
->dragging
);
8375 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
8376 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8377 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8378 int length
= end
- start
;
8380 /* If the display is already accurate, do nothing. */
8382 && start
== XINT (bar
->start
)
8383 && end
== XINT (bar
->end
))
8388 /* Make sure the values are reasonable, and try to preserve the
8389 distance between start and end. */
8392 else if (start
> top_range
)
8394 end
= start
+ length
;
8398 else if (end
> top_range
&& ! dragging
)
8401 /* Store the adjusted setting in the scroll bar. */
8402 XSETINT (bar
->start
, start
);
8403 XSETINT (bar
->end
, end
);
8405 /* Clip the end position, just for display. */
8406 if (end
> top_range
)
8409 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
8410 top positions, to make sure the handle is always at least that
8411 many pixels tall. */
8412 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8414 SetControlMinimum (ch
, 0);
8415 /* Don't inadvertently activate deactivated scroll bars */
8416 if (GetControlMaximum (ch
) != -1)
8417 SetControlMaximum (ch
, top_range
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
8419 SetControlValue (ch
, start
);
8420 #if TARGET_API_MAC_CARBON
8421 SetControlViewSize (ch
, end
- start
);
8428 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8432 x_scroll_bar_remove (bar
)
8433 struct scroll_bar
*bar
;
8435 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8439 /* Destroy the Mac scroll bar control */
8440 DisposeControl (SCROLL_BAR_CONTROL_HANDLE (bar
));
8442 /* Disassociate this scroll bar from its window. */
8443 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8448 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8449 that we are displaying PORTION characters out of a total of WHOLE
8450 characters, starting at POSITION. If WINDOW has no scroll bar,
8453 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8455 int portion
, whole
, position
;
8457 struct frame
*f
= XFRAME (w
->frame
);
8458 struct scroll_bar
*bar
;
8459 int top
, height
, left
, sb_left
, width
, sb_width
, disp_top
, disp_height
;
8460 int window_x
, window_y
, window_width
, window_height
;
8462 /* Get window dimensions. */
8463 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8468 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8470 height
= window_height
;
8472 /* Compute the left edge of the scroll bar area. */
8473 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8474 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8476 left
= XFASTINT (w
->left
);
8477 left
*= CANON_X_UNIT (f
);
8478 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8480 /* Compute the width of the scroll bar which might be less than
8481 the width of the area reserved for the scroll bar. */
8482 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8483 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8487 /* Compute the left edge of the scroll bar. */
8488 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8489 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8491 sb_left
= left
+ (width
- sb_width
) / 2;
8493 /* Adjustments according to Inside Macintosh to make it look nice */
8495 disp_height
= height
;
8501 else if (disp_top
== PIXEL_HEIGHT (f
) - 16)
8507 if (sb_left
+ sb_width
== PIXEL_WIDTH (f
))
8510 /* Does the scroll bar exist yet? */
8511 if (NILP (w
->vertical_scroll_bar
))
8514 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
8515 left
, top
, width
, height
, 0);
8517 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
, disp_top
,
8519 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8523 /* It may just need to be moved and resized. */
8526 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8527 ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
8531 /* If already correctly positioned, do nothing. */
8532 if (XINT (bar
->left
) == sb_left
8533 && XINT (bar
->top
) == top
8534 && XINT (bar
->width
) == sb_width
8535 && XINT (bar
->height
) == height
)
8539 /* Clear areas not covered by the scroll bar because it's not as
8540 wide as the area reserved for it . This makes sure a
8541 previous mode line display is cleared after C-x 2 C-x 1, for
8543 int area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8544 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
8545 left
, top
, area_width
, height
, 0);
8548 if (sb_left
+ sb_width
>= PIXEL_WIDTH (f
))
8549 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
8550 sb_left
- 1, top
, 1, height
, 0);
8554 MoveControl (ch
, sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
, disp_top
);
8555 SizeControl (ch
, sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8559 /* Remember new settings. */
8560 XSETINT (bar
->left
, sb_left
);
8561 XSETINT (bar
->top
, top
);
8562 XSETINT (bar
->width
, sb_width
);
8563 XSETINT (bar
->height
, height
);
8569 /* Set the scroll bar's current state, unless we're currently being
8571 if (NILP (bar
->dragging
))
8573 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8576 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8579 int start
= ((double) position
* top_range
) / whole
;
8580 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8581 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8587 /* The following three hooks are used when we're doing a thorough
8588 redisplay of the frame. We don't explicitly know which scroll bars
8589 are going to be deleted, because keeping track of when windows go
8590 away is a real pain - "Can you say set-window-configuration, boys
8591 and girls?" Instead, we just assert at the beginning of redisplay
8592 that *all* scroll bars are to be removed, and then save a scroll bar
8593 from the fiery pit when we actually redisplay its window. */
8595 /* Arrange for all scroll bars on FRAME to be removed at the next call
8596 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8597 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8600 XTcondemn_scroll_bars (frame
)
8603 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8604 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8607 bar
= FRAME_SCROLL_BARS (frame
);
8608 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8609 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8610 XSCROLL_BAR (bar
)->prev
= Qnil
;
8611 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8612 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8613 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8618 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8619 Note that WINDOW isn't necessarily condemned at all. */
8622 XTredeem_scroll_bar (window
)
8623 struct window
*window
;
8625 struct scroll_bar
*bar
;
8627 /* We can't redeem this window's scroll bar if it doesn't have one. */
8628 if (NILP (window
->vertical_scroll_bar
))
8631 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8633 /* Unlink it from the condemned list. */
8635 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
8637 if (NILP (bar
->prev
))
8639 /* If the prev pointer is nil, it must be the first in one of
8641 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8642 /* It's not condemned. Everything's fine. */
8644 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8645 window
->vertical_scroll_bar
))
8646 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8648 /* If its prev pointer is nil, it must be at the front of
8649 one or the other! */
8653 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8655 if (! NILP (bar
->next
))
8656 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8658 bar
->next
= FRAME_SCROLL_BARS (f
);
8660 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8661 if (! NILP (bar
->next
))
8662 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8666 /* Remove all scroll bars on FRAME that haven't been saved since the
8667 last call to `*condemn_scroll_bars_hook'. */
8670 XTjudge_scroll_bars (f
)
8673 Lisp_Object bar
, next
;
8675 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8677 /* Clear out the condemned list now so we won't try to process any
8678 more events on the hapless scroll bars. */
8679 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8681 for (; ! NILP (bar
); bar
= next
)
8683 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8685 x_scroll_bar_remove (b
);
8688 b
->next
= b
->prev
= Qnil
;
8691 /* Now there should be no references to the condemned scroll bars,
8692 and they should get garbage-collected. */
8697 activate_scroll_bars (frame
)
8703 bar
= FRAME_SCROLL_BARS (frame
);
8704 while (! NILP (bar
))
8706 ch
= SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (bar
));
8707 #ifdef TARGET_API_MAC_CARBON
8708 ActivateControl (ch
);
8710 SetControlMaximum (ch
,
8711 VERTICAL_SCROLL_BAR_TOP_RANGE (frame
,
8712 XINT (XSCROLL_BAR (bar
)
8715 bar
= XSCROLL_BAR (bar
)->next
;
8721 deactivate_scroll_bars (frame
)
8727 bar
= FRAME_SCROLL_BARS (frame
);
8728 while (! NILP (bar
))
8730 ch
= SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (bar
));
8731 #ifdef TARGET_API_MAC_CARBON
8732 DeactivateControl (ch
);
8734 SetControlMaximum (ch
, XINT (-1));
8736 bar
= XSCROLL_BAR (bar
)->next
;
8740 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8741 is set to something other than NO_EVENT, it is enqueued.
8743 This may be called from a signal handler, so we have to ignore GC
8747 x_scroll_bar_handle_click (bar
, part_code
, er
, bufp
)
8748 struct scroll_bar
*bar
;
8751 struct input_event
*bufp
;
8753 if (! GC_WINDOWP (bar
->window
))
8756 bufp
->kind
= SCROLL_BAR_CLICK_EVENT
;
8757 bufp
->frame_or_window
= bar
->window
;
8760 bar
->dragging
= Qnil
;
8764 case kControlUpButtonPart
:
8765 bufp
->part
= scroll_bar_up_arrow
;
8767 case kControlDownButtonPart
:
8768 bufp
->part
= scroll_bar_down_arrow
;
8770 case kControlPageUpPart
:
8771 bufp
->part
= scroll_bar_above_handle
;
8773 case kControlPageDownPart
:
8774 bufp
->part
= scroll_bar_below_handle
;
8776 #ifdef TARGET_API_MAC_CARBON
8779 case kControlIndicatorPart
:
8781 if (er
->what
== mouseDown
)
8782 bar
->dragging
= make_number (0);
8783 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8784 bufp
->part
= scroll_bar_handle
;
8790 /* Handle some mouse motion while someone is dragging the scroll bar.
8792 This may be called from a signal handler, so we have to ignore GC
8796 x_scroll_bar_note_movement (bar
, y_pos
, t
)
8797 struct scroll_bar
*bar
;
8801 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
8803 last_mouse_movement_time
= t
;
8806 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8808 /* If we're dragging the bar, display it. */
8809 if (! GC_NILP (bar
->dragging
))
8811 /* Where should the handle be now? */
8812 int new_start
= y_pos
- 24;
8814 if (new_start
!= XINT (bar
->start
))
8816 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8818 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8824 /* Return information to the user about the current position of the
8825 mouse on the scroll bar. */
8828 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8830 Lisp_Object
*bar_window
;
8831 enum scroll_bar_part
*part
;
8833 unsigned long *time
;
8835 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8836 WindowPtr wp
= FrontWindow ();
8838 struct frame
*f
= ((mac_output
*) GetWRefCon (wp
))->mFP
;
8839 int win_y
, top_range
;
8841 #if TARGET_API_MAC_CARBON
8842 SetPort (GetWindowPort (wp
));
8847 GetMouse (&mouse_pos
);
8849 win_y
= mouse_pos
.v
- XINT (bar
->top
);
8850 top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8852 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
8856 if (! NILP (bar
->dragging
))
8857 win_y
-= XINT (bar
->dragging
);
8861 if (win_y
> top_range
)
8865 *bar_window
= bar
->window
;
8867 if (! NILP (bar
->dragging
))
8868 *part
= scroll_bar_handle
;
8869 else if (win_y
< XINT (bar
->start
))
8870 *part
= scroll_bar_above_handle
;
8871 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8872 *part
= scroll_bar_handle
;
8874 *part
= scroll_bar_below_handle
;
8876 XSETINT (*x
, win_y
);
8877 XSETINT (*y
, top_range
);
8880 last_mouse_scroll_bar
= Qnil
;
8882 *time
= last_mouse_movement_time
;
8885 /***********************************************************************
8887 ***********************************************************************/
8889 /* Notice if the text cursor of window W has been overwritten by a
8890 drawing operation that outputs glyphs starting at START_X and
8891 ending at END_X in the line given by output_cursor.vpos.
8892 Coordinates are area-relative. END_X < 0 means all the rest
8893 of the line after START_X has been written. */
8896 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
8898 enum glyph_row_area area
;
8901 if (area
== TEXT_AREA
8902 && w
->phys_cursor_on_p
8903 && y0
<= w
->phys_cursor
.y
8904 && y1
>= w
->phys_cursor
.y
+ w
->phys_cursor_height
8905 && x0
<= w
->phys_cursor
.x
8906 && (x1
< 0 || x1
> w
->phys_cursor
.x
))
8907 w
->phys_cursor_on_p
= 0;
8911 /* Set clipping for output in glyph row ROW. W is the window in which
8912 we operate. GC is the graphics context to set clipping in.
8913 WHOLE_LINE_P non-zero means include the areas used for truncation
8914 mark display and alike in the clipping rectangle.
8916 ROW may be a text row or, e.g., a mode line. Text rows must be
8917 clipped to the interior of the window dedicated to text display,
8918 mode lines must be clipped to the whole window. */
8921 x_clip_to_row (w
, row
, gc
, whole_line_p
)
8923 struct glyph_row
*row
;
8927 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8929 int window_x
, window_y
, window_width
, window_height
;
8931 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8933 clip_rect
.left
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
8934 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
8935 clip_rect
.top
= max (clip_rect
.top
, window_y
);
8936 clip_rect
.right
= clip_rect
.left
+ window_width
;
8937 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
8939 /* If clipping to the whole line, including trunc marks, extend
8940 the rectangle to the left and increase its width. */
8943 clip_rect
.left
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
8944 clip_rect
.right
+= FRAME_X_FRINGE_WIDTH (f
);
8947 mac_set_clip_rectangle (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), &clip_rect
);
8951 /* Draw a hollow box cursor on window W in glyph row ROW. */
8954 x_draw_hollow_cursor (w
, row
)
8956 struct glyph_row
*row
;
8958 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8959 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
8960 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
8963 struct glyph
*cursor_glyph
;
8966 /* Compute frame-relative coordinates from window-relative
8968 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
8969 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
8970 + row
->ascent
- w
->phys_cursor_ascent
);
8971 h
= row
->height
- 1;
8973 /* Get the glyph the cursor is on. If we can't tell because
8974 the current matrix is invalid or such, give up. */
8975 cursor_glyph
= get_phys_cursor_glyph (w
);
8976 if (cursor_glyph
== NULL
)
8979 /* Compute the width of the rectangle to draw. If on a stretch
8980 glyph, and `x-stretch-block-cursor' is nil, don't draw a
8981 rectangle as wide as the glyph, but use a canonical character
8983 wd
= cursor_glyph
->pixel_width
- 1;
8984 if (cursor_glyph
->type
== STRETCH_GLYPH
8985 && !x_stretch_cursor_p
)
8986 wd
= min (CANON_X_UNIT (f
), wd
);
8988 /* The foreground of cursor_gc is typically the same as the normal
8989 background color, which can cause the cursor box to be invisible. */
8990 xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
8991 if (dpyinfo
->scratch_cursor_gc
)
8992 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
8994 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_MAC_WINDOW (f
),
8995 GCForeground
, &xgcv
);
8996 gc
= dpyinfo
->scratch_cursor_gc
;
8998 /* Set clipping, draw the rectangle, and reset clipping again. */
8999 x_clip_to_row (w
, row
, gc
, 0);
9000 mac_draw_rectangle (dpy
, FRAME_MAC_WINDOW (f
), gc
, x
, y
, wd
, h
);
9001 mac_reset_clipping (dpy
, FRAME_MAC_WINDOW (f
));
9005 /* Draw a bar cursor on window W in glyph row ROW.
9007 Implementation note: One would like to draw a bar cursor with an
9008 angle equal to the one given by the font property XA_ITALIC_ANGLE.
9009 Unfortunately, I didn't find a font yet that has this property set.
9013 x_draw_bar_cursor (w
, row
, width
)
9015 struct glyph_row
*row
;
9018 /* If cursor hpos is out of bounds, don't draw garbage. This can
9019 happen in mini-buffer windows when switching between echo area
9020 glyphs and mini-buffer. */
9021 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
9023 struct frame
*f
= XFRAME (w
->frame
);
9024 struct glyph
*cursor_glyph
;
9032 cursor_glyph
= get_phys_cursor_glyph (w
);
9033 if (cursor_glyph
== NULL
)
9036 xgcv
.background
= f
->output_data
.mac
->cursor_pixel
;
9037 xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
9038 mask
= GCForeground
| GCBackground
;
9039 dpy
= FRAME_MAC_DISPLAY (f
);
9040 window
= FRAME_MAC_WINDOW (f
);
9041 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
9044 XChangeGC (dpy
, gc
, mask
, &xgcv
);
9047 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
9048 FRAME_MAC_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
9052 width
= f
->output_data
.mac
->cursor_width
;
9054 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9055 x_clip_to_row (w
, row
, gc
, 0);
9056 XFillRectangle (dpy
, window
, gc
,
9058 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
9059 min (cursor_glyph
->pixel_width
, width
),
9061 mac_reset_clipping (dpy
, FRAME_MAC_WINDOW (f
));
9066 /* Clear the cursor of window W to background color, and mark the
9067 cursor as not shown. This is used when the text where the cursor
9068 is is about to be rewritten. */
9074 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
9075 x_update_window_cursor (w
, 0);
9079 /* Draw the cursor glyph of window W in glyph row ROW. See the
9080 comment of x_draw_glyphs for the meaning of HL. */
9083 x_draw_phys_cursor_glyph (w
, row
, hl
)
9085 struct glyph_row
*row
;
9086 enum draw_glyphs_face hl
;
9088 /* If cursor hpos is out of bounds, don't draw garbage. This can
9089 happen in mini-buffer windows when switching between echo area
9090 glyphs and mini-buffer. */
9091 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
9093 int on_p
= w
->phys_cursor_on_p
;
9094 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
9095 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
9097 w
->phys_cursor_on_p
= on_p
;
9099 /* When we erase the cursor, and ROW is overlapped by other
9100 rows, make sure that these overlapping parts of other rows
9102 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
9104 if (row
> w
->current_matrix
->rows
9105 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
9106 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
9108 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
9109 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
9110 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
9116 /* Erase the image of a cursor of window W from the screen. */
9119 x_erase_phys_cursor (w
)
9122 struct frame
*f
= XFRAME (w
->frame
);
9123 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9124 int hpos
= w
->phys_cursor
.hpos
;
9125 int vpos
= w
->phys_cursor
.vpos
;
9126 int mouse_face_here_p
= 0;
9127 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
9128 struct glyph_row
*cursor_row
;
9129 struct glyph
*cursor_glyph
;
9130 enum draw_glyphs_face hl
;
9132 /* No cursor displayed or row invalidated => nothing to do on the
9134 if (w
->phys_cursor_type
== NO_CURSOR
)
9135 goto mark_cursor_off
;
9137 /* VPOS >= active_glyphs->nrows means that window has been resized.
9138 Don't bother to erase the cursor. */
9139 if (vpos
>= active_glyphs
->nrows
)
9140 goto mark_cursor_off
;
9142 /* If row containing cursor is marked invalid, there is nothing we
9144 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
9145 if (!cursor_row
->enabled_p
)
9146 goto mark_cursor_off
;
9148 /* If row is completely invisible, don't attempt to delete a cursor which
9149 isn't there. This may happen if cursor is at top of window, and
9150 we switch to a buffer with a header line in that window. */
9151 if (cursor_row
->visible_height
<= 0)
9152 goto mark_cursor_off
;
9154 /* This can happen when the new row is shorter than the old one.
9155 In this case, either x_draw_glyphs or clear_end_of_line
9156 should have cleared the cursor. Note that we wouldn't be
9157 able to erase the cursor in this case because we don't have a
9158 cursor glyph at hand. */
9159 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
9160 goto mark_cursor_off
;
9162 /* If the cursor is in the mouse face area, redisplay that when
9163 we clear the cursor. */
9164 if (! NILP (dpyinfo
->mouse_face_window
)
9165 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
9166 && (vpos
> dpyinfo
->mouse_face_beg_row
9167 || (vpos
== dpyinfo
->mouse_face_beg_row
9168 && hpos
>= dpyinfo
->mouse_face_beg_col
))
9169 && (vpos
< dpyinfo
->mouse_face_end_row
9170 || (vpos
== dpyinfo
->mouse_face_end_row
9171 && hpos
< dpyinfo
->mouse_face_end_col
))
9172 /* Don't redraw the cursor's spot in mouse face if it is at the
9173 end of a line (on a newline). The cursor appears there, but
9174 mouse highlighting does not. */
9175 && cursor_row
->used
[TEXT_AREA
] > hpos
)
9176 mouse_face_here_p
= 1;
9178 /* Maybe clear the display under the cursor. */
9179 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
9182 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9184 cursor_glyph
= get_phys_cursor_glyph (w
);
9185 if (cursor_glyph
== NULL
)
9186 goto mark_cursor_off
;
9188 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
9190 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
9192 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
9194 cursor_glyph
->pixel_width
,
9195 cursor_row
->visible_height
,
9199 /* Erase the cursor by redrawing the character underneath it. */
9200 if (mouse_face_here_p
)
9201 hl
= DRAW_MOUSE_FACE
;
9203 hl
= DRAW_NORMAL_TEXT
;
9204 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
9207 w
->phys_cursor_on_p
= 0;
9208 w
->phys_cursor_type
= NO_CURSOR
;
9212 /* Non-zero if physical cursor of window W is within mouse face. */
9215 cursor_in_mouse_face_p (w
)
9218 struct mac_display_info
*dpyinfo
9219 = FRAME_MAC_DISPLAY_INFO (XFRAME (w
->frame
));
9220 int in_mouse_face
= 0;
9222 if (WINDOWP (dpyinfo
->mouse_face_window
)
9223 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
9225 int hpos
= w
->phys_cursor
.hpos
;
9226 int vpos
= w
->phys_cursor
.vpos
;
9228 if (vpos
>= dpyinfo
->mouse_face_beg_row
9229 && vpos
<= dpyinfo
->mouse_face_end_row
9230 && (vpos
> dpyinfo
->mouse_face_beg_row
9231 || hpos
>= dpyinfo
->mouse_face_beg_col
)
9232 && (vpos
< dpyinfo
->mouse_face_end_row
9233 || hpos
< dpyinfo
->mouse_face_end_col
9234 || dpyinfo
->mouse_face_past_end
))
9238 return in_mouse_face
;
9242 /* Display or clear cursor of window W. If ON is zero, clear the
9243 cursor. If it is non-zero, display the cursor. If ON is nonzero,
9244 where to put the cursor is specified by HPOS, VPOS, X and Y. */
9247 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
9249 int on
, hpos
, vpos
, x
, y
;
9251 struct frame
*f
= XFRAME (w
->frame
);
9252 int new_cursor_type
;
9253 int new_cursor_width
;
9254 struct glyph_matrix
*current_glyphs
;
9255 struct glyph_row
*glyph_row
;
9256 struct glyph
*glyph
;
9257 int cursor_non_selected
;
9258 int active_cursor
= 1;
9260 /* This is pointless on invisible frames, and dangerous on garbaged
9261 windows and frames; in the latter case, the frame or window may
9262 be in the midst of changing its size, and x and y may be off the
9264 if (! FRAME_VISIBLE_P (f
)
9265 || FRAME_GARBAGED_P (f
)
9266 || vpos
>= w
->current_matrix
->nrows
9267 || hpos
>= w
->current_matrix
->matrix_w
)
9270 /* If cursor is off and we want it off, return quickly. */
9271 if (!on
&& !w
->phys_cursor_on_p
)
9274 current_glyphs
= w
->current_matrix
;
9275 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
9276 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
9278 /* If cursor row is not enabled, we don't really know where to
9279 display the cursor. */
9280 if (!glyph_row
->enabled_p
)
9282 w
->phys_cursor_on_p
= 0;
9286 xassert (interrupt_input_blocked
);
9288 /* Set new_cursor_type to the cursor we want to be displayed. In a
9289 mini-buffer window, we want the cursor only to appear if we are
9290 reading input from this window. For the selected window, we want
9291 the cursor type given by the frame parameter. If explicitly
9292 marked off, draw no cursor. In all other cases, we want a hollow
9295 = !NILP (Fbuffer_local_value (Qcursor_in_non_selected_windows
,
9297 new_cursor_width
= -1;
9298 if (cursor_in_echo_area
9299 && FRAME_HAS_MINIBUF_P (f
)
9300 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
9302 if (w
== XWINDOW (echo_area_window
))
9303 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
9306 if (cursor_non_selected
)
9307 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9309 new_cursor_type
= NO_CURSOR
;
9315 if (f
!= FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
9316 || w
!= XWINDOW (f
->selected_window
))
9320 if (MINI_WINDOW_P (w
)
9321 || !cursor_non_selected
9322 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
9323 new_cursor_type
= NO_CURSOR
;
9325 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9329 struct buffer
*b
= XBUFFER (w
->buffer
);
9331 if (EQ (b
->cursor_type
, Qt
))
9332 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
9334 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
9336 if (w
->cursor_off_p
)
9338 if (new_cursor_type
== FILLED_BOX_CURSOR
)
9339 new_cursor_type
= HOLLOW_BOX_CURSOR
;
9340 else if (new_cursor_type
== BAR_CURSOR
&& new_cursor_width
> 1)
9341 new_cursor_width
= 1;
9343 new_cursor_type
= NO_CURSOR
;
9348 /* If cursor is currently being shown and we don't want it to be or
9349 it is in the wrong place, or the cursor type is not what we want,
9351 if (w
->phys_cursor_on_p
9353 || w
->phys_cursor
.x
!= x
9354 || w
->phys_cursor
.y
!= y
9355 || new_cursor_type
!= w
->phys_cursor_type
9356 || (new_cursor_type
== BAR_CURSOR
9357 && new_cursor_width
!= w
->phys_cursor_width
)))
9358 x_erase_phys_cursor (w
);
9360 /* If the cursor is now invisible and we want it to be visible,
9362 if (on
&& !w
->phys_cursor_on_p
)
9364 w
->phys_cursor_ascent
= glyph_row
->ascent
;
9365 w
->phys_cursor_height
= glyph_row
->height
;
9367 /* Set phys_cursor_.* before x_draw_.* is called because some
9368 of them may need the information. */
9369 w
->phys_cursor
.x
= x
;
9370 w
->phys_cursor
.y
= glyph_row
->y
;
9371 w
->phys_cursor
.hpos
= hpos
;
9372 w
->phys_cursor
.vpos
= vpos
;
9373 w
->phys_cursor_type
= new_cursor_type
;
9374 w
->phys_cursor_width
= new_cursor_width
;
9375 w
->phys_cursor_on_p
= 1;
9377 switch (new_cursor_type
)
9379 case HOLLOW_BOX_CURSOR
:
9380 x_draw_hollow_cursor (w
, glyph_row
);
9383 case FILLED_BOX_CURSOR
:
9384 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
9388 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
9401 /* Display the cursor on window W, or clear it. X and Y are window
9402 relative pixel coordinates. HPOS and VPOS are glyph matrix
9403 positions. If W is not the selected window, display a hollow
9404 cursor. ON non-zero means display the cursor at X, Y which
9405 correspond to HPOS, VPOS, otherwise it is cleared. */
9408 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
9410 int on
, hpos
, vpos
, x
, y
;
9413 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
9418 /* Display the cursor on window W, or clear it, according to ON_P.
9419 Don't change the cursor's position. */
9422 x_update_cursor (f
, on_p
)
9426 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
9430 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
9431 in the window tree rooted at W. */
9434 x_update_cursor_in_window_tree (w
, on_p
)
9440 if (!NILP (w
->hchild
))
9441 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
9442 else if (!NILP (w
->vchild
))
9443 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
9445 x_update_window_cursor (w
, on_p
);
9447 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
9452 /* Switch the display of W's cursor on or off, according to the value
9456 x_update_window_cursor (w
, on
)
9460 /* Don't update cursor in windows whose frame is in the process
9461 of being deleted. */
9462 if (w
->current_matrix
)
9465 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
,
9466 w
->phys_cursor
.vpos
, w
->phys_cursor
.x
,
9477 #if 0 /* MAC_TODO: no icon support yet. */
9479 x_bitmap_icon (f
, icon
)
9485 if (FRAME_W32_WINDOW (f
) == 0)
9489 hicon
= LoadIcon (hinst
, EMACS_CLASS
);
9490 else if (STRINGP (icon
))
9491 hicon
= LoadImage (NULL
, (LPCTSTR
) SDATA (icon
), IMAGE_ICON
, 0, 0,
9492 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
9493 else if (SYMBOLP (icon
))
9497 if (EQ (icon
, intern ("application")))
9498 name
= (LPCTSTR
) IDI_APPLICATION
;
9499 else if (EQ (icon
, intern ("hand")))
9500 name
= (LPCTSTR
) IDI_HAND
;
9501 else if (EQ (icon
, intern ("question")))
9502 name
= (LPCTSTR
) IDI_QUESTION
;
9503 else if (EQ (icon
, intern ("exclamation")))
9504 name
= (LPCTSTR
) IDI_EXCLAMATION
;
9505 else if (EQ (icon
, intern ("asterisk")))
9506 name
= (LPCTSTR
) IDI_ASTERISK
;
9507 else if (EQ (icon
, intern ("winlogo")))
9508 name
= (LPCTSTR
) IDI_WINLOGO
;
9512 hicon
= LoadIcon (NULL
, name
);
9520 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
9525 #endif /* MAC_TODO */
9527 /************************************************************************
9529 ************************************************************************/
9531 /* Display Error Handling functions not used on W32. Listing them here
9532 helps diff stay in step when comparing w32term.c with xterm.c.
9534 x_error_catcher (display, error)
9535 x_catch_errors (dpy)
9536 x_catch_errors_unwind (old_val)
9537 x_check_errors (dpy, format)
9538 x_had_errors_p (dpy)
9539 x_clear_errors (dpy)
9540 x_uncatch_errors (dpy, count)
9542 x_connection_signal (signalnum)
9543 x_connection_closed (dpy, error_message)
9544 x_error_quitter (display, error)
9545 x_error_handler (display, error)
9546 x_io_error_quitter (display)
9551 /* Changing the font of the frame. */
9553 /* Give frame F the font named FONTNAME as its default font, and
9554 return the full name of that font. FONTNAME may be a wildcard
9555 pattern; in that case, we choose some font that fits the pattern.
9556 The return value shows which font we chose. */
9559 x_new_font (f
, fontname
)
9561 register char *fontname
;
9563 struct font_info
*fontp
9564 = FS_LOAD_FONT (f
, 0, fontname
, -1);
9569 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
9570 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
9571 FRAME_FONTSET (f
) = -1;
9573 /* Compute the scroll bar width in character columns. */
9574 if (f
->scroll_bar_pixel_width
> 0)
9576 int wid
= FONT_WIDTH (FRAME_FONT (f
));
9577 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
9581 int wid
= FONT_WIDTH (FRAME_FONT (f
));
9582 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
9585 /* Now make the frame display the given font. */
9586 if (FRAME_MAC_WINDOW (f
) != 0)
9588 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->normal_gc
,
9589 f
->output_data
.mac
->font
);
9590 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->reverse_gc
,
9591 f
->output_data
.mac
->font
);
9592 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->cursor_gc
,
9593 f
->output_data
.mac
->font
);
9595 frame_update_line_height (f
);
9596 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
9597 x_set_window_size (f
, 0, f
->width
, f
->height
);
9600 /* If we are setting a new frame's font for the first time,
9601 there are no faces yet, so this font's height is the line height. */
9602 f
->output_data
.mac
->line_height
= FONT_HEIGHT (FRAME_FONT (f
));
9604 return build_string (fontp
->full_name
);
9607 /* Give frame F the fontset named FONTSETNAME as its default font, and
9608 return the full name of that fontset. FONTSETNAME may be a wildcard
9609 pattern; in that case, we choose some fontset that fits the pattern.
9610 The return value shows which fontset we chose. */
9613 x_new_fontset (f
, fontsetname
)
9617 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
9623 if (FRAME_FONTSET (f
) == fontset
)
9624 /* This fontset is already set in frame F. There's nothing more
9626 return fontset_name (fontset
);
9628 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
9630 if (!STRINGP (result
))
9631 /* Can't load ASCII font. */
9634 /* Since x_new_font doesn't update any fontset information, do it now. */
9635 FRAME_FONTSET(f
) = fontset
;
9637 return build_string (fontsetname
);
9640 /* Compute actual fringe widths */
9643 x_compute_fringe_widths (f
, redraw
)
9647 int o_left
= f
->output_data
.mac
->left_fringe_width
;
9648 int o_right
= f
->output_data
.mac
->right_fringe_width
;
9649 int o_cols
= f
->output_data
.mac
->fringe_cols
;
9651 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
9652 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
9653 int left_fringe_width
, right_fringe_width
;
9655 if (!NILP (left_fringe
))
9656 left_fringe
= Fcdr (left_fringe
);
9657 if (!NILP (right_fringe
))
9658 right_fringe
= Fcdr (right_fringe
);
9660 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
9661 XINT (left_fringe
));
9662 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
9663 XINT (right_fringe
));
9665 if (left_fringe_width
|| right_fringe_width
)
9667 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
9668 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
9669 int conf_wid
= left_wid
+ right_wid
;
9670 int font_wid
= FONT_WIDTH (f
->output_data
.mac
->font
);
9671 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
9672 int real_wid
= cols
* font_wid
;
9673 if (left_wid
&& right_wid
)
9675 if (left_fringe_width
< 0)
9677 /* Left fringe width is fixed, adjust right fringe if necessary */
9678 f
->output_data
.mac
->left_fringe_width
= left_wid
;
9679 f
->output_data
.mac
->right_fringe_width
= real_wid
- left_wid
;
9681 else if (right_fringe_width
< 0)
9683 /* Right fringe width is fixed, adjust left fringe if necessary */
9684 f
->output_data
.mac
->left_fringe_width
= real_wid
- right_wid
;
9685 f
->output_data
.mac
->right_fringe_width
= right_wid
;
9689 /* Adjust both fringes with an equal amount.
9690 Note that we are doing integer arithmetic here, so don't
9691 lose a pixel if the total width is an odd number. */
9692 int fill
= real_wid
- conf_wid
;
9693 f
->output_data
.mac
->left_fringe_width
= left_wid
+ fill
/2;
9694 f
->output_data
.mac
->right_fringe_width
= right_wid
+ fill
- fill
/2;
9697 else if (left_fringe_width
)
9699 f
->output_data
.mac
->left_fringe_width
= real_wid
;
9700 f
->output_data
.mac
->right_fringe_width
= 0;
9704 f
->output_data
.mac
->left_fringe_width
= 0;
9705 f
->output_data
.mac
->right_fringe_width
= real_wid
;
9707 f
->output_data
.mac
->fringe_cols
= cols
;
9708 f
->output_data
.mac
->fringes_extra
= real_wid
;
9712 f
->output_data
.mac
->left_fringe_width
= 0;
9713 f
->output_data
.mac
->right_fringe_width
= 0;
9714 f
->output_data
.mac
->fringe_cols
= 0;
9715 f
->output_data
.mac
->fringes_extra
= 0;
9718 if (redraw
&& FRAME_VISIBLE_P (f
))
9719 if (o_left
!= f
->output_data
.mac
->left_fringe_width
||
9720 o_right
!= f
->output_data
.mac
->right_fringe_width
||
9721 o_cols
!= f
->output_data
.mac
->fringe_cols
)
9725 /***********************************************************************
9726 TODO: W32 Input Methods
9727 ***********************************************************************/
9728 /* Listing missing functions from xterm.c helps diff stay in step.
9730 xim_destroy_callback (xim, client_data, call_data)
9731 xim_open_dpy (dpyinfo, resource_name)
9733 xim_instantiate_callback (display, client_data, call_data)
9734 xim_initialize (dpyinfo, resource_name)
9735 xim_close_dpy (dpyinfo)
9740 /* Calculate the absolute position in frame F
9741 from its current recorded position values and gravity. */
9744 x_calc_absolute_position (f
)
9748 int flags
= f
->output_data
.mac
->size_hint_flags
;
9752 /* Find the position of the outside upper-left corner of
9753 the inner window, with respect to the outer window. */
9754 if (f
->output_data
.mac
->parent_desc
!= FRAME_MAC_DISPLAY_INFO (f
)->root_window
)
9757 GetPort (&savePort
);
9759 #if TARGET_API_MAC_CARBON
9760 SetPort (GetWindowPort (FRAME_MAC_WINDOW (f
)));
9762 SetPort (FRAME_MAC_WINDOW (f
));
9765 #if TARGET_API_MAC_CARBON
9769 GetWindowPortBounds (FRAME_MAC_WINDOW (f
), &r
);
9770 SetPt(&pt
, r
.left
, r
.top
);
9772 #else /* not TARGET_API_MAC_CARBON */
9773 SetPt(&pt
, FRAME_MAC_WINDOW (f
)->portRect
.left
, FRAME_MAC_WINDOW (f
)->portRect
.top
);
9774 #endif /* not TARGET_API_MAC_CARBON */
9775 LocalToGlobal (&pt
);
9779 /* Treat negative positions as relative to the leftmost bottommost
9780 position that fits on the screen. */
9781 if (flags
& XNegative
)
9782 f
->output_data
.mac
->left_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->width
9783 - 2 * f
->output_data
.mac
->border_width
- pt
.h
9785 + f
->output_data
.mac
->left_pos
);
9786 /* NTEMACS_TODO: Subtract menubar height? */
9787 if (flags
& YNegative
)
9788 f
->output_data
.mac
->top_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->height
9789 - 2 * f
->output_data
.mac
->border_width
- pt
.v
9791 + f
->output_data
.mac
->top_pos
);
9792 /* The left_pos and top_pos
9793 are now relative to the top and left screen edges,
9794 so the flags should correspond. */
9795 f
->output_data
.mac
->size_hint_flags
&= ~ (XNegative
| YNegative
);
9798 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
9799 to really change the position, and 0 when calling from
9800 x_make_frame_visible (in that case, XOFF and YOFF are the current
9801 position values). It is -1 when calling from x_set_frame_parameters,
9802 which means, do adjust for borders but don't change the gravity. */
9805 x_set_offset (f
, xoff
, yoff
, change_gravity
)
9807 register int xoff
, yoff
;
9810 int modified_top
, modified_left
;
9812 if (change_gravity
> 0)
9814 f
->output_data
.mac
->top_pos
= yoff
;
9815 f
->output_data
.mac
->left_pos
= xoff
;
9816 f
->output_data
.mac
->size_hint_flags
&= ~ (XNegative
| YNegative
);
9818 f
->output_data
.mac
->size_hint_flags
|= XNegative
;
9820 f
->output_data
.mac
->size_hint_flags
|= YNegative
;
9821 f
->output_data
.mac
->win_gravity
= NorthWestGravity
;
9823 x_calc_absolute_position (f
);
9826 x_wm_set_size_hint (f
, (long) 0, 0);
9828 modified_left
= f
->output_data
.mac
->left_pos
;
9829 modified_top
= f
->output_data
.mac
->top_pos
;
9831 MoveWindow (f
->output_data
.mac
->mWP
, modified_left
+ 6,
9832 modified_top
+ 42, false);
9837 /* Call this to change the size of frame F's x-window.
9838 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
9839 for this size change and subsequent size changes.
9840 Otherwise we leave the window gravity unchanged. */
9843 x_set_window_size (f
, change_gravity
, cols
, rows
)
9848 int pixelwidth
, pixelheight
;
9852 check_frame_size (f
, &rows
, &cols
);
9853 f
->output_data
.mac
->vertical_scroll_bar_extra
9854 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
9856 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.mac
->font
)));
9858 x_compute_fringe_widths (f
, 0);
9860 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
9861 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
9863 f
->output_data
.mac
->win_gravity
= NorthWestGravity
;
9864 x_wm_set_size_hint (f
, (long) 0, 0);
9866 SizeWindow (FRAME_MAC_WINDOW (f
), pixelwidth
, pixelheight
, 0);
9868 /* Now, strictly speaking, we can't be sure that this is accurate,
9869 but the window manager will get around to dealing with the size
9870 change request eventually, and we'll hear how it went when the
9871 ConfigureNotify event gets here.
9873 We could just not bother storing any of this information here,
9874 and let the ConfigureNotify event set everything up, but that
9875 might be kind of confusing to the Lisp code, since size changes
9876 wouldn't be reported in the frame parameters until some random
9877 point in the future when the ConfigureNotify event arrives.
9879 We pass 1 for DELAY since we can't run Lisp code inside of
9881 change_frame_size (f
, rows
, cols
, 0, 1, 0);
9882 PIXEL_WIDTH (f
) = pixelwidth
;
9883 PIXEL_HEIGHT (f
) = pixelheight
;
9885 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
9886 receive in the ConfigureNotify event; if we get what we asked
9887 for, then the event won't cause the screen to become garbaged, so
9888 we have to make sure to do it here. */
9889 SET_FRAME_GARBAGED (f
);
9891 XFlush (FRAME_X_DISPLAY (f
));
9893 /* If cursor was outside the new size, mark it as off. */
9894 mark_window_cursors_off (XWINDOW (f
->root_window
));
9896 /* Clear out any recollection of where the mouse highlighting was,
9897 since it might be in a place that's outside the new frame size.
9898 Actually checking whether it is outside is a pain in the neck,
9899 so don't try--just let the highlighting be done afresh with new size. */
9900 cancel_mouse_face (f
);
9905 /* Mouse warping. */
9907 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
9910 x_set_mouse_position (f
, x
, y
)
9916 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.mac
->font
) / 2;
9917 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.mac
->line_height
/ 2;
9919 if (pix_x
< 0) pix_x
= 0;
9920 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
9922 if (pix_y
< 0) pix_y
= 0;
9923 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
9925 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
9929 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
9933 #if 0 /* MAC_TODO: CursorDeviceMoveTo is non-Carbon */
9936 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
9937 0, 0, 0, 0, pix_x
, pix_y
);
9943 /* focus shifting, raising and lowering. */
9946 x_focus_on_frame (f
)
9949 #if 0 /* This proves to be unpleasant. */
9953 /* I don't think that the ICCCM allows programs to do things like this
9954 without the interaction of the window manager. Whatever you end up
9955 doing with this code, do it to x_unfocus_frame too. */
9956 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9957 RevertToPointerRoot
, CurrentTime
);
9967 /* Raise frame F. */
9972 if (f
->async_visible
)
9973 SelectWindow (FRAME_MAC_WINDOW (f
));
9976 /* Lower frame F. */
9981 if (f
->async_visible
)
9982 SendBehind (FRAME_MAC_WINDOW (f
), nil
);
9986 XTframe_raise_lower (f
, raise_flag
)
9996 /* Change of visibility. */
9998 /* This tries to wait until the frame is really visible.
9999 However, if the window manager asks the user where to position
10000 the frame, this will return before the user finishes doing that.
10001 The frame will not actually be visible at that time,
10002 but it will become visible later when the window manager
10003 finishes with it. */
10006 x_make_frame_visible (f
)
10010 int original_top
, original_left
;
10014 if (! FRAME_VISIBLE_P (f
))
10016 /* We test FRAME_GARBAGED_P here to make sure we don't
10017 call x_set_offset a second time
10018 if we get to x_make_frame_visible a second time
10019 before the window gets really visible. */
10020 if (! FRAME_ICONIFIED_P (f
)
10021 && ! f
->output_data
.mac
->asked_for_visible
)
10022 x_set_offset (f
, f
->output_data
.mac
->left_pos
,
10023 f
->output_data
.mac
->top_pos
, 0);
10025 f
->output_data
.mac
->asked_for_visible
= 1;
10027 ShowWindow (FRAME_MAC_WINDOW (f
));
10030 XFlush (FRAME_MAC_DISPLAY (f
));
10032 #if 0 /* MAC_TODO */
10033 /* Synchronize to ensure Emacs knows the frame is visible
10034 before we do anything else. We do this loop with input not blocked
10035 so that incoming events are handled. */
10040 /* This must come after we set COUNT. */
10043 XSETFRAME (frame
, f
);
10045 /* Wait until the frame is visible. Process X events until a
10046 MapNotify event has been seen, or until we think we won't get a
10047 MapNotify at all.. */
10048 for (count
= input_signal_count
+ 10;
10049 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
10051 /* Force processing of queued events. */
10054 /* Machines that do polling rather than SIGIO have been
10055 observed to go into a busy-wait here. So we'll fake an
10056 alarm signal to let the handler know that there's something
10057 to be read. We used to raise a real alarm, but it seems
10058 that the handler isn't always enabled here. This is
10060 if (input_polling_used ())
10062 /* It could be confusing if a real alarm arrives while
10063 processing the fake one. Turn it off and let the
10064 handler reset it. */
10065 extern void poll_for_input_1
P_ ((void));
10066 int old_poll_suppress_count
= poll_suppress_count
;
10067 poll_suppress_count
= 1;
10068 poll_for_input_1 ();
10069 poll_suppress_count
= old_poll_suppress_count
;
10072 /* See if a MapNotify event has been processed. */
10073 FRAME_SAMPLE_VISIBILITY (f
);
10076 #endif /* MAC_TODO */
10079 /* Change from mapped state to withdrawn state. */
10081 /* Make the frame visible (mapped and not iconified). */
10084 x_make_frame_invisible (f
)
10087 /* Don't keep the highlight on an invisible frame. */
10088 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
10089 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
10093 HideWindow (FRAME_MAC_WINDOW (f
));
10095 /* We can't distinguish this from iconification
10096 just by the event that we get from the server.
10097 So we can't win using the usual strategy of letting
10098 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
10099 and synchronize with the server to make sure we agree. */
10101 FRAME_ICONIFIED_P (f
) = 0;
10102 f
->async_visible
= 0;
10103 f
->async_iconified
= 0;
10108 /* Change window state from mapped to iconified. */
10111 x_iconify_frame (f
)
10114 /* Don't keep the highlight on an invisible frame. */
10115 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
10116 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
10119 /* Review: Since window is still visible in dock, still allow updates? */
10120 if (f
->async_iconified
)
10126 CollapseWindow (FRAME_MAC_WINDOW (f
), true);
10132 /* Destroy the X window of frame F. */
10135 x_destroy_window (f
)
10138 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
10142 DisposeWindow (FRAME_MAC_WINDOW (f
));
10144 free_frame_menubar (f
);
10145 free_frame_faces (f
);
10147 xfree (f
->output_data
.mac
);
10148 f
->output_data
.mac
= 0;
10149 if (f
== dpyinfo
->x_focus_frame
)
10150 dpyinfo
->x_focus_frame
= 0;
10151 if (f
== dpyinfo
->x_focus_event_frame
)
10152 dpyinfo
->x_focus_event_frame
= 0;
10153 if (f
== dpyinfo
->x_highlight_frame
)
10154 dpyinfo
->x_highlight_frame
= 0;
10156 dpyinfo
->reference_count
--;
10158 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10160 dpyinfo
->mouse_face_beg_row
10161 = dpyinfo
->mouse_face_beg_col
= -1;
10162 dpyinfo
->mouse_face_end_row
10163 = dpyinfo
->mouse_face_end_col
= -1;
10164 dpyinfo
->mouse_face_window
= Qnil
;
10165 dpyinfo
->mouse_face_deferred_gc
= 0;
10166 dpyinfo
->mouse_face_mouse_frame
= 0;
10172 /* Setting window manager hints. */
10174 /* Set the normal size hints for the window manager, for frame F.
10175 FLAGS is the flags word to use--or 0 meaning preserve the flags
10176 that the window now has.
10177 If USER_POSITION is nonzero, we set the USPosition
10178 flag (this is useful when FLAGS is 0). */
10180 x_wm_set_size_hint (f
, flags
, user_position
)
10185 #if 0 /* MAC_TODO: connect this to the Appearance Manager */
10186 XSizeHints size_hints
;
10188 #ifdef USE_X_TOOLKIT
10191 Dimension widget_width
, widget_height
;
10192 Window window
= XtWindow (f
->output_data
.x
->widget
);
10193 #else /* not USE_X_TOOLKIT */
10194 Window window
= FRAME_X_WINDOW (f
);
10195 #endif /* not USE_X_TOOLKIT */
10197 /* Setting PMaxSize caused various problems. */
10198 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
10200 size_hints
.x
= f
->output_data
.x
->left_pos
;
10201 size_hints
.y
= f
->output_data
.x
->top_pos
;
10203 #ifdef USE_X_TOOLKIT
10204 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
10205 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
10206 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
10207 size_hints
.height
= widget_height
;
10208 size_hints
.width
= widget_width
;
10209 #else /* not USE_X_TOOLKIT */
10210 size_hints
.height
= PIXEL_HEIGHT (f
);
10211 size_hints
.width
= PIXEL_WIDTH (f
);
10212 #endif /* not USE_X_TOOLKIT */
10214 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
10215 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
10216 size_hints
.max_width
10217 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
10218 size_hints
.max_height
10219 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
10221 /* Calculate the base and minimum sizes.
10223 (When we use the X toolkit, we don't do it here.
10224 Instead we copy the values that the widgets are using, below.) */
10225 #ifndef USE_X_TOOLKIT
10227 int base_width
, base_height
;
10228 int min_rows
= 0, min_cols
= 0;
10230 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
10231 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
10233 check_frame_size (f
, &min_rows
, &min_cols
);
10235 /* The window manager uses the base width hints to calculate the
10236 current number of rows and columns in the frame while
10237 resizing; min_width and min_height aren't useful for this
10238 purpose, since they might not give the dimensions for a
10239 zero-row, zero-column frame.
10241 We use the base_width and base_height members if we have
10242 them; otherwise, we set the min_width and min_height members
10243 to the size for a zero x zero frame. */
10246 size_hints
.flags
|= PBaseSize
;
10247 size_hints
.base_width
= base_width
;
10248 size_hints
.base_height
= base_height
;
10249 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
10250 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
10252 size_hints
.min_width
= base_width
;
10253 size_hints
.min_height
= base_height
;
10257 /* If we don't need the old flags, we don't need the old hint at all. */
10260 size_hints
.flags
|= flags
;
10263 #endif /* not USE_X_TOOLKIT */
10266 XSizeHints hints
; /* Sometimes I hate X Windows... */
10267 long supplied_return
;
10271 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
10274 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
10277 #ifdef USE_X_TOOLKIT
10278 size_hints
.base_height
= hints
.base_height
;
10279 size_hints
.base_width
= hints
.base_width
;
10280 size_hints
.min_height
= hints
.min_height
;
10281 size_hints
.min_width
= hints
.min_width
;
10285 size_hints
.flags
|= flags
;
10290 if (hints
.flags
& PSize
)
10291 size_hints
.flags
|= PSize
;
10292 if (hints
.flags
& PPosition
)
10293 size_hints
.flags
|= PPosition
;
10294 if (hints
.flags
& USPosition
)
10295 size_hints
.flags
|= USPosition
;
10296 if (hints
.flags
& USSize
)
10297 size_hints
.flags
|= USSize
;
10301 #ifndef USE_X_TOOLKIT
10306 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
10307 size_hints
.flags
|= PWinGravity
;
10311 size_hints
.flags
&= ~ PPosition
;
10312 size_hints
.flags
|= USPosition
;
10314 #endif /* PWinGravity */
10317 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
10319 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
10321 #endif /* MAC_TODO */
10324 #if 0 /* MAC_TODO: hide application instead of iconify? */
10325 /* Used for IconicState or NormalState */
10328 x_wm_set_window_state (f
, state
)
10332 #ifdef USE_X_TOOLKIT
10335 XtSetArg (al
[0], XtNinitialState
, state
);
10336 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
10337 #else /* not USE_X_TOOLKIT */
10338 Window window
= FRAME_X_WINDOW (f
);
10340 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
10341 f
->output_data
.x
->wm_hints
.initial_state
= state
;
10343 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10344 #endif /* not USE_X_TOOLKIT */
10348 x_wm_set_icon_pixmap (f
, pixmap_id
)
10352 Pixmap icon_pixmap
;
10354 #ifndef USE_X_TOOLKIT
10355 Window window
= FRAME_X_WINDOW (f
);
10360 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
10361 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
10365 /* It seems there is no way to turn off use of an icon pixmap.
10366 The following line does it, only if no icon has yet been created,
10367 for some window managers. But with mwm it crashes.
10368 Some people say it should clear the IconPixmapHint bit in this case,
10369 but that doesn't work, and the X consortium said it isn't the
10370 right thing at all. Since there is no way to win,
10371 best to explicitly give up. */
10373 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
10379 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
10383 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
10384 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
10387 #else /* not USE_X_TOOLKIT */
10389 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
10390 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10392 #endif /* not USE_X_TOOLKIT */
10395 #endif /* MAC_TODO */
10398 x_wm_set_icon_position (f
, icon_x
, icon_y
)
10400 int icon_x
, icon_y
;
10402 #if 0 /* MAC_TODO: no icons on Mac */
10403 #ifdef USE_X_TOOLKIT
10404 Window window
= XtWindow (f
->output_data
.x
->widget
);
10406 Window window
= FRAME_X_WINDOW (f
);
10409 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
10410 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
10411 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
10413 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10414 #endif /* MAC_TODO */
10418 /***********************************************************************
10420 ***********************************************************************/
10422 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
10425 x_get_font_info (f
, font_idx
)
10429 return (FRAME_MAC_FONT_TABLE (f
) + font_idx
);
10432 /* the global font name table */
10433 char **font_name_table
= NULL
;
10434 int font_name_table_size
= 0;
10435 int font_name_count
= 0;
10437 /* compare two strings ignoring case */
10439 stricmp (const char *s
, const char *t
)
10441 for ( ; tolower (*s
) == tolower (*t
); s
++, t
++)
10444 return tolower (*s
) - tolower (*t
);
10447 /* compare two strings ignoring case and handling wildcard */
10449 wildstrieq (char *s1
, char *s2
)
10451 if (strcmp (s1
, "*") == 0 || strcmp (s2
, "*") == 0)
10454 return stricmp (s1
, s2
) == 0;
10457 /* Assume parameter 1 is fully qualified, no wildcards. */
10459 mac_font_pattern_match (fontname
, pattern
)
10463 char *regex
= (char *) alloca (strlen (pattern
) * 2 + 3);
10464 char *font_name_copy
= (char *) alloca (strlen (fontname
) + 1);
10467 /* Copy fontname so we can modify it during comparison. */
10468 strcpy (font_name_copy
, fontname
);
10473 /* Turn pattern into a regexp and do a regexp match. */
10474 for (; *pattern
; pattern
++)
10476 if (*pattern
== '?')
10478 else if (*pattern
== '*')
10489 return (fast_c_string_match_ignore_case (build_string (regex
),
10490 font_name_copy
) >= 0);
10493 /* Two font specs are considered to match if their foundry, family,
10494 weight, slant, and charset match. */
10496 mac_font_match (char *mf
, char *xf
)
10498 char m_foundry
[50], m_family
[50], m_weight
[20], m_slant
[2], m_charset
[20];
10499 char x_foundry
[50], x_family
[50], x_weight
[20], x_slant
[2], x_charset
[20];
10501 if (sscanf (mf
, "-%49[^-]-%49[^-]-%19[^-]-%1[^-]-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%19s",
10502 m_foundry
, m_family
, m_weight
, m_slant
, m_charset
) != 5)
10503 return mac_font_pattern_match (mf
, xf
);
10505 if (sscanf (xf
, "-%49[^-]-%49[^-]-%19[^-]-%1[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%19s",
10506 x_foundry
, x_family
, x_weight
, x_slant
, x_charset
) != 5)
10507 return mac_font_pattern_match (mf
, xf
);
10509 return (wildstrieq (m_foundry
, x_foundry
)
10510 && wildstrieq (m_family
, x_family
)
10511 && wildstrieq (m_weight
, x_weight
)
10512 && wildstrieq (m_slant
, x_slant
)
10513 && wildstrieq (m_charset
, x_charset
))
10514 || mac_font_pattern_match (mf
, xf
);
10519 mac_to_x_fontname (char *name
, int size
, Style style
, short scriptcode
)
10521 char foundry
[32], family
[32], cs
[32];
10522 char xf
[255], *result
, *p
;
10524 if (sscanf (name
, "%31[^-]-%31[^-]-%31s", foundry
, family
, cs
) != 3)
10526 strcpy(foundry
, "Apple");
10527 strcpy(family
, name
);
10529 switch (scriptcode
)
10531 case smTradChinese
:
10532 strcpy(cs
, "big5-0");
10534 case smSimpChinese
:
10535 strcpy(cs
, "gb2312.1980-0");
10538 strcpy(cs
, "jisx0208.1983-sjis");
10541 /* Each Apple Japanese font is entered into the font table
10542 twice: once as a jisx0208.1983-sjis font and once as a
10543 jisx0201.1976-0 font. The latter can be used to display
10544 the ascii charset and katakana-jisx0201 charset. A
10545 negative script code signals that the name of this latter
10546 font is being built. */
10547 strcpy(cs
, "jisx0201.1976-0");
10550 strcpy(cs
, "ksc5601.1989-0");
10553 strcpy(cs
, "mac-roman");
10558 sprintf(xf
, "-%s-%s-%s-%c-normal--%d-%d-75-75-m-%d-%s",
10559 foundry
, family
, style
& bold
? "bold" : "medium",
10560 style
& italic
? 'i' : 'r', size
, size
* 10, size
* 10, cs
);
10562 result
= (char *) xmalloc (strlen (xf
) + 1);
10563 strcpy (result
, xf
);
10564 for (p
= result
; *p
; p
++)
10570 /* Convert an X font spec to the corresponding mac font name, which
10571 can then be passed to GetFNum after conversion to a Pascal string.
10572 For ordinary Mac fonts, this should just be their names, like
10573 "monaco", "Taipei", etc. Fonts converted from the GNU intlfonts
10574 collection contain their charset designation in their names, like
10575 "ETL-Fixed-iso8859-1", "ETL-Fixed-koi8-r", etc. Both types of font
10576 names are handled accordingly. */
10578 x_font_name_to_mac_font_name (char *xf
, char *mf
)
10580 char foundry
[32], family
[32], weight
[20], slant
[2], cs
[32];
10584 if (sscanf (xf
, "-%31[^-]-%31[^-]-%19[^-]-%1[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%31s",
10585 foundry
, family
, weight
, slant
, cs
) != 5 &&
10586 sscanf (xf
, "-%31[^-]-%31[^-]-%19[^-]-%1[^-]-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%31s",
10587 foundry
, family
, weight
, slant
, cs
) != 5)
10590 if (strcmp (cs
, "big5-0") == 0 || strcmp (cs
, "gb2312.1980-0") == 0
10591 || strcmp (cs
, "jisx0208.1983-sjis") == 0
10592 || strcmp (cs
, "jisx0201.1976-0") == 0
10593 || strcmp (cs
, "ksc5601.1989-0") == 0 || strcmp (cs
, "mac-roman") == 0)
10594 strcpy(mf
, family
);
10596 sprintf(mf
, "%s-%s-%s", foundry
, family
, cs
);
10601 add_font_name_table_entry (char *font_name
)
10603 if (font_name_table_size
== 0)
10605 font_name_table_size
= 16;
10606 font_name_table
= (char **)
10607 xmalloc (font_name_table_size
* sizeof (char *));
10609 else if (font_name_count
+ 1 >= font_name_table_size
)
10611 font_name_table_size
+= 16;
10612 font_name_table
= (char **)
10613 xrealloc (font_name_table
,
10614 font_name_table_size
* sizeof (char *));
10617 font_name_table
[font_name_count
++] = font_name
;
10620 /* Sets up the table font_name_table to contain the list of all fonts
10621 in the system the first time the table is used so that the Resource
10622 Manager need not be accessed every time this information is
10626 init_font_name_table ()
10628 #if TARGET_API_MAC_CARBON
10631 if (Gestalt (gestaltSystemVersion
, &sv
) == noErr
&& sv
>= 0x1000)
10633 FMFontFamilyIterator ffi
;
10634 FMFontFamilyInstanceIterator ffii
;
10637 /* Create a dummy instance iterator here to avoid creating and
10638 destroying it in the loop. */
10639 if (FMCreateFontFamilyInstanceIterator (0, &ffii
) != noErr
)
10641 /* Create an iterator to enumerate the font families. */
10642 if (FMCreateFontFamilyIterator (NULL
, NULL
, kFMDefaultOptions
, &ffi
)
10645 FMDisposeFontFamilyInstanceIterator (&ffii
);
10649 while (FMGetNextFontFamily (&ffi
, &ff
) == noErr
)
10657 if (FMGetFontFamilyName (ff
, name
) != noErr
)
10661 sc
= FontToScript (ff
);
10663 /* Point the instance iterator at the current font family. */
10664 if (FMResetFontFamilyInstanceIterator(ff
, &ffii
) != noErr
)
10667 while (FMGetNextFontFamilyInstance (&ffii
, &font
, &style
, &size
)
10671 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
10673 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
10675 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
10677 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
10683 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
10685 if (smJapanese
== sc
)
10686 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
10692 /* Dispose of the iterators. */
10693 FMDisposeFontFamilyIterator (&ffi
);
10694 FMDisposeFontFamilyInstanceIterator (&ffii
);
10698 #endif /* TARGET_API_MAC_CARBON */
10700 SInt16 fontnum
, old_fontnum
;
10701 int num_mac_fonts
= CountResources('FOND');
10703 Handle font_handle
, font_handle_2
;
10704 short id
, scriptcode
;
10707 struct FontAssoc
*fat
;
10708 struct AsscEntry
*assc_entry
;
10710 GetPort (&port
); /* save the current font number used */
10711 #if TARGET_API_MAC_CARBON
10712 old_fontnum
= GetPortTextFont (port
);
10714 old_fontnum
= port
->txFont
;
10717 for (i
= 1; i
<= num_mac_fonts
; i
++) /* get all available fonts */
10719 font_handle
= GetIndResource ('FOND', i
);
10723 GetResInfo (font_handle
, &id
, &type
, name
);
10724 GetFNum (name
, &fontnum
);
10729 TextFont (fontnum
);
10730 scriptcode
= FontToScript (fontnum
);
10733 HLock (font_handle
);
10735 if (GetResourceSizeOnDisk (font_handle
)
10736 >= sizeof (struct FamRec
))
10738 fat
= (struct FontAssoc
*) (*font_handle
10739 + sizeof (struct FamRec
));
10741 = (struct AsscEntry
*) (*font_handle
10742 + sizeof (struct FamRec
)
10743 + sizeof (struct FontAssoc
));
10745 for (j
= 0; j
<= fat
->numAssoc
; j
++, assc_entry
++)
10747 if (font_name_table_size
== 0)
10749 font_name_table_size
= 16;
10750 font_name_table
= (char **)
10751 xmalloc (font_name_table_size
* sizeof (char *));
10753 else if (font_name_count
>= font_name_table_size
)
10755 font_name_table_size
+= 16;
10756 font_name_table
= (char **)
10757 xrealloc (font_name_table
,
10758 font_name_table_size
* sizeof (char *));
10760 font_name_table
[font_name_count
++]
10761 = mac_to_x_fontname (name
,
10762 assc_entry
->fontSize
,
10763 assc_entry
->fontStyle
,
10765 /* Both jisx0208.1983-sjis and
10766 jisx0201.1976-sjis parts are contained in
10767 Apple Japanese (SJIS) font. */
10768 if (smJapanese
== scriptcode
)
10770 font_name_table
[font_name_count
++]
10771 = mac_to_x_fontname (name
,
10772 assc_entry
->fontSize
,
10773 assc_entry
->fontStyle
,
10779 HUnlock (font_handle
);
10780 font_handle_2
= GetNextFOND (font_handle
);
10781 ReleaseResource (font_handle
);
10782 font_handle
= font_handle_2
;
10784 while (ResError () == noErr
&& font_handle
);
10787 TextFont (old_fontnum
);
10788 #if TARGET_API_MAC_CARBON
10790 #endif /* TARGET_API_MAC_CARBON */
10794 /* Return a list of at most MAXNAMES font specs matching the one in
10795 PATTERN. Cache matching fonts for patterns in
10796 dpyinfo->name_list_element to avoid looking them up again by
10797 calling mac_font_pattern_match (slow). */
10800 x_list_fonts (struct frame
*f
,
10801 Lisp_Object pattern
,
10806 Lisp_Object newlist
= Qnil
, tem
, key
;
10809 struct gcpro gcpro1
, gcpro2
;
10810 struct mac_display_info
*dpyinfo
= f
? FRAME_MAC_DISPLAY_INFO (f
) : NULL
;
10812 if (font_name_table
== NULL
) /* Initialize when first used. */
10813 init_font_name_table ();
10817 tem
= XCDR (dpyinfo
->name_list_element
);
10818 key
= Fcons (pattern
, make_number (maxnames
));
10820 newlist
= Fassoc (key
, tem
);
10821 if (!NILP (newlist
))
10823 newlist
= Fcdr_safe (newlist
);
10828 ptnstr
= SDATA (pattern
);
10830 GCPRO2 (pattern
, newlist
);
10832 /* Scan and matching bitmap fonts. */
10833 for (i
= 0; i
< font_name_count
; i
++)
10835 if (mac_font_pattern_match (font_name_table
[i
], ptnstr
))
10837 newlist
= Fcons (build_string (font_name_table
[i
]), newlist
);
10840 if (n_fonts
>= maxnames
)
10845 /* MAC_TODO: add code for matching outline fonts here */
10851 XSETCDR (dpyinfo
->name_list_element
,
10852 Fcons (Fcons (key
, newlist
),
10853 XCDR (dpyinfo
->name_list_element
)));
10863 /* Check that FONT is valid on frame F. It is if it can be found in F's
10867 x_check_font (f
, font
)
10872 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10874 xassert (font
!= NULL
);
10876 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10877 if (dpyinfo
->font_table
[i
].name
10878 && font
== dpyinfo
->font_table
[i
].font
)
10881 xassert (i
< dpyinfo
->n_fonts
);
10884 #endif /* GLYPH_DEBUG != 0 */
10886 /* Set *W to the minimum width, *H to the minimum font height of FONT.
10887 Note: There are (broken) X fonts out there with invalid XFontStruct
10888 min_bounds contents. For example, handa@etl.go.jp reports that
10889 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
10890 have font->min_bounds.width == 0. */
10893 x_font_min_bounds (font
, w
, h
)
10894 MacFontStruct
*font
;
10898 * TODO: Windows does not appear to offer min bound, only
10899 * average and maximum width, and maximum height.
10901 *h
= FONT_HEIGHT (font
);
10902 *w
= FONT_WIDTH (font
);
10906 /* Compute the smallest character width and smallest font height over
10907 all fonts available on frame F. Set the members smallest_char_width
10908 and smallest_font_height in F's x_display_info structure to
10909 the values computed. Value is non-zero if smallest_font_height or
10910 smallest_char_width become smaller than they were before. */
10913 x_compute_min_glyph_bounds (f
)
10917 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
10918 MacFontStruct
*font
;
10919 int old_width
= dpyinfo
->smallest_char_width
;
10920 int old_height
= dpyinfo
->smallest_font_height
;
10922 dpyinfo
->smallest_font_height
= 100000;
10923 dpyinfo
->smallest_char_width
= 100000;
10925 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10926 if (dpyinfo
->font_table
[i
].name
)
10928 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
10931 font
= (MacFontStruct
*) fontp
->font
;
10932 xassert (font
!= (MacFontStruct
*) ~0);
10933 x_font_min_bounds (font
, &w
, &h
);
10935 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
10936 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
10939 xassert (dpyinfo
->smallest_char_width
> 0
10940 && dpyinfo
->smallest_font_height
> 0);
10942 return (dpyinfo
->n_fonts
== 1
10943 || dpyinfo
->smallest_char_width
< old_width
10944 || dpyinfo
->smallest_font_height
< old_height
);
10948 /* Determine whether given string is a fully-specified XLFD: all 14
10949 fields are present, none is '*'. */
10952 is_fully_specified_xlfd (char *p
)
10960 for (i
= 0; i
< 13; i
++)
10962 q
= strchr (p
+ 1, '-');
10965 if (q
- p
== 2 && *(p
+ 1) == '*')
10970 if (strchr (p
+ 1, '-') != NULL
)
10973 if (*(p
+ 1) == '*' && *(p
+ 2) == '\0')
10980 const int kDefaultFontSize
= 9;
10983 /* XLoadQueryFont creates and returns an internal representation for a
10984 font in a MacFontStruct struct. There is really no concept
10985 corresponding to "loading" a font on the Mac. But we check its
10986 existence and find the font number and all other information for it
10987 and store them in the returned MacFontStruct. */
10989 static MacFontStruct
*
10990 XLoadQueryFont (Display
*dpy
, char *fontname
)
10992 int i
, size
, is_two_byte_font
, char_width
;
10995 SInt16 old_fontnum
, old_fontsize
;
10996 Style old_fontface
;
10999 Style fontface
= normal
;
11000 MacFontStruct
*font
;
11001 FontInfo the_fontinfo
;
11002 char s_weight
[7], c_slant
;
11004 if (is_fully_specified_xlfd (fontname
))
11008 for (i
= 0; i
< font_name_count
; i
++)
11009 if (mac_font_pattern_match (font_name_table
[i
], fontname
))
11012 if (i
>= font_name_count
)
11015 name
= font_name_table
[i
];
11018 GetPort (&port
); /* save the current font number used */
11019 #if TARGET_API_MAC_CARBON
11020 old_fontnum
= GetPortTextFont (port
);
11021 old_fontsize
= GetPortTextSize (port
);
11022 old_fontface
= GetPortTextFace (port
);
11024 old_fontnum
= port
->txFont
;
11025 old_fontsize
= port
->txSize
;
11026 old_fontface
= port
->txFace
;
11029 if (sscanf (name
, "-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]--%d-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%*s", &size
) != 1)
11030 size
= kDefaultFontSize
;
11032 if (sscanf (name
, "-%*[^-]-%*[^-]-%6[^-]-%*c-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%*s", s_weight
) == 1)
11033 if (strcmp (s_weight
, "bold") == 0)
11036 if (sscanf (name
, "-%*[^-]-%*[^-]-%*[^-]-%c-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%*s", &c_slant
) == 1)
11037 if (c_slant
== 'i')
11038 fontface
|= italic
;
11040 x_font_name_to_mac_font_name (name
, mfontname
);
11041 c2pstr (mfontname
);
11042 GetFNum (mfontname
, &fontnum
);
11046 font
= (MacFontStruct
*) xmalloc (sizeof (struct MacFontStruct
));
11048 font
->fontname
= (char *) xmalloc (strlen (name
) + 1);
11049 bcopy (name
, font
->fontname
, strlen (name
) + 1);
11051 font
->mac_fontnum
= fontnum
;
11052 font
->mac_fontsize
= size
;
11053 font
->mac_fontface
= fontface
;
11054 font
->mac_scriptcode
= FontToScript (fontnum
);
11056 /* Apple Japanese (SJIS) font is listed as both
11057 "*-jisx0208.1983-sjis" (Japanese script) and "*-jisx0201.1976-0"
11058 (Roman script) in init_font_name_table (). The latter should be
11059 treated as a one-byte font. */
11064 "-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%31s",
11066 && 0 == strcmp (cs
, "jisx0201.1976-0"))
11067 font
->mac_scriptcode
= smRoman
;
11070 is_two_byte_font
= font
->mac_scriptcode
== smJapanese
||
11071 font
->mac_scriptcode
== smTradChinese
||
11072 font
->mac_scriptcode
== smSimpChinese
||
11073 font
->mac_scriptcode
== smKorean
;
11075 TextFont (fontnum
);
11077 TextFace (fontface
);
11079 GetFontInfo (&the_fontinfo
);
11081 font
->ascent
= the_fontinfo
.ascent
;
11082 font
->descent
= the_fontinfo
.descent
;
11084 font
->min_byte1
= 0;
11085 if (is_two_byte_font
)
11086 font
->max_byte1
= 1;
11088 font
->max_byte1
= 0;
11089 font
->min_char_or_byte2
= 0x20;
11090 font
->max_char_or_byte2
= 0xff;
11092 if (is_two_byte_font
)
11094 /* Use the width of an "ideographic space" of that font because
11095 the_fontinfo.widMax returns the wrong width for some fonts. */
11096 switch (font
->mac_scriptcode
)
11099 char_width
= StringWidth("\p\x81\x40");
11101 case smTradChinese
:
11102 char_width
= StringWidth("\p\xa1\x40");
11104 case smSimpChinese
:
11105 char_width
= StringWidth("\p\xa1\xa1");
11108 char_width
= StringWidth("\p\xa1\xa1");
11113 /* Do this instead of use the_fontinfo.widMax, which incorrectly
11114 returns 15 for 12-point Monaco! */
11115 char_width
= CharWidth ('m');
11117 font
->max_bounds
.rbearing
= char_width
;
11118 font
->max_bounds
.lbearing
= 0;
11119 font
->max_bounds
.width
= char_width
;
11120 font
->max_bounds
.ascent
= the_fontinfo
.ascent
;
11121 font
->max_bounds
.descent
= the_fontinfo
.descent
;
11123 font
->min_bounds
= font
->max_bounds
;
11125 if (is_two_byte_font
|| CharWidth ('m') == CharWidth ('i'))
11126 font
->per_char
= NULL
;
11129 font
->per_char
= (XCharStruct
*)
11130 xmalloc (sizeof (XCharStruct
) * (0xff - 0x20 + 1));
11134 for (c
= 0x20; c
<= 0xff; c
++)
11136 font
->per_char
[c
- 0x20] = font
->max_bounds
;
11137 font
->per_char
[c
- 0x20].width
= CharWidth (c
);
11142 TextFont (old_fontnum
); /* restore previous font number, size and face */
11143 TextSize (old_fontsize
);
11144 TextFace (old_fontface
);
11150 /* Load font named FONTNAME of the size SIZE for frame F, and return a
11151 pointer to the structure font_info while allocating it dynamically.
11152 If SIZE is 0, load any size of font.
11153 If loading is failed, return NULL. */
11156 x_load_font (f
, fontname
, size
)
11158 register char *fontname
;
11161 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
11162 Lisp_Object font_names
;
11164 /* Get a list of all the fonts that match this name. Once we
11165 have a list of matching fonts, we compare them against the fonts
11166 we already have by comparing names. */
11167 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
11169 if (!NILP (font_names
))
11174 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11175 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
11176 if (dpyinfo
->font_table
[i
].name
11177 && (!strcmp (dpyinfo
->font_table
[i
].name
,
11178 SDATA (XCAR (tail
)))
11179 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
11180 SDATA (XCAR (tail
)))))
11181 return (dpyinfo
->font_table
+ i
);
11184 /* Load the font and add it to the table. */
11187 struct MacFontStruct
*font
;
11188 struct font_info
*fontp
;
11189 unsigned long value
;
11192 /* If we have found fonts by x_list_font, load one of them. If
11193 not, we still try to load a font by the name given as FONTNAME
11194 because XListFonts (called in x_list_font) of some X server has
11195 a bug of not finding a font even if the font surely exists and
11196 is loadable by XLoadQueryFont. */
11197 if (size
> 0 && !NILP (font_names
))
11198 fontname
= (char *) SDATA (XCAR (font_names
));
11200 font
= (MacFontStruct
*) XLoadQueryFont (FRAME_MAC_DISPLAY (f
), fontname
);
11204 /* Find a free slot in the font table. */
11205 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
11206 if (dpyinfo
->font_table
[i
].name
== NULL
)
11209 /* If no free slot found, maybe enlarge the font table. */
11210 if (i
== dpyinfo
->n_fonts
11211 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
11214 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
11215 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
11216 dpyinfo
->font_table
11217 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
11220 fontp
= dpyinfo
->font_table
+ i
;
11221 if (i
== dpyinfo
->n_fonts
)
11222 ++dpyinfo
->n_fonts
;
11224 /* Now fill in the slots of *FONTP. */
11226 fontp
->font
= font
;
11227 fontp
->font_idx
= i
;
11228 fontp
->name
= (char *) xmalloc (strlen (font
->fontname
) + 1);
11229 bcopy (font
->fontname
, fontp
->name
, strlen (font
->fontname
) + 1);
11231 fontp
->full_name
= fontp
->name
;
11233 fontp
->size
= font
->max_bounds
.width
;
11234 fontp
->height
= FONT_HEIGHT (font
);
11236 /* For some font, ascent and descent in max_bounds field is
11237 larger than the above value. */
11238 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
11239 if (max_height
> fontp
->height
)
11240 fontp
->height
= max_height
;
11243 /* The slot `encoding' specifies how to map a character
11244 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
11245 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
11246 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
11247 2:0xA020..0xFF7F). For the moment, we don't know which charset
11248 uses this font. So, we set information in fontp->encoding[1]
11249 which is never used by any charset. If mapping can't be
11250 decided, set FONT_ENCODING_NOT_DECIDED. */
11251 if (font
->mac_scriptcode
== smJapanese
)
11252 fontp
->encoding
[1] = 4;
11256 = (font
->max_byte1
== 0
11258 ? (font
->min_char_or_byte2
< 0x80
11259 ? (font
->max_char_or_byte2
< 0x80
11260 ? 0 /* 0x20..0x7F */
11261 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
11262 : 1) /* 0xA0..0xFF */
11264 : (font
->min_byte1
< 0x80
11265 ? (font
->max_byte1
< 0x80
11266 ? (font
->min_char_or_byte2
< 0x80
11267 ? (font
->max_char_or_byte2
< 0x80
11268 ? 0 /* 0x2020..0x7F7F */
11269 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
11270 : 3) /* 0x20A0..0x7FFF */
11271 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
11272 : (font
->min_char_or_byte2
< 0x80
11273 ? (font
->max_char_or_byte2
< 0x80
11274 ? 2 /* 0xA020..0xFF7F */
11275 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
11276 : 1))); /* 0xA0A0..0xFFFF */
11279 #if 0 /* MAC_TODO: fill these out with more reasonably values */
11280 fontp
->baseline_offset
11281 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
11282 ? (long) value
: 0);
11283 fontp
->relative_compose
11284 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
11285 ? (long) value
: 0);
11286 fontp
->default_ascent
11287 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
11288 ? (long) value
: 0);
11290 fontp
->baseline_offset
= 0;
11291 fontp
->relative_compose
= 0;
11292 fontp
->default_ascent
= 0;
11295 /* Set global flag fonts_changed_p to non-zero if the font loaded
11296 has a character with a smaller width than any other character
11297 before, or if the font loaded has a smalle>r height than any
11298 other font loaded before. If this happens, it will make a
11299 glyph matrix reallocation necessary. */
11300 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
11307 /* Return a pointer to struct font_info of a font named FONTNAME for
11308 frame F. If no such font is loaded, return NULL. */
11311 x_query_font (f
, fontname
)
11313 register char *fontname
;
11315 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
11318 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11319 if (dpyinfo
->font_table
[i
].name
11320 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
11321 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
11322 return (dpyinfo
->font_table
+ i
);
11327 /* Find a CCL program for a font specified by FONTP, and set the member
11328 `encoder' of the structure. */
11331 x_find_ccl_program (fontp
)
11332 struct font_info
*fontp
;
11334 Lisp_Object list
, elt
;
11336 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
11340 && STRINGP (XCAR (elt
))
11341 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
11347 struct ccl_program
*ccl
11348 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
11350 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
11353 fontp
->font_encoder
= ccl
;
11359 /***********************************************************************
11361 ***********************************************************************/
11363 #ifdef USE_X_TOOLKIT
11364 static XrmOptionDescRec emacs_options
[] = {
11365 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
11366 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
11368 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
11369 XrmoptionSepArg
, NULL
},
11370 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
11372 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
11373 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
11374 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
11375 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
11376 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
11377 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
11378 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
11380 #endif /* USE_X_TOOLKIT */
11382 static int x_initialized
;
11384 #ifdef MULTI_KBOARD
11385 /* Test whether two display-name strings agree up to the dot that separates
11386 the screen number from the server number. */
11388 same_x_server (name1
, name2
)
11389 char *name1
, *name2
;
11391 int seen_colon
= 0;
11392 unsigned char *system_name
= SDATA (Vsystem_name
);
11393 int system_name_length
= strlen (system_name
);
11394 int length_until_period
= 0;
11396 while (system_name
[length_until_period
] != 0
11397 && system_name
[length_until_period
] != '.')
11398 length_until_period
++;
11400 /* Treat `unix' like an empty host name. */
11401 if (! strncmp (name1
, "unix:", 5))
11403 if (! strncmp (name2
, "unix:", 5))
11405 /* Treat this host's name like an empty host name. */
11406 if (! strncmp (name1
, system_name
, system_name_length
)
11407 && name1
[system_name_length
] == ':')
11408 name1
+= system_name_length
;
11409 if (! strncmp (name2
, system_name
, system_name_length
)
11410 && name2
[system_name_length
] == ':')
11411 name2
+= system_name_length
;
11412 /* Treat this host's domainless name like an empty host name. */
11413 if (! strncmp (name1
, system_name
, length_until_period
)
11414 && name1
[length_until_period
] == ':')
11415 name1
+= length_until_period
;
11416 if (! strncmp (name2
, system_name
, length_until_period
)
11417 && name2
[length_until_period
] == ':')
11418 name2
+= length_until_period
;
11420 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
11424 if (seen_colon
&& *name1
== '.')
11428 && (*name1
== '.' || *name1
== '\0')
11429 && (*name2
== '.' || *name2
== '\0'));
11434 /* The Mac Event loop code */
11437 #include <Events.h>
11438 #include <Quickdraw.h>
11439 #include <Balloons.h>
11440 #include <Devices.h>
11442 #include <Gestalt.h>
11444 #include <Processes.h>
11446 #include <ToolUtils.h>
11447 #include <TextUtils.h>
11448 #include <Dialogs.h>
11449 #include <Script.h>
11451 #include <TextEncodingConverter.h>
11452 #include <Resources.h>
11457 #endif /* ! MAC_OSX */
11459 #define M_APPLE 128
11462 #define WINDOW_RESOURCE 128
11463 #define TERM_WINDOW_RESOURCE 129
11465 #define DEFAULT_NUM_COLS 80
11467 #define MIN_DOC_SIZE 64
11468 #define MAX_DOC_SIZE 32767
11470 /* sleep time for WaitNextEvent */
11471 #define WNE_SLEEP_AT_SUSPEND 10
11472 #define WNE_SLEEP_AT_RESUME 1
11474 /* true when cannot handle any Mac OS events */
11475 static int handling_window_update
= 0;
11477 /* the flag appl_is_suspended is used both for determining the sleep
11478 time to be passed to WaitNextEvent and whether the cursor should be
11479 drawn when updating the display. The cursor is turned off when
11480 Emacs is suspended. Redrawing it is unnecessary and what needs to
11481 be done depends on whether the cursor lies inside or outside the
11482 redraw region. So we might as well skip drawing it when Emacs is
11484 static Boolean app_is_suspended
= false;
11485 static long app_sleep_time
= WNE_SLEEP_AT_RESUME
;
11487 #define EXTRA_STACK_ALLOC (256 * 1024)
11489 #define ARGV_STRING_LIST_ID 129
11490 #define ABOUT_ALERT_ID 128
11491 #define RAM_TOO_LARGE_ALERT_ID 129
11493 Boolean terminate_flag
= false;
11495 /* True if using command key as meta key. */
11496 Lisp_Object Vmac_command_key_is_meta
;
11498 /* True if the ctrl and meta keys should be reversed. */
11499 Lisp_Object Vmac_reverse_ctrl_meta
;
11501 #if USE_CARBON_EVENTS
11502 /* True if the mouse wheel button (i.e. button 4) should map to
11503 mouse-2, instead of mouse-3. */
11504 Lisp_Object Vmac_wheel_button_is_mouse_2
;
11506 /* If Non-nil, the Mac "Command" key is passed on to the Mac Toolbox
11507 for processing before Emacs sees it. */
11508 Lisp_Object Vmac_pass_command_to_system
;
11510 /* If Non-nil, the Mac "Control" key is passed on to the Mac Toolbox
11511 for processing before Emacs sees it. */
11512 Lisp_Object Vmac_pass_control_to_system
;
11515 /* convert input from Mac keyboard (assumed to be in Mac Roman coding)
11516 to this text encoding */
11517 int mac_keyboard_text_encoding
;
11518 int current_mac_keyboard_text_encoding
= kTextEncodingMacRoman
;
11520 /* Set in term/mac-win.el to indicate that event loop can now generate
11521 drag and drop events. */
11522 Lisp_Object Qmac_ready_for_drag_n_drop
;
11524 Lisp_Object drag_and_drop_file_list
;
11526 Point saved_menu_event_location
;
11529 static void init_required_apple_events (void);
11530 static pascal OSErr
11531 do_ae_open_application (const AppleEvent
*, AppleEvent
*, long);
11532 static pascal OSErr
11533 do_ae_print_documents (const AppleEvent
*, AppleEvent
*, long);
11534 static pascal OSErr
do_ae_open_documents (AppleEvent
*, AppleEvent
*, long);
11535 static pascal OSErr
do_ae_quit_application (AppleEvent
*, AppleEvent
*, long);
11537 /* Drag and Drop */
11538 static OSErr
init_mac_drag_n_drop ();
11539 static pascal OSErr
mac_do_receive_drag (WindowPtr
, void*, DragReference
);
11541 #if USE_CARBON_EVENTS
11542 /* Preliminary Support for the OSX Services Menu */
11543 static OSStatus
mac_handle_service_event (EventHandlerCallRef
,EventRef
,void*);
11544 static void init_service_handler ();
11547 extern void init_emacs_passwd_dir ();
11548 extern int emacs_main (int, char **, char **);
11549 extern void check_alarm ();
11551 extern void initialize_applescript();
11552 extern void terminate_applescript();
11554 static unsigned int
11555 #if USE_CARBON_EVENTS
11556 mac_to_emacs_modifiers (UInt32 mods
)
11558 mac_to_emacs_modifiers (EventModifiers mods
)
11561 unsigned int result
= 0;
11562 if (mods
& macShiftKey
)
11563 result
|= shift_modifier
;
11564 if (mods
& macCtrlKey
)
11565 result
|= ctrl_modifier
;
11566 if (mods
& macMetaKey
)
11567 result
|= meta_modifier
;
11568 if (NILP (Vmac_command_key_is_meta
) && (mods
& macAltKey
))
11569 result
|= alt_modifier
;
11573 #if USE_CARBON_EVENTS
11574 /* Obtains the event modifiers from the event ref and then calls
11575 mac_to_emacs_modifiers. */
11577 mac_event_to_emacs_modifiers (EventRef eventRef
)
11580 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
11581 sizeof (UInt32
), NULL
, &mods
);
11582 return mac_to_emacs_modifiers (mods
);
11585 /* Given an event ref, return the code to use for the mouse button
11586 code in the emacs input_event. */
11588 mac_get_mouse_btn (EventRef ref
)
11590 EventMouseButton result
= kEventMouseButtonPrimary
;
11591 GetEventParameter (ref
, kEventParamMouseButton
, typeMouseButton
, NULL
,
11592 sizeof (EventMouseButton
), NULL
, &result
);
11595 case kEventMouseButtonPrimary
:
11597 case kEventMouseButtonSecondary
:
11598 return NILP (Vmac_wheel_button_is_mouse_2
) ? 2 : 1;
11599 case kEventMouseButtonTertiary
:
11600 case 4: /* 4 is the number for the mouse wheel button */
11601 return NILP (Vmac_wheel_button_is_mouse_2
) ? 1 : 2;
11607 /* Normally, ConvertEventRefToEventRecord will correctly handle all
11608 events. However the click of the mouse wheel is not converted to a
11609 mouseDown or mouseUp event. This calls ConvertEventRef, but then
11610 checks to see if it is a mouse up or down carbon event that has not
11611 been converted, and if so, converts it by hand (to be picked up in
11612 the XTread_socket loop). */
11613 static Boolean
mac_convert_event_ref (EventRef eventRef
, EventRecord
*eventRec
)
11615 Boolean result
= ConvertEventRefToEventRecord (eventRef
, eventRec
);
11616 /* Do special case for mouse wheel button. */
11617 if (!result
&& GetEventClass (eventRef
) == kEventClassMouse
)
11619 UInt32 kind
= GetEventKind (eventRef
);
11620 if (kind
== kEventMouseDown
&& !(eventRec
->what
== mouseDown
))
11622 eventRec
->what
= mouseDown
;
11625 if (kind
== kEventMouseUp
&& !(eventRec
->what
== mouseUp
))
11627 eventRec
->what
= mouseUp
;
11632 /* Need where and when. */
11634 GetEventParameter (eventRef
, kEventParamMouseLocation
,
11635 typeQDPoint
, NULL
, sizeof (Point
),
11636 NULL
, &eventRec
->where
);
11637 /* Use two step process because new event modifiers are
11638 32-bit and old are 16-bit. Currently, only loss is
11640 GetEventParameter (eventRef
, kEventParamKeyModifiers
,
11641 typeUInt32
, NULL
, sizeof (UInt32
),
11643 eventRec
->modifiers
= mods
;
11645 eventRec
->when
= EventTimeToTicks (GetEventTime (eventRef
));
11654 do_get_menus (void)
11656 Handle menubar_handle
;
11657 MenuHandle menu_handle
;
11659 menubar_handle
= GetNewMBar (128);
11660 if(menubar_handle
== NULL
)
11662 SetMenuBar (menubar_handle
);
11665 menu_handle
= GetMenuHandle (M_APPLE
);
11666 if(menu_handle
!= NULL
)
11667 AppendResMenu (menu_handle
,'DRVR');
11674 do_init_managers (void)
11676 #if !TARGET_API_MAC_CARBON
11677 InitGraf (&qd
.thePort
);
11679 FlushEvents (everyEvent
, 0);
11683 InitDialogs (NULL
);
11684 #endif /* !TARGET_API_MAC_CARBON */
11687 #if !TARGET_API_MAC_CARBON
11688 /* set up some extra stack space for use by emacs */
11689 SetApplLimit ((Ptr
) ((long) GetApplLimit () - EXTRA_STACK_ALLOC
));
11691 /* MaxApplZone must be called for AppleScript to execute more
11692 complicated scripts */
11695 #endif /* !TARGET_API_MAC_CARBON */
11699 do_check_ram_size (void)
11701 SInt32 physical_ram_size
, logical_ram_size
;
11703 if (Gestalt (gestaltPhysicalRAMSize
, &physical_ram_size
) != noErr
11704 || Gestalt (gestaltLogicalRAMSize
, &logical_ram_size
) != noErr
11705 || physical_ram_size
> 256 * 1024 * 1024
11706 || logical_ram_size
> 256 * 1024 * 1024)
11708 StopAlert (RAM_TOO_LARGE_ALERT_ID
, NULL
);
11714 do_window_update (WindowPtr win
)
11716 struct mac_output
*mwp
= (mac_output
*) GetWRefCon (win
);
11717 struct frame
*f
= mwp
->mFP
;
11721 if (f
->async_visible
== 0)
11723 f
->async_visible
= 1;
11724 f
->async_iconified
= 0;
11725 SET_FRAME_GARBAGED (f
);
11727 /* An update event is equivalent to MapNotify on X, so report
11728 visibility changes properly. */
11729 if (! NILP(Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
11730 /* Force a redisplay sooner or later to update the
11731 frame titles in case this is the second frame. */
11732 record_asynch_buffer_change ();
11737 handling_window_update
= 1;
11739 XClearWindow (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
));
11741 expose_frame (f
, 0, 0, 0, 0);
11743 handling_window_update
= 0;
11750 is_emacs_window (WindowPtr win
)
11752 Lisp_Object tail
, frame
;
11757 FOR_EACH_FRAME (tail
, frame
)
11758 if (FRAME_MAC_P (XFRAME (frame
)))
11759 if (FRAME_MAC_WINDOW (XFRAME (frame
)) == win
)
11766 do_window_activate (WindowPtr win
)
11771 if (is_emacs_window (win
))
11773 mwp
= (mac_output
*) GetWRefCon (win
);
11778 x_new_focus_frame (FRAME_MAC_DISPLAY_INFO (f
), f
);
11779 activate_scroll_bars (f
);
11785 do_window_deactivate (WindowPtr win
)
11790 if (is_emacs_window (win
))
11792 mwp
= (mac_output
*) GetWRefCon (win
);
11795 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
11797 x_new_focus_frame (FRAME_MAC_DISPLAY_INFO (f
), 0);
11798 deactivate_scroll_bars (f
);
11810 wp
= FrontWindow();
11811 if (is_emacs_window (wp
))
11813 mwp
= (mac_output
*) GetWRefCon (wp
);
11818 x_new_focus_frame (FRAME_MAC_DISPLAY_INFO (f
), f
);
11819 activate_scroll_bars (f
);
11823 app_is_suspended
= false;
11824 app_sleep_time
= WNE_SLEEP_AT_RESUME
;
11834 wp
= FrontWindow();
11835 if (is_emacs_window (wp
))
11837 mwp
= (mac_output
*) GetWRefCon (wp
);
11840 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
11842 x_new_focus_frame (FRAME_MAC_DISPLAY_INFO (f
), 0);
11843 deactivate_scroll_bars (f
);
11847 app_is_suspended
= true;
11848 app_sleep_time
= WNE_SLEEP_AT_SUSPEND
;
11853 do_mouse_moved (Point mouse_pos
)
11855 WindowPtr wp
= FrontWindow ();
11858 if (is_emacs_window (wp
))
11860 f
= ((mac_output
*) GetWRefCon (wp
))->mFP
;
11862 #if TARGET_API_MAC_CARBON
11863 SetPort (GetWindowPort (wp
));
11868 GlobalToLocal (&mouse_pos
);
11870 note_mouse_movement (f
, &mouse_pos
);
11876 do_os_event (EventRecord
*erp
)
11878 switch((erp
->message
>> 24) & 0x000000FF)
11880 case suspendResumeMessage
:
11881 if((erp
->message
& resumeFlag
) == 1)
11887 case mouseMovedMessage
:
11888 do_mouse_moved (erp
->where
);
11894 do_events (EventRecord
*erp
)
11899 do_window_update ((WindowPtr
) erp
->message
);
11907 if ((erp
->modifiers
& activeFlag
) != 0)
11908 do_window_activate ((WindowPtr
) erp
->message
);
11910 do_window_deactivate ((WindowPtr
) erp
->message
);
11916 do_apple_menu (SInt16 menu_item
)
11918 #if !TARGET_API_MAC_CARBON
11920 SInt16 da_driver_refnum
;
11922 if (menu_item
== I_ABOUT
)
11923 NoteAlert (ABOUT_ALERT_ID
, NULL
);
11926 GetMenuItemText (GetMenuHandle (M_APPLE
), menu_item
, item_name
);
11927 da_driver_refnum
= OpenDeskAcc (item_name
);
11929 #endif /* !TARGET_API_MAC_CARBON */
11933 do_menu_choice (SInt32 menu_choice
)
11935 SInt16 menu_id
, menu_item
;
11937 menu_id
= HiWord (menu_choice
);
11938 menu_item
= LoWord (menu_choice
);
11946 do_apple_menu (menu_item
);
11951 WindowPtr wp
= FrontWindow ();
11952 struct frame
*f
= ((mac_output
*) GetWRefCon (wp
))->mFP
;
11953 MenuHandle menu
= GetMenuHandle (menu_id
);
11958 GetMenuItemRefCon (menu
, menu_item
, &refcon
);
11959 menubar_selection_callback (f
, refcon
);
11968 /* Handle drags in size box. Based on code contributed by Ben
11969 Mesander and IM - Window Manager A. */
11972 do_grow_window (WindowPtr w
, EventRecord
*e
)
11977 mac_output
*mwp
= (mac_output
*) GetWRefCon (w
);
11978 struct frame
*f
= mwp
->mFP
;
11980 SetRect(&limit_rect
, MIN_DOC_SIZE
, MIN_DOC_SIZE
, MAX_DOC_SIZE
, MAX_DOC_SIZE
);
11982 grow_size
= GrowWindow (w
, e
->where
, &limit_rect
);
11984 /* see if it really changed size */
11985 if (grow_size
!= 0)
11987 rows
= PIXEL_TO_CHAR_HEIGHT (f
, HiWord (grow_size
));
11988 columns
= PIXEL_TO_CHAR_WIDTH (f
, LoWord (grow_size
));
11990 x_set_window_size (f
, 0, columns
, rows
);
11995 /* Handle clicks in zoom box. Calculation of "standard state" based
11996 on code in IM - Window Manager A and code contributed by Ben
11997 Mesander. The standard state of an Emacs window is 80-characters
11998 wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */
12001 do_zoom_window (WindowPtr w
, int zoom_in_or_out
)
12004 Rect zoom_rect
, port_rect
;
12006 int w_title_height
, columns
, rows
, width
, height
, dummy
, x
, y
;
12007 mac_output
*mwp
= (mac_output
*) GetWRefCon (w
);
12008 struct frame
*f
= mwp
->mFP
;
12010 GetPort (&save_port
);
12012 #if TARGET_API_MAC_CARBON
12013 SetPort (GetWindowPort (w
));
12018 /* Clear window to avoid flicker. */
12019 #if TARGET_API_MAC_CARBON
12024 GetWindowPortBounds (w
, &r
);
12027 if (zoom_in_or_out
== inZoomOut
)
12029 /* calculate height of window's title bar (hard card it for now). */
12030 w_title_height
= 20 + GetMBarHeight ();
12032 /* get maximum height of window into zoom_rect.bottom -
12034 GetQDGlobalsScreenBits (&bm
);
12035 zoom_rect
= bm
.bounds
;
12036 zoom_rect
.top
+= w_title_height
;
12037 InsetRect (&zoom_rect
, 8, 4); /* not too tight */
12039 zoom_rect
.right
= zoom_rect
.left
12040 + CHAR_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
12042 SetWindowStandardState (w
, &zoom_rect
);
12045 #else /* not TARGET_API_MAC_CARBON */
12046 EraseRect (&(w
->portRect
));
12047 if (zoom_in_or_out
== inZoomOut
)
12049 SetPt (&top_left
, w
->portRect
.left
, w
->portRect
.top
);
12050 LocalToGlobal (&top_left
);
12052 /* calculate height of window's title bar */
12053 w_title_height
= top_left
.v
- 1
12054 - (**((WindowPeek
) w
)->strucRgn
).rgnBBox
.top
+ GetMBarHeight ();
12056 /* get maximum height of window into zoom_rect.bottom - zoom_rect.top */
12057 zoom_rect
= qd
.screenBits
.bounds
;
12058 zoom_rect
.top
+= w_title_height
;
12059 InsetRect (&zoom_rect
, 8, 4); /* not too tight */
12061 zoom_rect
.right
= zoom_rect
.left
12062 + CHAR_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
12064 (**((WStateDataHandle
) ((WindowPeek
) w
)->dataHandle
)).stdState
12067 #endif /* not TARGET_API_MAC_CARBON */
12069 ZoomWindow (w
, zoom_in_or_out
, w
== FrontWindow ());
12071 /* retrieve window size and update application values */
12072 #if TARGET_API_MAC_CARBON
12073 GetWindowPortBounds (w
, &port_rect
);
12075 port_rect
= w
->portRect
;
12077 rows
= PIXEL_TO_CHAR_HEIGHT (f
, port_rect
.bottom
- port_rect
.top
);
12078 columns
= PIXEL_TO_CHAR_WIDTH (f
, port_rect
.right
- port_rect
.left
);
12079 x_set_window_size (mwp
->mFP
, 0, columns
, rows
);
12081 SetPort (save_port
);
12084 /* Initialize Drag And Drop to allow files to be dropped onto emacs frames */
12086 init_mac_drag_n_drop ()
12088 OSErr result
= InstallReceiveHandler (mac_do_receive_drag
, 0L, NULL
);
12092 /* Intialize AppleEvent dispatcher table for the required events. */
12094 init_required_apple_events ()
12099 /* Make sure we have apple events before starting. */
12100 err
= Gestalt (gestaltAppleEventsAttr
, &result
);
12104 if (!(result
& (1 << gestaltAppleEventsPresent
)))
12107 #if TARGET_API_MAC_CARBON
12108 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenApplication
,
12109 NewAEEventHandlerUPP
12110 ((AEEventHandlerProcPtr
) do_ae_open_application
),
12113 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenApplication
,
12114 NewAEEventHandlerProc
12115 ((AEEventHandlerProcPtr
) do_ae_open_application
),
12121 #if TARGET_API_MAC_CARBON
12122 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenDocuments
,
12123 NewAEEventHandlerUPP
12124 ((AEEventHandlerProcPtr
) do_ae_open_documents
),
12127 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenDocuments
,
12128 NewAEEventHandlerProc
12129 ((AEEventHandlerProcPtr
) do_ae_open_documents
),
12135 #if TARGET_API_MAC_CARBON
12136 err
= AEInstallEventHandler(kCoreEventClass
, kAEPrintDocuments
,
12137 NewAEEventHandlerUPP
12138 ((AEEventHandlerProcPtr
) do_ae_print_documents
),
12141 err
= AEInstallEventHandler(kCoreEventClass
, kAEPrintDocuments
,
12142 NewAEEventHandlerProc
12143 ((AEEventHandlerProcPtr
) do_ae_print_documents
),
12149 #if TARGET_API_MAC_CARBON
12150 err
= AEInstallEventHandler(kCoreEventClass
, kAEQuitApplication
,
12151 NewAEEventHandlerUPP
12152 ((AEEventHandlerProcPtr
) do_ae_quit_application
),
12155 err
= AEInstallEventHandler(kCoreEventClass
, kAEQuitApplication
,
12156 NewAEEventHandlerProc
12157 ((AEEventHandlerProcPtr
) do_ae_quit_application
),
12164 #if USE_CARBON_EVENTS
12166 void init_service_handler()
12168 EventTypeSpec specs
[] = {{kEventClassService
, kEventServiceGetTypes
},
12169 {kEventClassService
, kEventServiceCopy
},
12170 {kEventClassService
, kEventServicePaste
}};
12171 InstallApplicationEventHandler (NewEventHandlerUPP (mac_handle_service_event
),
12172 3, specs
, NULL
, NULL
);
12176 MAC_TODO: Check to see if this is called by AEProcessDesc...
12178 OSStatus
mac_handle_service_event (EventHandlerCallRef callRef
,
12179 EventRef event
, void *data
)
12181 OSStatus err
= noErr
;
12182 switch (GetEventKind (event
))
12184 case kEventServiceGetTypes
:
12186 CFMutableArrayRef copyTypes
, pasteTypes
;
12188 Boolean selection
= true;
12190 GetEventParameter(event, kEventParamServicePasteTypes,
12191 typeCFMutableArrayRef, NULL,
12192 sizeof (CFMutableArrayRef), NULL, &pasteTypes);
12194 GetEventParameter(event
, kEventParamServiceCopyTypes
,
12195 typeCFMutableArrayRef
, NULL
,
12196 sizeof (CFMutableArrayRef
), NULL
, ©Types
);
12197 type
= CreateTypeStringWithOSType (kScrapFlavorTypeText
);
12199 CFArrayAppendValue (copyTypes
, type
);
12200 //CFArrayAppendValue (pasteTypes, type);
12204 case kEventServiceCopy
:
12206 ScrapRef currentScrap
, specificScrap
;
12208 Size byteCount
= 0;
12210 GetCurrentScrap (¤tScrap
);
12212 err
= GetScrapFlavorSize (currentScrap
, kScrapFlavorTypeText
, &byteCount
);
12215 void *buffer
= xmalloc (byteCount
);
12216 if (buffer
!= NULL
)
12218 GetEventParameter (event
, kEventParamScrapRef
, typeScrapRef
, NULL
,
12219 sizeof (ScrapRef
), NULL
, &specificScrap
);
12221 err
= GetScrapFlavorData (currentScrap
, kScrapFlavorTypeText
,
12222 &byteCount
, buffer
);
12224 PutScrapFlavor (specificScrap
, kScrapFlavorTypeText
,
12225 kScrapFlavorMaskNone
, byteCount
, buffer
);
12231 case kEventServicePaste
:
12234 // Get the current location
12236 ScrapRef specificScrap;
12237 GetEventParameter(event, kEventParamScrapRef, typeScrapRef, NULL,
12238 sizeof(ScrapRef), NULL, &specificScrap);
12239 err = GetScrapFlavorSize(specificScrap, kScrapFlavorTypeText, &byteCount);
12240 if (err == noErr) {
12241 void * buffer = xmalloc(byteCount);
12242 if (buffer != NULL ) {
12243 err = GetScrapFlavorData(specificScrap, kScrapFlavorTypeText,
12244 &byteCount, buffer);
12245 if (err == noErr) {
12246 // Actually place in the buffer
12248 // Get the current "selection" string here
12261 /* Open Application Apple Event */
12262 static pascal OSErr
12263 do_ae_open_application(const AppleEvent
*pae
, AppleEvent
*preply
, long prefcon
)
12269 /* Defined in mac.c. */
12271 path_from_vol_dir_name (char *, int, short, long, char *);
12274 /* Called when we receive an AppleEvent with an ID of
12275 "kAEOpenDocuments". This routine gets the direct parameter,
12276 extracts the FSSpecs in it, and puts their names on a list. */
12277 static pascal OSErr
12278 do_ae_open_documents(AppleEvent
*message
, AppleEvent
*reply
, long refcon
)
12283 DescType actual_type
;
12286 err
= AEGetParamDesc (message
, keyDirectObject
, typeAEList
, &the_desc
);
12288 goto descriptor_error_exit
;
12290 /* Check to see that we got all of the required parameters from the
12291 event descriptor. For an 'odoc' event this should just be the
12293 err
= AEGetAttributePtr(message
, keyMissedKeywordAttr
, typeWildCard
,
12294 &actual_type
, (Ptr
) &keyword
,
12295 sizeof (keyword
), &actual_size
);
12296 /* No error means that we found some unused parameters.
12297 errAEDescNotFound means that there are no more parameters. If we
12298 get an error code other than that, flag it. */
12299 if ((err
== noErr
) || (err
!= errAEDescNotFound
))
12301 err
= errAEEventNotHandled
;
12306 /* Got all the parameters we need. Now, go through the direct
12307 object list and parse it up. */
12309 long num_files_to_open
;
12311 err
= AECountItems (&the_desc
, &num_files_to_open
);
12316 /* AE file list is one based so just use that for indexing here. */
12317 for (i
= 1; (err
== noErr
) && (i
<= num_files_to_open
); i
++)
12320 Str255 path_name
, unix_path_name
;
12325 err
= AEGetNthPtr(&the_desc
, i
, typeFSS
, &keyword
, &actual_type
,
12326 (Ptr
) &fs
, sizeof (fs
), &actual_size
);
12327 if (err
!= noErr
) break;
12330 err
= FSpMakeFSRef (&fs
, &fref
);
12331 if (err
!= noErr
) break;
12333 if (FSRefMakePath (&fref
, unix_path_name
, 255) == noErr
)
12335 if (path_from_vol_dir_name (path_name
, 255, fs
.vRefNum
, fs
.parID
,
12337 mac_to_posix_pathname (path_name
, unix_path_name
, 255))
12339 drag_and_drop_file_list
= Fcons (build_string (unix_path_name
),
12340 drag_and_drop_file_list
);
12346 /* Nuke the coerced file list in any case */
12347 err2
= AEDisposeDesc(&the_desc
);
12349 descriptor_error_exit
:
12350 /* InvalRect(&(gFrontMacWindowP->mWP->portRect)); */
12355 static pascal OSErr
mac_do_receive_drag (WindowPtr window
, void *handlerRefCon
,
12356 DragReference theDrag
)
12360 FlavorFlags theFlags
;
12363 ItemReference theItem
;
12366 Size size
= sizeof (HFSFlavor
);
12368 drag_and_drop_file_list
= Qnil
;
12369 GetDragMouse (theDrag
, &mouse
, 0L);
12370 CountDragItems (theDrag
, &items
);
12371 for (index
= 1; index
<= items
; index
++)
12373 /* Only handle file references. */
12374 GetDragItemReferenceNumber (theDrag
, index
, &theItem
);
12375 result
= GetFlavorFlags (theDrag
, theItem
, flavorTypeHFS
, &theFlags
);
12376 if (result
== noErr
)
12383 Str255 unix_path_name
;
12384 GetFlavorData (theDrag
, theItem
, flavorTypeHFS
, &data
, &size
, 0L);
12386 /* Use Carbon routines, otherwise it converts the file name
12387 to /Macintosh HD/..., which is not correct. */
12388 FSpMakeFSRef (&data
.fileSpec
, &fref
);
12389 if (! FSRefMakePath (&fref
, unix_path_name
, sizeof (unix_path_name
)));
12391 if (path_from_vol_dir_name (path_name
, 255, data
.fileSpec
.vRefNum
,
12392 data
.fileSpec
.parID
, data
.fileSpec
.name
) &&
12393 mac_to_posix_pathname (path_name
, unix_path_name
, 255))
12395 drag_and_drop_file_list
= Fcons (build_string (unix_path_name
),
12396 drag_and_drop_file_list
);
12401 /* If there are items in the list, construct an event and post it to
12402 the queue like an interrupt using kbd_buffer_store_event. */
12403 if (!NILP (drag_and_drop_file_list
))
12405 struct input_event event
;
12407 struct frame
*f
= ((mac_output
*) GetWRefCon(window
))->mFP
;
12408 SetPort (GetWindowPort (window
));
12409 GlobalToLocal (&mouse
);
12411 event
.kind
= DRAG_N_DROP_EVENT
;
12413 event
.modifiers
= 0;
12414 event
.timestamp
= TickCount () * (1000 / 60);
12415 XSETINT (event
.x
, mouse
.h
);
12416 XSETINT (event
.y
, mouse
.v
);
12417 XSETFRAME (frame
, f
);
12418 event
.frame_or_window
= Fcons (frame
, drag_and_drop_file_list
);
12420 /* Post to the interrupt queue */
12421 kbd_buffer_store_event (&event
);
12422 /* MAC_TODO: Mimic behavior of windows by switching contexts to Emacs */
12424 ProcessSerialNumber psn
;
12425 GetCurrentProcess (&psn
);
12426 SetFrontProcess (&psn
);
12432 /* Print Document Apple Event */
12433 static pascal OSErr
12434 do_ae_print_documents (const AppleEvent
*pAE
, AppleEvent
*reply
, long refcon
)
12436 return errAEEventNotHandled
;
12440 static pascal OSErr
12441 do_ae_quit_application (AppleEvent
* message
, AppleEvent
*reply
, long refcon
)
12443 /* FixMe: Do we need an unwind-protect or something here? And what
12444 do we do about unsaved files. Currently just forces quit rather
12445 than doing recursive callback to get user input. */
12447 terminate_flag
= true;
12449 /* Fkill_emacs doesn't return. We have to return. (TI) */
12456 profiler_exit_proc ()
12458 ProfilerDump ("\pEmacs.prof");
12463 /* These few functions implement Emacs as a normal Mac application
12464 (almost): set up the heap and the Toolbox, handle necessary
12465 system events plus a few simple menu events. They also set up
12466 Emacs's access to functions defined in the rest of this file.
12467 Emacs uses function hooks to perform all its terminal I/O. A
12468 complete list of these functions appear in termhooks.h. For what
12469 they do, read the comments there and see also w32term.c and
12470 xterm.c. What's noticeably missing here is the event loop, which
12471 is normally present in most Mac application. After performing the
12472 necessary Mac initializations, main passes off control to
12473 emacs_main (corresponding to main in emacs.c). Emacs_main calls
12474 mac_read_socket (defined further below) to read input. This is
12475 where WaitNextEvent is called to process Mac events. This is also
12476 where check_alarm in sysdep.c is called to simulate alarm signals.
12477 This makes the cursor jump back to its correct position after
12478 briefly jumping to that of the matching parenthesis, print useful
12479 hints and prompts in the minibuffer after the user stops typing for
12482 #if !TARGET_API_MAC_CARBON
12487 #if __profile__ /* is the profiler on? */
12488 if (ProfilerInit(collectDetailed
, bestTimeBase
, 5000, 200))
12493 /* set creator and type for files created by MSL */
12494 _fcreator
= 'EMAx';
12498 do_init_managers ();
12502 do_check_ram_size ();
12504 init_emacs_passwd_dir ();
12508 initialize_applescript ();
12510 init_required_apple_events ();
12516 /* set up argv array from STR# resource */
12517 get_string_list (&argv
, ARGV_STRING_LIST_ID
);
12521 /* free up AppleScript resources on exit */
12522 atexit (terminate_applescript
);
12524 #if __profile__ /* is the profiler on? */
12525 atexit (profiler_exit_proc
);
12528 /* 3rd param "envp" never used in emacs_main */
12529 (void) emacs_main (argc
, argv
, 0);
12532 /* Never reached - real exit in Fkill_emacs */
12537 /* Table for translating Mac keycode to X keysym values. Contributed
12538 by Sudhir Shenoy. */
12539 static unsigned char keycode_to_xkeysym_table
[] = {
12541 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
12542 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
12543 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
12544 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
12546 0, '\xae' /* kp. */, 0, '\xaa' /* kp* */,
12547 0, '\xab' /* kp+ */, 0, '\x7f' /* kp_clr */,
12548 0, 0, 0, '\xaf' /* kp/ */,
12549 '\x8d' /* kp_ent */, 0, '\xad' /* kp- */, 0,
12551 0, '\xbd' /* kp= */, '\xb0' /* kp0 */, '\xb1' /* kp1 */,
12552 '\xb2' /* kp2 */, '\xb3' /* kp3 */, '\xb4' /* kp4 */, '\xb5' /* kp5 */,
12553 '\xb6' /* kp6 */, '\xb7' /* kp7 */, 0, '\xb8' /* kp8 */,
12554 '\xb9' /* kp9 */, 0, 0, 0,
12556 '\xc2' /* F5 */, '\xc3' /* F6 */, '\xc4' /* F7 */, '\xc0' /* F3 */,
12557 '\xc5' /* F8 */, '\xc6' /* F9 */, 0, '\xc8' /* F11 */,
12558 0, '\xca' /* F13 */, 0, '\xcb' /* F14 */,
12559 0, '\xc7' /* F10 */, 0, '\xc9' /* F12 */,
12561 0, '\xcc' /* F15 */, '\x9e' /* ins */, '\x95' /* home */,
12562 '\x9a' /* pgup */, '\x9f' /* del */, '\xc1' /* F4 */, '\x9c' /* end */,
12563 '\xbf' /* F2 */, '\x9b' /* pgdown */, '\xbe' /* F1 */, '\x51' /* left */,
12564 '\x53' /* right */, '\x54' /* down */, '\x52' /* up */, 0
12568 keycode_to_xkeysym (int keyCode
, int *xKeySym
)
12570 *xKeySym
= keycode_to_xkeysym_table
[keyCode
& 0x7f];
12571 return *xKeySym
!= 0;
12574 /* Emacs calls this whenever it wants to read an input event from the
12577 XTread_socket (int sd
, struct input_event
*bufp
, int numchars
, int expected
)
12580 #if USE_CARBON_EVENTS
12581 OSStatus rneResult
;
12583 EventMouseButton mouseBtn
;
12587 EventMask event_mask
;
12590 if (interrupt_input_blocked
)
12592 interrupt_input_pending
= 1;
12597 interrupt_input_pending
= 0;
12600 /* So people can tell when we have read the available input. */
12601 input_signal_count
++;
12606 /* Don't poll for events to process (specifically updateEvt) if
12607 window update currently already in progress. A call to redisplay
12608 (in do_window_update) can be preempted by another call to
12609 redisplay, causing blank regions to be left on the screen and the
12610 cursor to be left at strange places. */
12611 if (handling_window_update
)
12617 if (terminate_flag
)
12618 Fkill_emacs (make_number (1));
12620 /* It is necessary to set this (additional) argument slot of an
12621 event to nil because keyboard.c protects incompletely processed
12622 event from being garbage collected by placing them in the
12623 kbd_buffer_gcpro vector. */
12626 event_mask
= everyEvent
;
12627 if (NILP (Fboundp (Qmac_ready_for_drag_n_drop
)))
12628 event_mask
-= highLevelEventMask
;
12630 #if USE_CARBON_EVENTS
12631 rneResult
= ReceiveNextEvent (0, NULL
,
12633 ? TicksToEventTime (app_sleep_time
)
12638 /* Handle new events */
12639 if (!mac_convert_event_ref (eventRef
, &er
))
12640 switch (GetEventClass (eventRef
))
12642 case kEventClassMouse
:
12643 if (GetEventKind (eventRef
) == kEventMouseWheelMoved
)
12647 WindowPtr window_ptr
= FrontNonFloatingWindow ();
12648 struct mac_output
*mwp
= (mac_output
*) GetWRefCon (window_ptr
);
12649 GetEventParameter(eventRef
, kEventParamMouseWheelDelta
,
12650 typeSInt32
, NULL
, sizeof (SInt32
),
12652 GetEventParameter(eventRef
, kEventParamMouseLocation
,
12653 typeQDPoint
, NULL
, sizeof (Point
),
12655 bufp
->kind
= MOUSE_WHEEL_EVENT
;
12656 bufp
->code
= delta
;
12657 bufp
->modifiers
= mac_event_to_emacs_modifiers(eventRef
);
12658 SetPort (GetWindowPort (window_ptr
));
12659 GlobalToLocal (&point
);
12660 XSETINT (bufp
->x
, point
.h
);
12661 XSETINT (bufp
->y
, point
.v
);
12662 XSETFRAME (bufp
->frame_or_window
, mwp
->mFP
);
12663 bufp
->timestamp
= EventTimeToTicks (GetEventTime (eventRef
))*(1000/60);
12667 SendEventToEventTarget (eventRef
, GetEventDispatcherTarget ());
12671 /* Send the event to the appropriate receiver. */
12672 SendEventToEventTarget (eventRef
, GetEventDispatcherTarget ());
12676 if (WaitNextEvent (event_mask
, &er
, (expected
? app_sleep_time
: 0L), NULL
))
12677 #endif /* USE_CARBON_EVENTS */
12683 WindowPtr window_ptr
= FrontWindow ();
12686 #if USE_CARBON_EVENTS
12687 /* This is needed to send mouse events like aqua window buttons
12688 to the correct handler. */
12689 if (eventNotHandledErr
!= SendEventToEventTarget (eventRef
, GetEventDispatcherTarget ())) {
12693 if (!is_emacs_window(window_ptr
))
12697 if (mouse_tracking_in_progress
== mouse_tracking_scroll_bar
12698 && er
.what
== mouseUp
)
12700 struct mac_output
*mwp
= (mac_output
*) GetWRefCon (window_ptr
);
12701 Point mouse_loc
= er
.where
;
12703 /* Convert to local coordinates of new window. */
12704 #if TARGET_API_MAC_CARBON
12705 SetPort (GetWindowPort (window_ptr
));
12707 SetPort (window_ptr
);
12710 GlobalToLocal (&mouse_loc
);
12712 #if USE_CARBON_EVENTS
12713 bufp
->code
= mac_get_mouse_btn (eventRef
);
12715 bufp
->code
= 0; /* only one mouse button */
12717 bufp
->kind
= SCROLL_BAR_CLICK_EVENT
;
12718 bufp
->frame_or_window
= tracked_scroll_bar
->window
;
12719 bufp
->part
= scroll_bar_handle
;
12720 #if USE_CARBON_EVENTS
12721 bufp
->modifiers
= mac_event_to_emacs_modifiers (eventRef
);
12723 bufp
->modifiers
= mac_to_emacs_modifiers (er
.modifiers
);
12725 bufp
->modifiers
|= up_modifier
;
12726 bufp
->timestamp
= er
.when
* (1000 / 60);
12727 /* ticks to milliseconds */
12729 XSETINT (bufp
->x
, tracked_scroll_bar
->left
+ 2);
12730 XSETINT (bufp
->y
, mouse_loc
.v
- 24);
12731 tracked_scroll_bar
->dragging
= Qnil
;
12732 mouse_tracking_in_progress
= mouse_tracking_none
;
12733 tracked_scroll_bar
= NULL
;
12738 part_code
= FindWindow (er
.where
, &window_ptr
);
12744 struct frame
*f
= ((mac_output
*)
12745 GetWRefCon (FrontWindow ()))->mFP
;
12746 saved_menu_event_location
= er
.where
;
12747 bufp
->kind
= MENU_BAR_ACTIVATE_EVENT
;
12748 XSETFRAME (bufp
->frame_or_window
, f
);
12754 if (window_ptr
!= FrontWindow ())
12755 SelectWindow (window_ptr
);
12758 SInt16 control_part_code
;
12760 struct mac_output
*mwp
= (mac_output
*)
12761 GetWRefCon (window_ptr
);
12762 Point mouse_loc
= er
.where
;
12764 /* convert to local coordinates of new window */
12765 #if TARGET_API_MAC_CARBON
12766 SetPort (GetWindowPort (window_ptr
));
12768 SetPort (window_ptr
);
12771 GlobalToLocal (&mouse_loc
);
12772 #if TARGET_API_MAC_CARBON
12773 ch
= FindControlUnderMouse (mouse_loc
, window_ptr
,
12774 &control_part_code
);
12776 control_part_code
= FindControl (mouse_loc
, window_ptr
, &ch
);
12779 #if USE_CARBON_EVENTS
12780 bufp
->code
= mac_get_mouse_btn (eventRef
);
12782 bufp
->code
= 0; /* only one mouse button */
12784 XSETINT (bufp
->x
, mouse_loc
.h
);
12785 XSETINT (bufp
->y
, mouse_loc
.v
);
12786 bufp
->timestamp
= er
.when
* (1000 / 60);
12787 /* ticks to milliseconds */
12789 #if TARGET_API_MAC_CARBON
12792 if (control_part_code
!= 0)
12795 struct scroll_bar
*bar
= (struct scroll_bar
*)
12796 GetControlReference (ch
);
12797 x_scroll_bar_handle_click (bar
, control_part_code
, &er
,
12799 if (er
.what
== mouseDown
12800 && control_part_code
== kControlIndicatorPart
)
12802 mouse_tracking_in_progress
12803 = mouse_tracking_scroll_bar
;
12804 tracked_scroll_bar
= bar
;
12808 mouse_tracking_in_progress
= mouse_tracking_none
;
12809 tracked_scroll_bar
= NULL
;
12814 bufp
->kind
= MOUSE_CLICK_EVENT
;
12815 XSETFRAME (bufp
->frame_or_window
, mwp
->mFP
);
12816 if (er
.what
== mouseDown
)
12817 mouse_tracking_in_progress
12818 = mouse_tracking_mouse_movement
;
12820 mouse_tracking_in_progress
= mouse_tracking_none
;
12823 #if USE_CARBON_EVENTS
12824 bufp
->modifiers
= mac_event_to_emacs_modifiers (eventRef
);
12826 bufp
->modifiers
= mac_to_emacs_modifiers (er
.modifiers
);
12832 bufp
->modifiers
|= down_modifier
;
12835 bufp
->modifiers
|= up_modifier
;
12844 #if TARGET_API_MAC_CARBON
12848 GetQDGlobalsScreenBits (&bm
);
12849 DragWindow (window_ptr
, er
.where
, &bm
.bounds
);
12851 #else /* not TARGET_API_MAC_CARBON */
12852 DragWindow (window_ptr
, er
.where
, &qd
.screenBits
.bounds
);
12853 #endif /* not TARGET_API_MAC_CARBON */
12857 if (TrackGoAway (window_ptr
, er
.where
))
12859 bufp
->kind
= DELETE_WINDOW_EVENT
;
12860 XSETFRAME (bufp
->frame_or_window
,
12861 ((mac_output
*) GetWRefCon (window_ptr
))->mFP
);
12866 /* window resize handling added --ben */
12868 do_grow_window(window_ptr
, &er
);
12871 /* window zoom handling added --ben */
12874 if (TrackBox (window_ptr
, er
.where
, part_code
))
12875 do_zoom_window (window_ptr
, part_code
);
12887 #if USE_CARBON_EVENTS
12888 if (eventNotHandledErr
== SendEventToEventTarget (eventRef
, GetEventDispatcherTarget ()))
12896 int keycode
= (er
.message
& keyCodeMask
) >> 8;
12899 #if USE_CARBON_EVENTS
12900 /* When using Carbon Events, we need to pass raw keyboard events
12901 to the TSM ourselves. If TSM handles it, it will pass back
12902 noErr, otherwise it will pass back "eventNotHandledErr" and
12903 we can process it normally. */
12904 if ((!NILP (Vmac_pass_command_to_system
)
12905 || !(er
.modifiers
& cmdKey
))
12906 && (!NILP (Vmac_pass_control_to_system
)
12907 || !(er
.modifiers
& controlKey
)))
12910 err
= SendEventToEventTarget (eventRef
,
12911 GetEventDispatcherTarget ());
12912 if (err
!= eventNotHandledErr
)
12917 if (!IsValidWindowPtr (FrontNonFloatingWindow ()))
12926 if (keycode
== 0x33) /* delete key (charCode translated to 0x8) */
12929 bufp
->kind
= ASCII_KEYSTROKE_EVENT
;
12931 else if (keycode_to_xkeysym (keycode
, &xkeysym
))
12933 bufp
->code
= 0xff00 | xkeysym
;
12934 bufp
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
12936 else if (!NILP (Vmac_reverse_ctrl_meta
) && (er
.modifiers
& controlKey
))
12938 /* This is a special case to deal with converting from
12939 a control character to non-control character */
12940 int new_modifiers
= er
.modifiers
& ~controlKey
;
12941 int new_keycode
= keycode
| new_modifiers
;
12942 Ptr kchr_ptr
= (Ptr
) GetScriptManagerVariable (smKCHRCache
);
12943 unsigned long some_state
= 0;
12944 bufp
->code
= KeyTranslate (kchr_ptr
, new_keycode
, &some_state
) & 0xff;
12945 bufp
->kind
= ASCII_KEYSTROKE_EVENT
;
12949 if (er
.modifiers
& macMetaKey
)
12951 /* This code comes from Keyboard Resource, Appendix
12952 C of IM - Text. This is necessary since shift is
12953 ignored in KCHR table translation when option or
12954 command is pressed. */
12955 int new_modifiers
= er
.modifiers
& 0xf600;
12956 /* mask off option and command */
12957 int new_keycode
= keycode
| new_modifiers
;
12958 Ptr kchr_ptr
= (Ptr
) GetScriptManagerVariable (smKCHRCache
);
12959 unsigned long some_state
= 0;
12960 bufp
->code
= KeyTranslate (kchr_ptr
, new_keycode
,
12961 &some_state
) & 0xff;
12964 bufp
->code
= er
.message
& charCodeMask
;
12965 bufp
->kind
= ASCII_KEYSTROKE_EVENT
;
12969 /* If variable mac-convert-keyboard-input-to-latin-1 is non-nil,
12970 convert non-ASCII characters typed at the Mac keyboard
12971 (presumed to be in the Mac Roman encoding) to iso-latin-1
12972 encoding before they are passed to Emacs. This enables the
12973 Mac keyboard to be used to enter non-ASCII iso-latin-1
12974 characters directly. */
12975 if (mac_keyboard_text_encoding
!= kTextEncodingMacRoman
12976 && bufp
->kind
== ASCII_KEYSTROKE_EVENT
&& bufp
->code
>= 128)
12978 static TECObjectRef converter
= NULL
;
12979 OSStatus the_err
= noErr
;
12980 OSStatus convert_status
= noErr
;
12982 if (converter
== NULL
)
12984 the_err
= TECCreateConverter (&converter
,
12985 kTextEncodingMacRoman
,
12986 mac_keyboard_text_encoding
);
12987 current_mac_keyboard_text_encoding
12988 = mac_keyboard_text_encoding
;
12990 else if (mac_keyboard_text_encoding
12991 != current_mac_keyboard_text_encoding
)
12993 /* Free the converter for the current encoding before
12994 creating a new one. */
12995 TECDisposeConverter (converter
);
12996 the_err
= TECCreateConverter (&converter
,
12997 kTextEncodingMacRoman
,
12998 mac_keyboard_text_encoding
);
12999 current_mac_keyboard_text_encoding
13000 = mac_keyboard_text_encoding
;
13003 if (the_err
== noErr
)
13005 unsigned char ch
= bufp
->code
;
13006 ByteCount actual_input_length
, actual_output_length
;
13007 unsigned char outch
;
13009 convert_status
= TECConvertText (converter
, &ch
, 1,
13010 &actual_input_length
,
13012 &actual_output_length
);
13013 if (convert_status
== noErr
13014 && actual_input_length
== 1
13015 && actual_output_length
== 1)
13016 bufp
->code
= outch
;
13020 #if USE_CARBON_EVENTS
13021 bufp
->modifiers
= mac_event_to_emacs_modifiers (eventRef
);
13023 bufp
->modifiers
= mac_to_emacs_modifiers (er
.modifiers
);
13028 = (mac_output
*) GetWRefCon (FrontNonFloatingWindow ());
13029 XSETFRAME (bufp
->frame_or_window
, mwp
->mFP
);
13032 bufp
->timestamp
= er
.when
* (1000 / 60); /* ticks to milliseconds */
13037 case kHighLevelEvent
:
13038 drag_and_drop_file_list
= Qnil
;
13040 AEProcessAppleEvent(&er
);
13042 /* Build a DRAG_N_DROP_EVENT type event as is done in
13043 constuct_drag_n_drop in w32term.c. */
13044 if (!NILP (drag_and_drop_file_list
))
13046 struct frame
*f
= NULL
;
13050 wp
= FrontNonFloatingWindow ();
13051 if (wp
&& is_emacs_window(wp
))
13052 f
= ((mac_output
*) GetWRefCon (wp
))->mFP
;
13054 bufp
->kind
= DRAG_N_DROP_EVENT
;
13056 bufp
->timestamp
= er
.when
* (1000 / 60);
13057 /* ticks to milliseconds */
13058 #if USE_CARBON_EVENTS
13059 bufp
->modifiers
= mac_event_to_emacs_modifiers (eventRef
);
13061 bufp
->modifiers
= mac_to_emacs_modifiers (er
.modifiers
);
13064 XSETINT (bufp
->x
, 0);
13065 XSETINT (bufp
->y
, 0);
13067 XSETFRAME (frame
, f
);
13068 bufp
->frame_or_window
= Fcons (frame
, drag_and_drop_file_list
);
13070 /* Regardless of whether Emacs was suspended or in the
13071 foreground, ask it to redraw its entire screen.
13072 Otherwise parts of the screen can be left in an
13073 inconsistent state. */
13075 #if TARGET_API_MAC_CARBON
13079 GetWindowPortBounds (wp
, &r
);
13080 InvalWindowRect (wp
, &r
);
13082 #else /* not TARGET_API_MAC_CARBON */
13083 InvalRect (&(wp
->portRect
));
13084 #endif /* not TARGET_API_MAC_CARBON */
13091 #if USE_CARBON_EVENTS
13092 ReleaseEvent (eventRef
);
13096 /* If the focus was just given to an autoraising frame,
13098 /* ??? This ought to be able to handle more than one such frame. */
13099 if (pending_autoraise_frame
)
13101 x_raise_frame (pending_autoraise_frame
);
13102 pending_autoraise_frame
= 0;
13105 #if !TARGET_API_MAC_CARBON
13106 check_alarm (); /* simulate the handling of a SIGALRM */
13110 static Point old_mouse_pos
= { -1, -1 };
13112 if (app_is_suspended
)
13114 old_mouse_pos
.h
= -1;
13115 old_mouse_pos
.v
= -1;
13123 struct scroll_bar
*sb
;
13125 wp
= FrontWindow ();
13126 if (is_emacs_window (wp
))
13128 f
= ((mac_output
*) GetWRefCon (wp
))->mFP
;
13130 #if TARGET_API_MAC_CARBON
13131 SetPort (GetWindowPort (wp
));
13136 GetMouse (&mouse_pos
);
13138 if (!EqualPt (mouse_pos
, old_mouse_pos
))
13140 if (mouse_tracking_in_progress
== mouse_tracking_scroll_bar
13141 && tracked_scroll_bar
)
13142 x_scroll_bar_note_movement (tracked_scroll_bar
,
13144 - XINT (tracked_scroll_bar
->top
),
13145 TickCount() * (1000 / 60));
13147 note_mouse_movement (f
, &mouse_pos
);
13149 old_mouse_pos
= mouse_pos
;
13161 /* Need to override CodeWarrior's input function so no conversion is
13162 done on newlines Otherwise compiled functions in .elc files will be
13163 read incorrectly. Defined in ...:MSL C:MSL
13164 Common:Source:buffer_io.c. */
13167 __convert_to_newlines (unsigned char * p
, size_t * n
)
13169 #pragma unused(p,n)
13173 __convert_from_newlines (unsigned char * p
, size_t * n
)
13175 #pragma unused(p,n)
13180 /* Initialize the struct pointed to by MW to represent a new COLS x
13181 ROWS Macintosh window, using font with name FONTNAME and size
13184 NewMacWindow (FRAME_PTR fp
)
13187 #if TARGET_API_MAC_CARBON
13188 static int making_terminal_window
= 0;
13190 static int making_terminal_window
= 1;
13193 mwp
= fp
->output_data
.mac
;
13195 if (making_terminal_window
)
13197 if (!(mwp
->mWP
= GetNewCWindow (TERM_WINDOW_RESOURCE
, NULL
,
13200 making_terminal_window
= 0;
13203 if (!(mwp
->mWP
= GetNewCWindow (WINDOW_RESOURCE
, NULL
, (WindowPtr
) -1)))
13206 SetWRefCon (mwp
->mWP
, (long) mwp
);
13207 /* so that update events can find this mac_output struct */
13208 mwp
->mFP
= fp
; /* point back to emacs frame */
13210 #if TARGET_API_MAC_CARBON
13211 SetPort (GetWindowPort (mwp
->mWP
));
13213 SetPort (mwp
->mWP
);
13218 SizeWindow (mwp
->mWP
, mwp
->pixel_width
, mwp
->pixel_height
, false);
13219 ShowWindow (mwp
->mWP
);
13224 void make_mac_frame (struct frame
*f
)
13226 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
13227 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_right
;
13231 f
->output_data
.mac
->cursor_pixel
= 0;
13232 f
->output_data
.mac
->border_pixel
= 0x00ff00;
13233 f
->output_data
.mac
->mouse_pixel
= 0xff00ff;
13234 f
->output_data
.mac
->cursor_foreground_pixel
= 0x0000ff;
13236 f
->output_data
.mac
->desired_cursor
= FILLED_BOX_CURSOR
;
13238 f
->output_data
.mac
->fontset
= -1;
13239 f
->output_data
.mac
->scroll_bar_foreground_pixel
= -1;
13240 f
->output_data
.mac
->scroll_bar_background_pixel
= -1;
13241 f
->output_data
.mac
->left_pos
= 4;
13242 f
->output_data
.mac
->top_pos
= 4;
13243 f
->output_data
.mac
->border_width
= 0;
13244 f
->output_data
.mac
->explicit_parent
= 0;
13246 f
->output_data
.mac
->internal_border_width
= 0;
13248 f
->output_method
= output_mac
;
13257 void make_mac_terminal_frame (struct frame
*f
)
13261 XSETFRAME (frame
, f
);
13263 f
->output_method
= output_mac
;
13264 f
->output_data
.mac
= (struct mac_output
*)
13265 xmalloc (sizeof (struct mac_output
));
13266 bzero (f
->output_data
.mac
, sizeof (struct mac_output
));
13267 f
->output_data
.mac
->fontset
= -1;
13268 f
->output_data
.mac
->scroll_bar_foreground_pixel
= -1;
13269 f
->output_data
.mac
->scroll_bar_background_pixel
= -1;
13271 XSETFRAME (FRAME_KBOARD (f
)->Vdefault_minibuffer_frame
, f
);
13276 make_mac_frame (f
);
13280 /* Need to be initialized for unshow_buffer in window.c. */
13281 selected_window
= f
->selected_window
;
13283 Fmodify_frame_parameters (frame
,
13284 Fcons (Fcons (Qfont
,
13285 build_string ("-*-monaco-medium-r-*--*-90-*-*-*-*-mac-roman")), Qnil
));
13286 Fmodify_frame_parameters (frame
,
13287 Fcons (Fcons (Qforeground_color
,
13288 build_string ("black")), Qnil
));
13289 Fmodify_frame_parameters (frame
,
13290 Fcons (Fcons (Qbackground_color
,
13291 build_string ("white")), Qnil
));
13295 /***********************************************************************
13297 ***********************************************************************/
13299 #ifdef USE_X_TOOLKIT
13300 static XrmOptionDescRec emacs_options
[] = {
13301 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
13302 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
13304 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
13305 XrmoptionSepArg
, NULL
},
13306 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
13308 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13309 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13310 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13311 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13312 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13313 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
13314 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
13316 #endif /* USE_X_TOOLKIT */
13318 #ifdef MULTI_KBOARD
13319 /* Test whether two display-name strings agree up to the dot that separates
13320 the screen number from the server number. */
13322 same_x_server (name1
, name2
)
13323 char *name1
, *name2
;
13325 int seen_colon
= 0;
13326 unsigned char *system_name
= SDATA (Vsystem_name
);
13327 int system_name_length
= strlen (system_name
);
13328 int length_until_period
= 0;
13330 while (system_name
[length_until_period
] != 0
13331 && system_name
[length_until_period
] != '.')
13332 length_until_period
++;
13334 /* Treat `unix' like an empty host name. */
13335 if (! strncmp (name1
, "unix:", 5))
13337 if (! strncmp (name2
, "unix:", 5))
13339 /* Treat this host's name like an empty host name. */
13340 if (! strncmp (name1
, system_name
, system_name_length
)
13341 && name1
[system_name_length
] == ':')
13342 name1
+= system_name_length
;
13343 if (! strncmp (name2
, system_name
, system_name_length
)
13344 && name2
[system_name_length
] == ':')
13345 name2
+= system_name_length
;
13346 /* Treat this host's domainless name like an empty host name. */
13347 if (! strncmp (name1
, system_name
, length_until_period
)
13348 && name1
[length_until_period
] == ':')
13349 name1
+= length_until_period
;
13350 if (! strncmp (name2
, system_name
, length_until_period
)
13351 && name2
[length_until_period
] == ':')
13352 name2
+= length_until_period
;
13354 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
13358 if (seen_colon
&& *name1
== '.')
13362 && (*name1
== '.' || *name1
== '\0')
13363 && (*name2
== '.' || *name2
== '\0'));
13367 int mac_initialized
= 0;
13370 mac_initialize_display_info ()
13372 struct mac_display_info
*dpyinfo
= &one_mac_display_info
;
13373 GDHandle main_device_handle
;
13375 bzero (dpyinfo
, sizeof (*dpyinfo
));
13377 /* Put it on x_display_name_list. */
13378 x_display_name_list
= Fcons (Fcons (build_string ("Mac"), Qnil
),
13379 x_display_name_list
);
13380 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
13383 dpyinfo
->mac_id_name
13384 = (char *) xmalloc (SCHARS (Vinvocation_name
)
13385 + SCHARS (Vsystem_name
)
13387 sprintf (dpyinfo
->mac_id_name
, "%s@%s",
13388 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
13390 dpyinfo
->mac_id_name
= (char *) xmalloc (strlen ("Mac Display") + 1);
13391 strcpy (dpyinfo
->mac_id_name
, "Mac Display");
13394 main_device_handle
= LMGetMainDevice();
13396 dpyinfo
->reference_count
= 0;
13397 dpyinfo
->resx
= 75.0;
13398 dpyinfo
->resy
= 75.0;
13399 dpyinfo
->n_planes
= 1;
13400 dpyinfo
->n_cbits
= 16;
13401 dpyinfo
->height
= (**main_device_handle
).gdRect
.bottom
;
13402 dpyinfo
->width
= (**main_device_handle
).gdRect
.right
;
13403 dpyinfo
->grabbed
= 0;
13404 dpyinfo
->root_window
= NULL
;
13406 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
13407 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
13408 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
13409 dpyinfo
->mouse_face_window
= Qnil
;
13412 struct mac_display_info
*
13413 mac_term_init (display_name
, xrm_option
, resource_name
)
13414 Lisp_Object display_name
;
13416 char *resource_name
;
13418 struct mac_display_info
*dpyinfo
;
13419 GDHandle main_device_handle
;
13421 if (!mac_initialized
)
13424 mac_initialized
= 1;
13427 mac_initialize_display_info (display_name
);
13429 dpyinfo
= &one_mac_display_info
;
13431 main_device_handle
= LMGetMainDevice();
13433 dpyinfo
->height
= (**main_device_handle
).gdRect
.bottom
;
13434 dpyinfo
->width
= (**main_device_handle
).gdRect
.right
;
13440 void MakeMeTheFrontProcess ()
13442 ProcessSerialNumber psn
;
13445 err
= GetCurrentProcess (&psn
);
13447 (void) SetFrontProcess (&psn
);
13449 #endif /* MAC_OSX */
13451 /* Set up use of X before we make the first connection. */
13453 static struct redisplay_interface x_redisplay_interface
=
13458 x_clear_end_of_line
,
13460 x_after_update_window_line
,
13461 x_update_window_begin
,
13462 x_update_window_end
,
13465 x_clear_mouse_face
,
13466 x_get_glyph_overhangs
,
13467 x_fix_overlapping_area
13473 rif
= &x_redisplay_interface
;
13475 clear_frame_hook
= x_clear_frame
;
13476 ins_del_lines_hook
= x_ins_del_lines
;
13477 delete_glyphs_hook
= x_delete_glyphs
;
13478 ring_bell_hook
= XTring_bell
;
13479 reset_terminal_modes_hook
= XTreset_terminal_modes
;
13480 set_terminal_modes_hook
= XTset_terminal_modes
;
13481 update_begin_hook
= x_update_begin
;
13482 update_end_hook
= x_update_end
;
13483 set_terminal_window_hook
= XTset_terminal_window
;
13484 read_socket_hook
= XTread_socket
;
13485 frame_up_to_date_hook
= XTframe_up_to_date
;
13486 mouse_position_hook
= XTmouse_position
;
13487 frame_rehighlight_hook
= XTframe_rehighlight
;
13488 frame_raise_lower_hook
= XTframe_raise_lower
;
13490 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
13491 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
13492 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
13493 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
13495 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
13497 scroll_region_ok
= 1; /* we'll scroll partial frames */
13498 char_ins_del_ok
= 1;
13499 line_ins_del_ok
= 1; /* we'll just blt 'em */
13500 fast_clear_end_of_line
= 1; /* X does this well */
13501 memory_below_frame
= 0; /* we don't remember what scrolls
13506 last_tool_bar_item
= -1;
13507 any_help_event_p
= 0;
13509 /* Try to use interrupt input; if we can't, then start polling. */
13510 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
13512 #ifdef USE_X_TOOLKIT
13513 XtToolkitInitialize ();
13514 Xt_app_con
= XtCreateApplicationContext ();
13515 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
13517 /* Install an asynchronous timer that processes Xt timeout events
13518 every 0.1s. This is necessary because some widget sets use
13519 timeouts internally, for example the LessTif menu bar, or the
13520 Xaw3d scroll bar. When Xt timouts aren't processed, these
13521 widgets don't behave normally. */
13523 EMACS_TIME interval
;
13524 EMACS_SET_SECS_USECS (interval
, 0, 100000);
13525 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
13529 #if USE_TOOLKIT_SCROLL_BARS
13530 xaw3d_arrow_scroll
= False
;
13531 xaw3d_pick_top
= True
;
13535 /* Note that there is no real way portable across R3/R4 to get the
13536 original error handler. */
13537 XSetErrorHandler (x_error_handler
);
13538 XSetIOErrorHandler (x_io_error_quitter
);
13540 /* Disable Window Change signals; they are handled by X events. */
13542 signal (SIGWINCH
, SIG_DFL
);
13543 #endif /* ! defined (SIGWINCH) */
13545 signal (SIGPIPE
, x_connection_signal
);
13548 mac_initialize_display_info ();
13550 #if TARGET_API_MAC_CARBON
13551 init_required_apple_events ();
13553 init_mac_drag_n_drop ();
13555 #if USE_CARBON_EVENTS
13556 init_service_handler ();
13559 DisableMenuCommand (NULL
, kHICommandQuit
);
13561 if (!inhibit_window_system
)
13562 MakeMeTheFrontProcess ();
13571 staticpro (&x_error_message_string
);
13572 x_error_message_string
= Qnil
;
13575 staticpro (&x_display_name_list
);
13576 x_display_name_list
= Qnil
;
13578 staticpro (&last_mouse_scroll_bar
);
13579 last_mouse_scroll_bar
= Qnil
;
13581 staticpro (&Qvendor_specific_keysyms
);
13582 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
13584 staticpro (&last_mouse_press_frame
);
13585 last_mouse_press_frame
= Qnil
;
13587 Qmac_ready_for_drag_n_drop
= intern ("mac-ready-for-drag-n-drop");
13588 staticpro (&Qmac_ready_for_drag_n_drop
);
13591 staticpro (&help_echo
);
13592 help_echo_object
= Qnil
;
13593 staticpro (&help_echo_object
);
13594 help_echo_window
= Qnil
;
13595 staticpro (&help_echo_window
);
13596 previous_help_echo
= Qnil
;
13597 staticpro (&previous_help_echo
);
13598 help_echo_pos
= -1;
13600 DEFVAR_BOOL ("x-autoselect-window", &x_autoselect_window_p
,
13601 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
13602 x_autoselect_window_p
= 0;
13604 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
13605 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
13606 For example, if a block cursor is over a tab, it will be drawn as
13607 wide as that tab on the display. */);
13608 x_stretch_cursor_p
= 0;
13610 #if 0 /* TODO: Setting underline position from font properties. */
13611 DEFVAR_BOOL ("x-use-underline-position-properties",
13612 &x_use_underline_position_properties
,
13613 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
13614 nil means ignore them. If you encounter fonts with bogus
13615 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
13616 to 4.1, set this to nil. */);
13617 x_use_underline_position_properties
= 1;
13620 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
13621 doc
: /* If not nil, Emacs uses toolkit scroll bars. */);
13622 Vx_toolkit_scroll_bars
= Qt
;
13624 staticpro (&last_mouse_motion_frame
);
13625 last_mouse_motion_frame
= Qnil
;
13627 DEFVAR_LISP ("mac-command-key-is-meta", &Vmac_command_key_is_meta
,
13628 doc
: /* Non-nil means that the command key is used as the Emacs meta key.
13629 Otherwise the option key is used. */);
13630 Vmac_command_key_is_meta
= Qt
;
13632 DEFVAR_LISP ("mac-reverse-ctrl-meta", &Vmac_reverse_ctrl_meta
,
13633 doc
: /* Non-nil means that the control and meta keys are reversed. This is
13634 useful for non-standard keyboard layouts. */);
13635 Vmac_reverse_ctrl_meta
= Qnil
;
13637 #if USE_CARBON_EVENTS
13638 DEFVAR_LISP ("mac-wheel-button-is-mouse-2", &Vmac_wheel_button_is_mouse_2
,
13639 doc
: /* Non-nil means that the wheel button will be treated as mouse-2 and
13640 the right click will be mouse-3.
13641 Otherwise, the right click will be mouse-2 and the wheel button mouse-3.*/);
13642 Vmac_wheel_button_is_mouse_2
= Qt
;
13644 DEFVAR_LISP ("mac-pass-command-to-system", &Vmac_pass_command_to_system
,
13645 doc
: /* If non-nil, the Mac \"Command\" key is passed on to the Mac
13646 Toolbox for processing before Emacs sees it. */);
13647 Vmac_pass_command_to_system
= Qt
;
13649 DEFVAR_LISP ("mac-pass-control-to-system", &Vmac_pass_control_to_system
,
13650 doc
: /* If non-nil, the Mac \"Control\" key is passed on to the Mac
13651 Toolbox for processing before Emacs sees it. */);
13652 Vmac_pass_control_to_system
= Qt
;
13655 DEFVAR_INT ("mac-keyboard-text-encoding", &mac_keyboard_text_encoding
,
13656 doc
: /* One of the Text Encoding Base constant values defined in the
13657 Basic Text Constants section of Inside Macintosh - Text Encoding
13658 Conversion Manager. Its value determines the encoding characters
13659 typed at the Mac keyboard (presumed to be in the MacRoman encoding)
13660 will convert into. E.g., if it is set to kTextEncodingMacRoman (0),
13661 its default value, no conversion takes place. If it is set to
13662 kTextEncodingISOLatin1 (0x201) or kTextEncodingISOLatin2 (0x202),
13663 characters typed on Mac keyboard are first converted into the
13664 ISO Latin-1 or ISO Latin-2 encoding, respectively before being
13665 passed to Emacs. Together with Emacs's set-keyboard-coding-system
13666 command, this enables the Mac keyboard to be used to enter non-ASCII
13667 characters directly. */);
13668 mac_keyboard_text_encoding
= kTextEncodingMacRoman
;