1 /* Implementation of GUI terminal on the Mac OS.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004,
3 2005 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* Contributed by Andrew Choi (akochoi@mac.com). */
30 #include "blockinput.h"
38 #if TARGET_API_MAC_CARBON
39 /* USE_CARBON_EVENTS determines if the Carbon Event Manager is used to
40 obtain events from the event queue. If set to 0, WaitNextEvent is
42 #define USE_CARBON_EVENTS 1
43 #else /* not TARGET_API_MAC_CARBON */
44 #include <Quickdraw.h>
45 #include <ToolUtils.h>
49 #include <Resources.h>
51 #include <TextUtils.h>
55 #if defined (__MRC__) || (__MSL__ >= 0x6000)
56 #include <ControlDefinitions.h>
62 #endif /* not TARGET_API_MAC_CARBON */
71 #include <sys/param.h>
76 #include "dispextern.h"
78 #include "termhooks.h"
86 #include "intervals.h"
92 /* Non-nil means Emacs uses toolkit scroll bars. */
94 Lisp_Object Vx_toolkit_scroll_bars
;
96 /* If Non-nil, the text will be rendered using Core Graphics text rendering which may anti-alias the text. */
97 Lisp_Object Vmac_use_core_graphics
;
100 /* Non-zero means that a HELP_EVENT has been generated since Emacs
103 static int any_help_event_p
;
105 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
106 static Lisp_Object last_window
;
108 /* This is a chain of structures for all the X displays currently in
111 struct x_display_info
*x_display_list
;
113 /* This is a list of cons cells, each of the form (NAME
114 FONT-LIST-CACHE . RESOURCE-DATABASE), one for each element of
115 x_display_list and in the same order. NAME is the name of the
116 frame. FONT-LIST-CACHE records previous values returned by
117 x-list-fonts. RESOURCE-DATABASE preserves the X Resource Database
118 equivalent, which is implemented with a Lisp object, for the
121 Lisp_Object x_display_name_list
;
123 /* This is display since Mac does not support multiple ones. */
124 struct mac_display_info one_mac_display_info
;
126 /* Frame being updated by update_frame. This is declared in term.c.
127 This is set by update_begin and looked at by all the XT functions.
128 It is zero while not inside an update. In that case, the XT
129 functions assume that `selected_frame' is the frame to apply to. */
131 extern struct frame
*updating_frame
;
133 /* This is a frame waiting to be auto-raised, within XTread_socket. */
135 struct frame
*pending_autoraise_frame
;
139 Formerly, we used PointerMotionHintMask (in standard_event_mask)
140 so that we would have to call XQueryPointer after each MotionNotify
141 event to ask for another such event. However, this made mouse tracking
142 slow, and there was a bug that made it eventually stop.
144 Simply asking for MotionNotify all the time seems to work better.
146 In order to avoid asking for motion events and then throwing most
147 of them away or busy-polling the server for mouse positions, we ask
148 the server for pointer motion hints. This means that we get only
149 one event per group of mouse movements. "Groups" are delimited by
150 other kinds of events (focus changes and button clicks, for
151 example), or by XQueryPointer calls; when one of these happens, we
152 get another MotionNotify event the next time the mouse moves. This
153 is at least as efficient as getting motion events when mouse
154 tracking is on, and I suspect only negligibly worse when tracking
157 /* Where the mouse was last time we reported a mouse event. */
159 static Rect last_mouse_glyph
;
160 static FRAME_PTR last_mouse_glyph_frame
;
162 /* The scroll bar in which the last X motion event occurred.
164 If the last X motion event occurred in a scroll bar, we set this so
165 XTmouse_position can know whether to report a scroll bar motion or
168 If the last X motion event didn't occur in a scroll bar, we set
169 this to Qnil, to tell XTmouse_position to return an ordinary motion
172 static Lisp_Object last_mouse_scroll_bar
;
174 /* This is a hack. We would really prefer that XTmouse_position would
175 return the time associated with the position it returns, but there
176 doesn't seem to be any way to wrest the time-stamp from the server
177 along with the position query. So, we just keep track of the time
178 of the last movement we received, and return that in hopes that
179 it's somewhat accurate. */
181 static Time last_mouse_movement_time
;
183 struct scroll_bar
*tracked_scroll_bar
= NULL
;
185 /* Incremented by XTread_socket whenever it really tries to read
189 static int volatile input_signal_count
;
191 static int input_signal_count
;
194 extern Lisp_Object Vsystem_name
;
196 /* A mask of extra modifier bits to put into every keyboard char. */
198 extern EMACS_INT extra_keyboard_modifiers
;
200 /* The keysyms to use for the various modifiers. */
202 static Lisp_Object Qalt
, Qhyper
, Qsuper
, Qctrl
,
203 Qmeta
, Qmodifier_value
;
205 extern int inhibit_window_system
;
207 #if __MRC__ && !TARGET_API_MAC_CARBON
208 QDGlobals qd
; /* QuickDraw global information structure. */
211 #define mac_window_to_frame(wp) (((mac_output *) GetWRefCon (wp))->mFP)
213 struct mac_display_info
*mac_display_info_for_display (Display
*);
214 static void x_update_window_end
P_ ((struct window
*, int, int));
215 static int x_io_error_quitter
P_ ((Display
*));
216 int x_catch_errors
P_ ((Display
*));
217 void x_uncatch_errors
P_ ((Display
*, int));
218 void x_lower_frame
P_ ((struct frame
*));
219 void x_scroll_bar_clear
P_ ((struct frame
*));
220 int x_had_errors_p
P_ ((Display
*));
221 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
222 void x_raise_frame
P_ ((struct frame
*));
223 void x_set_window_size
P_ ((struct frame
*, int, int, int));
224 void x_wm_set_window_state
P_ ((struct frame
*, int));
225 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
226 void mac_initialize
P_ ((void));
227 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
228 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
229 static void x_update_end
P_ ((struct frame
*));
230 static void XTframe_up_to_date
P_ ((struct frame
*));
231 static void XTset_terminal_modes
P_ ((void));
232 static void XTreset_terminal_modes
P_ ((void));
233 static void x_clear_frame
P_ ((void));
234 static void frame_highlight
P_ ((struct frame
*));
235 static void frame_unhighlight
P_ ((struct frame
*));
236 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
237 static void mac_focus_changed
P_ ((int, struct mac_display_info
*,
238 struct frame
*, struct input_event
*));
239 static void x_detect_focus_change
P_ ((struct mac_display_info
*,
240 EventRecord
*, struct input_event
*));
241 static void XTframe_rehighlight
P_ ((struct frame
*));
242 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
243 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
244 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
245 enum text_cursor_kinds
));
247 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*, int, GC
));
248 static void x_flush
P_ ((struct frame
*f
));
249 static void x_update_begin
P_ ((struct frame
*));
250 static void x_update_window_begin
P_ ((struct window
*));
251 static void x_after_update_window_line
P_ ((struct glyph_row
*));
252 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
253 enum scroll_bar_part
*,
254 Lisp_Object
*, Lisp_Object
*,
257 static int is_emacs_window
P_ ((WindowPtr
));
259 static void XSetFont
P_ ((Display
*, GC
, XFontStruct
*));
261 /* Defined in macmenu.h. */
262 extern void menubar_selection_callback (FRAME_PTR
, int);
264 #define GC_FORE_COLOR(gc) (&(gc)->fore_color)
265 #define GC_BACK_COLOR(gc) (&(gc)->back_color)
266 #define GC_FONT(gc) ((gc)->xgcv.font)
267 #define GC_CLIP_REGION(gc) ((gc)->clip_region)
268 #define FRAME_NORMAL_GC(f) ((f)->output_data.mac->normal_gc)
270 static RgnHandle saved_port_clip_region
= NULL
;
273 mac_begin_clip (region
)
276 static RgnHandle new_region
= NULL
;
278 if (saved_port_clip_region
== NULL
)
279 saved_port_clip_region
= NewRgn ();
280 if (new_region
== NULL
)
281 new_region
= NewRgn ();
285 GetClip (saved_port_clip_region
);
286 SectRgn (saved_port_clip_region
, region
, new_region
);
287 SetClip (new_region
);
292 mac_end_clip (region
)
296 SetClip (saved_port_clip_region
);
300 /* X display function emulation */
303 XFreePixmap (display
, pixmap
)
304 Display
*display
; /* not used */
307 DisposeGWorld (pixmap
);
311 /* Mac version of XDrawLine. */
314 mac_draw_line (f
, gc
, x1
, y1
, x2
, y2
)
319 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
321 RGBForeColor (GC_FORE_COLOR (gc
));
323 mac_begin_clip (GC_CLIP_REGION (gc
));
326 mac_end_clip (GC_CLIP_REGION (gc
));
330 mac_draw_line_to_pixmap (display
, p
, gc
, x1
, y1
, x2
, y2
)
339 GetGWorld (&old_port
, &old_gdh
);
342 RGBForeColor (GC_FORE_COLOR (gc
));
344 LockPixels (GetGWorldPixMap (p
));
347 UnlockPixels (GetGWorldPixMap (p
));
349 SetGWorld (old_port
, old_gdh
);
354 mac_erase_rectangle (f
, gc
, x
, y
, width
, height
)
358 unsigned int width
, height
;
362 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
364 RGBBackColor (GC_BACK_COLOR (gc
));
365 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
367 mac_begin_clip (GC_CLIP_REGION (gc
));
369 mac_end_clip (GC_CLIP_REGION (gc
));
371 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
375 /* Mac version of XClearArea. */
378 mac_clear_area (f
, x
, y
, width
, height
)
381 unsigned int width
, height
;
383 mac_erase_rectangle (f
, FRAME_NORMAL_GC (f
), x
, y
, width
, height
);
386 /* Mac version of XClearWindow. */
392 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
394 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
396 #if TARGET_API_MAC_CARBON
400 GetWindowPortBounds (FRAME_MAC_WINDOW (f
), &r
);
403 #else /* not TARGET_API_MAC_CARBON */
404 EraseRect (&(FRAME_MAC_WINDOW (f
)->portRect
));
405 #endif /* not TARGET_API_MAC_CARBON */
409 /* Mac replacement for XCopyArea. */
412 mac_draw_bitmap (f
, gc
, x
, y
, width
, height
, bits
, overlay_p
)
415 int x
, y
, width
, height
;
416 unsigned short *bits
;
422 bitmap
.rowBytes
= sizeof(unsigned short);
423 bitmap
.baseAddr
= (char *)bits
;
424 SetRect (&(bitmap
.bounds
), 0, 0, width
, height
);
426 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
428 RGBForeColor (GC_FORE_COLOR (gc
));
429 RGBBackColor (GC_BACK_COLOR (gc
));
430 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
432 mac_begin_clip (GC_CLIP_REGION (gc
));
433 #if TARGET_API_MAC_CARBON
439 CopyBits (&bitmap
, GetPortBitMapForCopyBits (port
),
440 &(bitmap
.bounds
), &r
, overlay_p
? srcOr
: srcCopy
, 0);
441 UnlockPortBits (port
);
443 #else /* not TARGET_API_MAC_CARBON */
444 CopyBits (&bitmap
, &(FRAME_MAC_WINDOW (f
)->portBits
), &(bitmap
.bounds
), &r
,
445 overlay_p
? srcOr
: srcCopy
, 0);
446 #endif /* not TARGET_API_MAC_CARBON */
447 mac_end_clip (GC_CLIP_REGION (gc
));
449 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
453 /* Mac replacement for XCreateBitmapFromBitmapData. */
456 mac_create_bitmap_from_bitmap_data (bitmap
, bits
, w
, h
)
461 static unsigned char swap_nibble
[16]
462 = { 0x0, 0x8, 0x4, 0xc, /* 0000 1000 0100 1100 */
463 0x2, 0xa, 0x6, 0xe, /* 0010 1010 0110 1110 */
464 0x1, 0x9, 0x5, 0xd, /* 0001 1001 0101 1101 */
465 0x3, 0xb, 0x7, 0xf }; /* 0011 1011 0111 1111 */
469 w1
= (w
+ 7) / 8; /* nb of 8bits elt in X bitmap */
470 bitmap
->rowBytes
= ((w
+ 15) / 16) * 2; /* nb of 16bits elt in Mac bitmap */
471 bitmap
->baseAddr
= xmalloc (bitmap
->rowBytes
* h
);
472 bzero (bitmap
->baseAddr
, bitmap
->rowBytes
* h
);
473 for (i
= 0; i
< h
; i
++)
475 p
= bitmap
->baseAddr
+ i
* bitmap
->rowBytes
;
476 for (j
= 0; j
< w1
; j
++)
478 /* Bitswap XBM bytes to match how Mac does things. */
479 unsigned char c
= *bits
++;
480 *p
++ = (unsigned char)((swap_nibble
[c
& 0xf] << 4)
481 | (swap_nibble
[(c
>>4) & 0xf]));;
485 SetRect (&(bitmap
->bounds
), 0, 0, w
, h
);
490 mac_free_bitmap (bitmap
)
493 xfree (bitmap
->baseAddr
);
498 XCreatePixmap (display
, w
, width
, height
, depth
)
499 Display
*display
; /* not used */
501 unsigned int width
, height
;
508 SetPortWindowPort (w
);
510 SetRect (&r
, 0, 0, width
, height
);
511 err
= NewGWorld (&pixmap
, depth
, &r
, NULL
, NULL
, 0);
519 XCreatePixmapFromBitmapData (display
, w
, data
, width
, height
, fg
, bg
, depth
)
520 Display
*display
; /* not used */
523 unsigned int width
, height
;
524 unsigned long fg
, bg
;
531 static GC gc
= NULL
; /* not reentrant */
534 gc
= XCreateGC (display
, w
, 0, NULL
);
536 pixmap
= XCreatePixmap (display
, w
, width
, height
, depth
);
540 GetGWorld (&old_port
, &old_gdh
);
541 SetGWorld (pixmap
, NULL
);
542 mac_create_bitmap_from_bitmap_data (&bitmap
, data
, width
, height
);
543 XSetForeground (display
, gc
, fg
);
544 XSetBackground (display
, gc
, bg
);
545 RGBForeColor (GC_FORE_COLOR (gc
));
546 RGBBackColor (GC_BACK_COLOR (gc
));
547 LockPixels (GetGWorldPixMap (pixmap
));
548 #if TARGET_API_MAC_CARBON
549 CopyBits (&bitmap
, GetPortBitMapForCopyBits (pixmap
),
550 &bitmap
.bounds
, &bitmap
.bounds
, srcCopy
, 0);
551 #else /* not TARGET_API_MAC_CARBON */
552 CopyBits (&bitmap
, &(((GrafPtr
)pixmap
)->portBits
),
553 &bitmap
.bounds
, &bitmap
.bounds
, srcCopy
, 0);
554 #endif /* not TARGET_API_MAC_CARBON */
555 UnlockPixels (GetGWorldPixMap (pixmap
));
556 SetGWorld (old_port
, old_gdh
);
557 mac_free_bitmap (&bitmap
);
563 /* Mac replacement for XFillRectangle. */
566 mac_fill_rectangle (f
, gc
, x
, y
, width
, height
)
570 unsigned int width
, height
;
574 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
576 RGBForeColor (GC_FORE_COLOR (gc
));
577 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
579 mac_begin_clip (GC_CLIP_REGION (gc
));
580 PaintRect (&r
); /* using foreground color of gc */
581 mac_end_clip (GC_CLIP_REGION (gc
));
585 /* Mac replacement for XDrawRectangle: dest is a window. */
588 mac_draw_rectangle (f
, gc
, x
, y
, width
, height
)
592 unsigned int width
, height
;
596 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
598 RGBForeColor (GC_FORE_COLOR (gc
));
599 SetRect (&r
, x
, y
, x
+ width
+ 1, y
+ height
+ 1);
601 mac_begin_clip (GC_CLIP_REGION (gc
));
602 FrameRect (&r
); /* using foreground color of gc */
603 mac_end_clip (GC_CLIP_REGION (gc
));
609 atsu_get_text_layout_with_text_ptr (text
, text_length
, style
, text_layout
)
610 ConstUniCharArrayPtr text
;
611 UniCharCount text_length
;
613 ATSUTextLayout
*text_layout
;
616 static ATSUTextLayout saved_text_layout
= NULL
; /* not reentrant */
618 if (saved_text_layout
== NULL
)
620 UniCharCount lengths
[] = {kATSUToTextEnd
};
621 ATSUAttributeTag tags
[] = {kATSULineLayoutOptionsTag
};
622 ByteCount sizes
[] = {sizeof (ATSLineLayoutOptions
)};
623 static ATSLineLayoutOptions line_layout
=
624 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
625 kATSLineDisableAllLayoutOperations
| kATSLineUseDeviceMetrics
627 kATSLineIsDisplayOnly
| kATSLineFractDisable
630 ATSUAttributeValuePtr values
[] = {&line_layout
};
632 err
= ATSUCreateTextLayoutWithTextPtr (text
,
633 kATSUFromTextBeginning
,
639 err
= ATSUSetLayoutControls (saved_text_layout
,
640 sizeof (tags
) / sizeof (tags
[0]),
641 tags
, sizes
, values
);
642 /* XXX: Should we do this? */
644 err
= ATSUSetTransientFontMatching (saved_text_layout
, true);
648 err
= ATSUSetRunStyle (saved_text_layout
, style
,
649 kATSUFromTextBeginning
, kATSUToTextEnd
);
651 err
= ATSUSetTextPointerLocation (saved_text_layout
, text
,
652 kATSUFromTextBeginning
,
658 *text_layout
= saved_text_layout
;
665 mac_invert_rectangle (f
, x
, y
, width
, height
)
668 unsigned int width
, height
;
672 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
674 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
681 mac_draw_string_common (f
, gc
, x
, y
, buf
, nchars
, mode
, bytes_per_char
)
686 int nchars
, mode
, bytes_per_char
;
688 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
689 UInt32 textFlags
, savedFlags
;
690 if (!NILP(Vmac_use_core_graphics
)) {
691 textFlags
= kQDUseCGTextRendering
;
692 savedFlags
= SwapQDTextFlags(textFlags
);
696 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
698 RGBForeColor (GC_FORE_COLOR (gc
));
700 RGBBackColor (GC_BACK_COLOR (gc
));
703 if (GC_FONT (gc
)->mac_style
)
706 ATSUTextLayout text_layout
;
708 xassert (bytes_per_char
== 2);
710 #ifndef WORDS_BIG_ENDIAN
713 UniChar
*text
= (UniChar
*)buf
;
715 for (i
= 0; i
< nchars
; i
++)
716 text
[i
] = EndianU16_BtoN (text
[i
]);
719 err
= atsu_get_text_layout_with_text_ptr ((ConstUniCharArrayPtr
)buf
,
721 GC_FONT (gc
)->mac_style
,
726 if (NILP (Vmac_use_core_graphics
))
729 mac_begin_clip (GC_CLIP_REGION (gc
));
731 ATSUDrawText (text_layout
,
732 kATSUFromTextBeginning
, kATSUToTextEnd
,
733 kATSUUseGrafPortPenLoc
, kATSUUseGrafPortPenLoc
);
734 mac_end_clip (GC_CLIP_REGION (gc
));
740 CGContextRef context
;
741 float port_height
= FRAME_PIXEL_HEIGHT (f
);
742 ATSUAttributeTag tags
[] = {kATSUCGContextTag
};
743 ByteCount sizes
[] = {sizeof (CGContextRef
)};
744 ATSUAttributeValuePtr values
[] = {&context
};
747 QDBeginCGContext (port
, &context
);
748 if (gc
->n_clip_rects
)
750 CGContextTranslateCTM (context
, 0, port_height
);
751 CGContextScaleCTM (context
, 1, -1);
752 CGContextClipToRects (context
, gc
->clip_rects
,
754 CGContextScaleCTM (context
, 1, -1);
755 CGContextTranslateCTM (context
, 0, -port_height
);
757 CGContextSetRGBFillColor
759 RED_FROM_ULONG (gc
->xgcv
.foreground
) / 255.0,
760 GREEN_FROM_ULONG (gc
->xgcv
.foreground
) / 255.0,
761 BLUE_FROM_ULONG (gc
->xgcv
.foreground
) / 255.0,
763 err
= ATSUSetLayoutControls (text_layout
,
764 sizeof (tags
) / sizeof (tags
[0]),
765 tags
, sizes
, values
);
767 ATSUDrawText (text_layout
,
768 kATSUFromTextBeginning
, kATSUToTextEnd
,
769 Long2Fix (x
), Long2Fix (port_height
- y
));
770 CGContextSynchronize (context
);
771 QDEndCGContext (port
, &context
);
773 /* This doesn't work on Mac OS X 10.1. */
774 ATSUClearLayoutControls (text_layout
,
775 sizeof (tags
) / sizeof (tags
[0]),
778 ATSUSetLayoutControls (text_layout
,
779 sizeof (tags
) / sizeof (tags
[0]),
780 tags
, sizes
, values
);
789 TextFont (GC_FONT (gc
)->mac_fontnum
);
790 TextSize (GC_FONT (gc
)->mac_fontsize
);
791 TextFace (GC_FONT (gc
)->mac_fontface
);
794 mac_begin_clip (GC_CLIP_REGION (gc
));
796 DrawText (buf
, 0, nchars
* bytes_per_char
);
797 mac_end_clip (GC_CLIP_REGION (gc
));
803 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
804 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
805 if (!NILP(Vmac_use_core_graphics
))
806 SwapQDTextFlags(savedFlags
);
811 /* Mac replacement for XDrawString. */
814 mac_draw_string (f
, gc
, x
, y
, buf
, nchars
)
821 mac_draw_string_common (f
, gc
, x
, y
, buf
, nchars
, srcOr
, 1);
825 /* Mac replacement for XDrawString16. */
828 mac_draw_string_16 (f
, gc
, x
, y
, buf
, nchars
)
835 mac_draw_string_common (f
, gc
, x
, y
, (char *) buf
, nchars
, srcOr
, 2);
839 /* Mac replacement for XDrawImageString. */
842 mac_draw_image_string (f
, gc
, x
, y
, buf
, nchars
)
849 mac_draw_string_common (f
, gc
, x
, y
, buf
, nchars
, srcCopy
, 1);
853 /* Mac replacement for XDrawString16. */
856 mac_draw_image_string_16 (f
, gc
, x
, y
, buf
, nchars
)
863 mac_draw_string_common (f
, gc
, x
, y
, (char *) buf
, nchars
, srcCopy
, 2);
867 #if USE_CG_TEXT_DRAWING
868 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
871 mac_draw_string_cg (f
, gc
, x
, y
, buf
, nchars
)
879 float port_height
, gx
, gy
;
881 CGContextRef context
;
885 if (NILP (Vmac_use_core_graphics
) || GC_FONT (gc
)->cg_font
== NULL
)
888 port
= GetWindowPort (FRAME_MAC_WINDOW (f
));
889 port_height
= FRAME_PIXEL_HEIGHT (f
);
891 gy
= port_height
- y
;
892 glyphs
= (CGGlyph
*)buf
;
893 advances
= xmalloc (sizeof (CGSize
) * nchars
);
894 for (i
= 0; i
< nchars
; i
++)
896 advances
[i
].width
= x_per_char_metric (GC_FONT (gc
), buf
)->width
;
897 advances
[i
].height
= 0;
898 glyphs
[i
] = GC_FONT (gc
)->cg_glyphs
[buf
->byte2
];
902 QDBeginCGContext (port
, &context
);
903 if (gc
->n_clip_rects
)
905 CGContextTranslateCTM (context
, 0, port_height
);
906 CGContextScaleCTM (context
, 1, -1);
907 CGContextClipToRects (context
, gc
->clip_rects
, gc
->n_clip_rects
);
908 CGContextScaleCTM (context
, 1, -1);
909 CGContextTranslateCTM (context
, 0, -port_height
);
911 CGContextSetRGBFillColor (context
,
912 RED_FROM_ULONG (gc
->xgcv
.foreground
) / 255.0,
913 GREEN_FROM_ULONG (gc
->xgcv
.foreground
) / 255.0,
914 BLUE_FROM_ULONG (gc
->xgcv
.foreground
) / 255.0,
916 CGContextSetFont (context
, GC_FONT (gc
)->cg_font
);
917 CGContextSetFontSize (context
, GC_FONT (gc
)->mac_fontsize
);
918 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
919 CGContextSetTextPosition (context
, gx
, gy
);
920 CGContextShowGlyphsWithAdvances (context
, glyphs
, advances
, nchars
);
922 for (i
= 0; i
< nchars
; i
++)
924 CGContextShowGlyphsAtPoint (context
, gx
, gy
, glyphs
+ i
, 1);
925 gx
+= advances
[i
].width
;
928 CGContextSynchronize (context
);
929 QDEndCGContext (port
, &context
);
938 /* Mac replacement for XCopyArea: dest must be window. */
941 mac_copy_area (src
, f
, gc
, src_x
, src_y
, width
, height
, dest_x
, dest_y
)
946 unsigned int width
, height
;
951 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
953 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
954 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
956 ForeColor (blackColor
);
957 BackColor (whiteColor
);
959 mac_begin_clip (GC_CLIP_REGION (gc
));
960 LockPixels (GetGWorldPixMap (src
));
961 #if TARGET_API_MAC_CARBON
967 CopyBits (GetPortBitMapForCopyBits (src
),
968 GetPortBitMapForCopyBits (port
),
969 &src_r
, &dest_r
, srcCopy
, 0);
970 UnlockPortBits (port
);
972 #else /* not TARGET_API_MAC_CARBON */
973 CopyBits (&(((GrafPtr
)src
)->portBits
), &(FRAME_MAC_WINDOW (f
)->portBits
),
974 &src_r
, &dest_r
, srcCopy
, 0);
975 #endif /* not TARGET_API_MAC_CARBON */
976 UnlockPixels (GetGWorldPixMap (src
));
977 mac_end_clip (GC_CLIP_REGION (gc
));
979 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
984 mac_copy_area_with_mask (src
, mask
, f
, gc
, src_x
, src_y
,
985 width
, height
, dest_x
, dest_y
)
990 unsigned int width
, height
;
995 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
997 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
998 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1000 ForeColor (blackColor
);
1001 BackColor (whiteColor
);
1003 mac_begin_clip (GC_CLIP_REGION (gc
));
1004 LockPixels (GetGWorldPixMap (src
));
1005 LockPixels (GetGWorldPixMap (mask
));
1006 #if TARGET_API_MAC_CARBON
1011 LockPortBits (port
);
1012 CopyMask (GetPortBitMapForCopyBits (src
), GetPortBitMapForCopyBits (mask
),
1013 GetPortBitMapForCopyBits (port
),
1014 &src_r
, &src_r
, &dest_r
);
1015 UnlockPortBits (port
);
1017 #else /* not TARGET_API_MAC_CARBON */
1018 CopyMask (&(((GrafPtr
)src
)->portBits
), &(((GrafPtr
)mask
)->portBits
),
1019 &(FRAME_MAC_WINDOW (f
)->portBits
), &src_r
, &src_r
, &dest_r
);
1020 #endif /* not TARGET_API_MAC_CARBON */
1021 UnlockPixels (GetGWorldPixMap (mask
));
1022 UnlockPixels (GetGWorldPixMap (src
));
1023 mac_end_clip (GC_CLIP_REGION (gc
));
1025 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1029 /* Mac replacement for XCopyArea: used only for scrolling. */
1032 mac_scroll_area (f
, gc
, src_x
, src_y
, width
, height
, dest_x
, dest_y
)
1036 unsigned int width
, height
;
1039 #if TARGET_API_MAC_CARBON
1041 RgnHandle dummy
= NewRgn (); /* For avoiding update events. */
1043 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1044 ScrollWindowRect (FRAME_MAC_WINDOW (f
),
1045 &src_r
, dest_x
- src_x
, dest_y
- src_y
,
1046 kScrollWindowNoOptions
, dummy
);
1048 #else /* not TARGET_API_MAC_CARBON */
1050 WindowPtr w
= FRAME_MAC_WINDOW (f
);
1054 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1055 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1057 /* In Color QuickDraw, set ForeColor and BackColor as follows to avoid
1058 color mapping in CopyBits. Otherwise, it will be slow. */
1059 ForeColor (blackColor
);
1060 BackColor (whiteColor
);
1061 mac_begin_clip (GC_CLIP_REGION (gc
));
1062 CopyBits (&(w
->portBits
), &(w
->portBits
), &src_r
, &dest_r
, srcCopy
, 0);
1063 mac_end_clip (GC_CLIP_REGION (gc
));
1065 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1066 #endif /* not TARGET_API_MAC_CARBON */
1070 /* Mac replacement for XChangeGC. */
1073 XChangeGC (display
, gc
, mask
, xgcv
)
1079 if (mask
& GCForeground
)
1080 XSetForeground (display
, gc
, xgcv
->foreground
);
1081 if (mask
& GCBackground
)
1082 XSetBackground (display
, gc
, xgcv
->background
);
1084 XSetFont (display
, gc
, xgcv
->font
);
1088 /* Mac replacement for XCreateGC. */
1091 XCreateGC (display
, window
, mask
, xgcv
)
1097 GC gc
= xmalloc (sizeof (*gc
));
1101 bzero (gc
, sizeof (*gc
));
1102 XChangeGC (display
, gc
, mask
, xgcv
);
1109 /* Used in xfaces.c. */
1112 XFreeGC (display
, gc
)
1116 if (gc
->clip_region
)
1117 DisposeRgn (gc
->clip_region
);
1122 /* Mac replacement for XGetGCValues. */
1125 XGetGCValues (display
, gc
, mask
, xgcv
)
1131 if (mask
& GCForeground
)
1132 xgcv
->foreground
= gc
->xgcv
.foreground
;
1133 if (mask
& GCBackground
)
1134 xgcv
->background
= gc
->xgcv
.background
;
1136 xgcv
->font
= gc
->xgcv
.font
;
1140 /* Mac replacement for XSetForeground. */
1143 XSetForeground (display
, gc
, color
)
1146 unsigned long color
;
1148 if (gc
->xgcv
.foreground
!= color
)
1150 gc
->xgcv
.foreground
= color
;
1151 gc
->fore_color
.red
= RED16_FROM_ULONG (color
);
1152 gc
->fore_color
.green
= GREEN16_FROM_ULONG (color
);
1153 gc
->fore_color
.blue
= BLUE16_FROM_ULONG (color
);
1158 /* Mac replacement for XSetBackground. */
1161 XSetBackground (display
, gc
, color
)
1164 unsigned long color
;
1166 if (gc
->xgcv
.background
!= color
)
1168 gc
->xgcv
.background
= color
;
1169 gc
->back_color
.red
= RED16_FROM_ULONG (color
);
1170 gc
->back_color
.green
= GREEN16_FROM_ULONG (color
);
1171 gc
->back_color
.blue
= BLUE16_FROM_ULONG (color
);
1176 /* Mac replacement for XSetFont. */
1179 XSetFont (display
, gc
, font
)
1184 gc
->xgcv
.font
= font
;
1188 /* Mac replacement for XSetClipRectangles. */
1191 mac_set_clip_rectangles (display
, gc
, rectangles
, n
)
1199 if (n
< 0 || n
> MAX_CLIP_RECTS
)
1203 if (gc
->clip_region
)
1205 DisposeRgn (gc
->clip_region
);
1206 gc
->clip_region
= NULL
;
1211 if (gc
->clip_region
== NULL
)
1212 gc
->clip_region
= NewRgn ();
1213 RectRgn (gc
->clip_region
, rectangles
);
1216 RgnHandle region
= NewRgn ();
1218 for (i
= 1; i
< n
; i
++)
1220 RectRgn (region
, rectangles
+ i
);
1221 UnionRgn (gc
->clip_region
, region
, gc
->clip_region
);
1223 DisposeRgn (region
);
1226 #if defined (MAC_OSX) && USE_ATSUI
1227 gc
->n_clip_rects
= n
;
1229 for (i
= 0; i
< n
; i
++)
1231 Rect
*rect
= rectangles
+ i
;
1233 gc
->clip_rects
[i
] = CGRectMake (rect
->left
, rect
->top
,
1234 rect
->right
- rect
->left
,
1235 rect
->bottom
- rect
->top
);
1241 /* Mac replacement for XSetClipMask. */
1244 mac_reset_clip_rectangles (display
, gc
)
1248 mac_set_clip_rectangles (display
, gc
, NULL
, 0);
1252 /* Mac replacement for XSetWindowBackground. */
1255 XSetWindowBackground (display
, w
, color
)
1258 unsigned long color
;
1260 #if !TARGET_API_MAC_CARBON
1261 AuxWinHandle aw_handle
;
1262 CTabHandle ctab_handle
;
1263 ColorSpecPtr ct_table
;
1268 bg_color
.red
= RED16_FROM_ULONG (color
);
1269 bg_color
.green
= GREEN16_FROM_ULONG (color
);
1270 bg_color
.blue
= BLUE16_FROM_ULONG (color
);
1272 #if TARGET_API_MAC_CARBON
1273 SetWindowContentColor (w
, &bg_color
);
1275 if (GetAuxWin (w
, &aw_handle
))
1277 ctab_handle
= (*aw_handle
)->awCTable
;
1278 HandToHand ((Handle
*) &ctab_handle
);
1279 ct_table
= (*ctab_handle
)->ctTable
;
1280 ct_size
= (*ctab_handle
)->ctSize
;
1281 while (ct_size
> -1)
1283 if (ct_table
->value
== 0)
1285 ct_table
->rgb
= bg_color
;
1286 CTabChanged (ctab_handle
);
1287 SetWinColor (w
, (WCTabHandle
) ctab_handle
);
1295 /* x_sync is a no-op on Mac. */
1303 /* Flush display of frame F, or of all frames if F is null. */
1309 #if TARGET_API_MAC_CARBON
1312 QDFlushPortBuffer (GetWindowPort (FRAME_MAC_WINDOW (f
)), NULL
);
1314 QDFlushPortBuffer (GetQDGlobalsThePort (), NULL
);
1320 /* Remove calls to XFlush by defining XFlush to an empty replacement.
1321 Calls to XFlush should be unnecessary because the X output buffer
1322 is flushed automatically as needed by calls to XPending,
1323 XNextEvent, or XWindowEvent according to the XFlush man page.
1324 XTread_socket calls XPending. Removing XFlush improves
1327 #define XFlush(DISPLAY) (void) 0
1330 /* Return the struct mac_display_info corresponding to DPY. There's
1333 struct mac_display_info
*
1334 mac_display_info_for_display (dpy
)
1337 return &one_mac_display_info
;
1342 /***********************************************************************
1343 Starting and ending an update
1344 ***********************************************************************/
1346 /* Start an update of frame F. This function is installed as a hook
1347 for update_begin, i.e. it is called when update_begin is called.
1348 This function is called prior to calls to x_update_window_begin for
1349 each window being updated. */
1355 #if TARGET_API_MAC_CARBON
1356 /* During update of a frame, availability of input events is
1357 periodically checked with ReceiveNextEvent if
1358 redisplay-dont-pause is nil. That normally flushes window buffer
1359 changes for every check, and thus screen update looks waving even
1360 if no input is available. So we disable screen updates during
1361 update of a frame. */
1363 DisableScreenUpdates ();
1369 /* Start update of window W. Set the global variable updated_window
1370 to the window being updated and set output_cursor to the cursor
1374 x_update_window_begin (w
)
1377 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1378 struct mac_display_info
*display_info
= FRAME_MAC_DISPLAY_INFO (f
);
1381 set_output_cursor (&w
->cursor
);
1385 if (f
== display_info
->mouse_face_mouse_frame
)
1387 /* Don't do highlighting for mouse motion during the update. */
1388 display_info
->mouse_face_defer
= 1;
1390 /* If F needs to be redrawn, simply forget about any prior mouse
1392 if (FRAME_GARBAGED_P (f
))
1393 display_info
->mouse_face_window
= Qnil
;
1395 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
1396 their mouse_face_p flag set, which means that they are always
1397 unequal to rows in a desired matrix which never have that
1398 flag set. So, rows containing mouse-face glyphs are never
1399 scrolled, and we don't have to switch the mouse highlight off
1400 here to prevent it from being scrolled. */
1402 /* Can we tell that this update does not affect the window
1403 where the mouse highlight is? If so, no need to turn off.
1404 Likewise, don't do anything if the frame is garbaged;
1405 in that case, the frame's current matrix that we would use
1406 is all wrong, and we will redisplay that line anyway. */
1407 if (!NILP (display_info
->mouse_face_window
)
1408 && w
== XWINDOW (display_info
->mouse_face_window
))
1412 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
1413 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
1416 if (i
< w
->desired_matrix
->nrows
)
1417 clear_mouse_face (display_info
);
1426 /* Draw a vertical window border from (x,y0) to (x,y1) */
1429 mac_draw_vertical_window_border (w
, x
, y0
, y1
)
1433 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1436 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
1438 XSetForeground (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->normal_gc
,
1441 mac_draw_line (f
, f
->output_data
.mac
->normal_gc
, x
, y0
, x
, y1
);
1444 /* End update of window W (which is equal to updated_window).
1446 Draw vertical borders between horizontally adjacent windows, and
1447 display W's cursor if CURSOR_ON_P is non-zero.
1449 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
1450 glyphs in mouse-face were overwritten. In that case we have to
1451 make sure that the mouse-highlight is properly redrawn.
1453 W may be a menu bar pseudo-window in case we don't have X toolkit
1454 support. Such windows don't have a cursor, so don't display it
1458 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
1460 int cursor_on_p
, mouse_face_overwritten_p
;
1462 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (XFRAME (w
->frame
));
1464 if (!w
->pseudo_window_p
)
1469 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
1471 output_cursor
.x
, output_cursor
.y
);
1473 if (draw_window_fringes (w
, 1))
1474 x_draw_vertical_border (w
);
1479 /* If a row with mouse-face was overwritten, arrange for
1480 XTframe_up_to_date to redisplay the mouse highlight. */
1481 if (mouse_face_overwritten_p
)
1483 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
1484 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
1485 dpyinfo
->mouse_face_window
= Qnil
;
1488 updated_window
= NULL
;
1492 /* End update of frame F. This function is installed as a hook in
1499 /* Mouse highlight may be displayed again. */
1500 FRAME_MAC_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
1503 #if TARGET_API_MAC_CARBON
1504 EnableScreenUpdates ();
1506 XFlush (FRAME_MAC_DISPLAY (f
));
1511 /* This function is called from various places in xdisp.c whenever a
1512 complete update has been performed. The global variable
1513 updated_window is not available here. */
1516 XTframe_up_to_date (f
)
1519 if (FRAME_MAC_P (f
))
1521 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
1523 if (dpyinfo
->mouse_face_deferred_gc
1524 || f
== dpyinfo
->mouse_face_mouse_frame
)
1527 if (dpyinfo
->mouse_face_mouse_frame
)
1528 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
1529 dpyinfo
->mouse_face_mouse_x
,
1530 dpyinfo
->mouse_face_mouse_y
);
1531 dpyinfo
->mouse_face_deferred_gc
= 0;
1538 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
1539 arrow bitmaps, or clear the fringes if no bitmaps are required
1540 before DESIRED_ROW is made current. The window being updated is
1541 found in updated_window. This function is called from
1542 update_window_line only if it is known that there are differences
1543 between bitmaps to be drawn between current row and DESIRED_ROW. */
1546 x_after_update_window_line (desired_row
)
1547 struct glyph_row
*desired_row
;
1549 struct window
*w
= updated_window
;
1555 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
1556 desired_row
->redraw_fringe_bitmaps_p
= 1;
1558 /* When a window has disappeared, make sure that no rest of
1559 full-width rows stays visible in the internal border. Could
1560 check here if updated_window is the leftmost/rightmost window,
1561 but I guess it's not worth doing since vertically split windows
1562 are almost never used, internal border is rarely set, and the
1563 overhead is very small. */
1564 if (windows_or_buffers_changed
1565 && desired_row
->full_width_p
1566 && (f
= XFRAME (w
->frame
),
1567 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
1569 && (height
= desired_row
->visible_height
,
1572 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
1574 /* Internal border is drawn below the tool bar. */
1575 if (WINDOWP (f
->tool_bar_window
)
1576 && w
== XWINDOW (f
->tool_bar_window
))
1580 mac_clear_area (f
, 0, y
, width
, height
);
1581 mac_clear_area (f
, FRAME_PIXEL_WIDTH (f
) - width
, y
, width
, height
);
1587 /* Draw the bitmap WHICH in one of the left or right fringes of
1588 window W. ROW is the glyph row for which to display the bitmap; it
1589 determines the vertical position at which the bitmap has to be
1593 x_draw_fringe_bitmap (w
, row
, p
)
1595 struct glyph_row
*row
;
1596 struct draw_fringe_bitmap_params
*p
;
1598 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1599 Display
*display
= FRAME_MAC_DISPLAY (f
);
1600 struct face
*face
= p
->face
;
1603 /* Must clip because of partially visible lines. */
1604 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
1607 /* Adjust position of "bottom aligned" bitmap on partially
1608 visible last row. */
1610 int oldVH
= row
->visible_height
;
1611 row
->visible_height
= p
->h
;
1612 row
->y
-= rowY
- p
->y
;
1613 x_clip_to_row (w
, row
, -1, face
->gc
);
1615 row
->visible_height
= oldVH
;
1618 x_clip_to_row (w
, row
, -1, face
->gc
);
1620 if (p
->bx
>= 0 && !p
->overlay_p
)
1622 #if 0 /* MAC_TODO: stipple */
1623 /* In case the same realized face is used for fringes and
1624 for something displayed in the text (e.g. face `region' on
1625 mono-displays, the fill style may have been changed to
1626 FillSolid in x_draw_glyph_string_background. */
1628 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
1630 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
1633 mac_erase_rectangle (f
, face
->gc
, p
->bx
, p
->by
, p
->nx
, p
->ny
);
1635 #if 0 /* MAC_TODO: stipple */
1637 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
1643 unsigned short *bits
= p
->bits
+ p
->dh
;
1646 XGetGCValues (display
, face
->gc
, GCForeground
, &gcv
);
1647 XSetForeground (display
, face
->gc
,
1649 ? (p
->overlay_p
? face
->background
1650 : f
->output_data
.mac
->cursor_pixel
)
1651 : face
->foreground
));
1652 mac_draw_bitmap (f
, face
->gc
, p
->x
, p
->y
,
1653 p
->wd
, p
->h
, bits
, p
->overlay_p
);
1654 XSetForeground (display
, face
->gc
, gcv
.foreground
);
1657 mac_reset_clip_rectangles (display
, face
->gc
);
1662 /* This is called when starting Emacs and when restarting after
1663 suspend. When starting Emacs, no window is mapped. And nothing
1664 must be done to Emacs's own window if it is suspended (though that
1668 XTset_terminal_modes ()
1672 /* This is called when exiting or suspending Emacs. Exiting will make
1673 the windows go away, and suspending requires no action. */
1676 XTreset_terminal_modes ()
1682 /***********************************************************************
1684 ***********************************************************************/
1686 /* Function prototypes of this page. */
1688 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1689 static int mac_encode_char
P_ ((int, XChar2b
*, struct font_info
*, int *));
1692 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1693 is not contained in the font. */
1695 static INLINE XCharStruct
*
1696 x_per_char_metric (font
, char2b
)
1700 /* The result metric information. */
1701 XCharStruct
*pcm
= NULL
;
1703 xassert (font
&& char2b
);
1706 if (font
->mac_style
)
1708 if (char2b
->byte1
>= font
->min_byte1
1709 && char2b
->byte1
<= font
->max_byte1
1710 && char2b
->byte2
>= font
->min_char_or_byte2
1711 && char2b
->byte2
<= font
->max_char_or_byte2
)
1713 pcm
= (font
->per_char
1714 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1715 * (char2b
->byte1
- font
->min_byte1
))
1716 + (char2b
->byte2
- font
->min_char_or_byte2
));
1719 if (pcm
&& !pcm
->valid_p
)
1722 ATSUTextLayout text_layout
;
1725 ATSTrapezoid glyph_bounds
;
1728 c
= (char2b
->byte1
<< 8) + char2b
->byte2
;
1730 err
= atsu_get_text_layout_with_text_ptr (&c
, 1,
1734 err
= ATSUMeasureTextImage (text_layout
,
1735 kATSUFromTextBeginning
, kATSUToTextEnd
,
1736 0, 0, &char_bounds
);
1739 err
= ATSUGetGlyphBounds (text_layout
, 0, 0,
1740 kATSUFromTextBeginning
, kATSUToTextEnd
,
1741 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1742 kATSUseFractionalOrigins
,
1744 kATSUseDeviceOrigins
,
1746 1, &glyph_bounds
, NULL
);
1752 xassert (glyph_bounds
.lowerRight
.x
- glyph_bounds
.lowerLeft
.x
1753 == glyph_bounds
.upperRight
.x
- glyph_bounds
.upperLeft
.x
);
1755 char_width
= Fix2Long (glyph_bounds
.upperRight
.x
1756 - glyph_bounds
.upperLeft
.x
);
1757 STORE_XCHARSTRUCT (*pcm
, char_width
, char_bounds
);
1764 if (font
->per_char
!= NULL
)
1766 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1768 /* min_char_or_byte2 specifies the linear character index
1769 corresponding to the first element of the per_char array,
1770 max_char_or_byte2 is the index of the last character. A
1771 character with non-zero CHAR2B->byte1 is not in the font.
1772 A character with byte2 less than min_char_or_byte2 or
1773 greater max_char_or_byte2 is not in the font. */
1774 if (char2b
->byte1
== 0
1775 && char2b
->byte2
>= font
->min_char_or_byte2
1776 && char2b
->byte2
<= font
->max_char_or_byte2
)
1777 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1781 /* If either min_byte1 or max_byte1 are nonzero, both
1782 min_char_or_byte2 and max_char_or_byte2 are less than
1783 256, and the 2-byte character index values corresponding
1784 to the per_char array element N (counting from 0) are:
1786 byte1 = N/D + min_byte1
1787 byte2 = N\D + min_char_or_byte2
1791 D = max_char_or_byte2 - min_char_or_byte2 + 1
1792 / = integer division
1793 \ = integer modulus */
1794 if (char2b
->byte1
>= font
->min_byte1
1795 && char2b
->byte1
<= font
->max_byte1
1796 && char2b
->byte2
>= font
->min_char_or_byte2
1797 && char2b
->byte2
<= font
->max_char_or_byte2
)
1799 pcm
= (font
->per_char
1800 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1801 * (char2b
->byte1
- font
->min_byte1
))
1802 + (char2b
->byte2
- font
->min_char_or_byte2
));
1808 /* If the per_char pointer is null, all glyphs between the first
1809 and last character indexes inclusive have the same
1810 information, as given by both min_bounds and max_bounds. */
1811 if (char2b
->byte2
>= font
->min_char_or_byte2
1812 && char2b
->byte2
<= font
->max_char_or_byte2
)
1813 pcm
= &font
->max_bounds
;
1819 return ((pcm
== NULL
1820 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1827 static XCharStruct
*
1828 mac_per_char_metric (font
, char2b
, font_type
)
1833 return x_per_char_metric (font
, char2b
);
1837 Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1838 the two-byte form of C. Encoding is returned in *CHAR2B. */
1841 mac_encode_char (c
, char2b
, font_info
, two_byte_p
)
1844 struct font_info
*font_info
;
1847 int charset
= CHAR_CHARSET (c
);
1848 XFontStruct
*font
= font_info
->font
;
1850 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1851 This may be either a program in a special encoder language or a
1853 if (font_info
->font_encoder
)
1855 /* It's a program. */
1856 struct ccl_program
*ccl
= font_info
->font_encoder
;
1858 check_ccl_update (ccl
);
1859 if (CHARSET_DIMENSION (charset
) == 1)
1861 ccl
->reg
[0] = charset
;
1862 ccl
->reg
[1] = char2b
->byte2
;
1867 ccl
->reg
[0] = charset
;
1868 ccl
->reg
[1] = char2b
->byte1
;
1869 ccl
->reg
[2] = char2b
->byte2
;
1872 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1874 /* We assume that MSBs are appropriately set/reset by CCL
1876 if (font
->max_byte1
== 0) /* 1-byte font */
1877 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1879 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1881 else if (font_info
->encoding
[charset
])
1883 /* Fixed encoding scheme. See fontset.h for the meaning of the
1884 encoding numbers. */
1885 int enc
= font_info
->encoding
[charset
];
1887 if ((enc
== 1 || enc
== 2)
1888 && CHARSET_DIMENSION (charset
) == 2)
1889 char2b
->byte1
|= 0x80;
1891 if (enc
== 1 || enc
== 3)
1892 char2b
->byte2
|= 0x80;
1898 ENCODE_SJIS (char2b
->byte1
, char2b
->byte2
, sjis1
, sjis2
);
1899 char2b
->byte1
= sjis1
;
1900 char2b
->byte2
= sjis2
;
1905 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1907 return FONT_TYPE_UNKNOWN
;
1912 /***********************************************************************
1914 ***********************************************************************/
1918 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
1919 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
1920 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
1922 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
1923 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
1924 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
1925 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
1926 static void mac_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
1927 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
1928 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
1929 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
1930 /*static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap,
1931 unsigned long *, double, int));*/
1932 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
1933 double, int, unsigned long));
1934 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
1935 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
1936 static void x_draw_image_relief
P_ ((struct glyph_string
*));
1937 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
1938 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
1939 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
1941 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
1942 int, int, int, int, int, int,
1944 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
1945 int, int, int, Rect
*));
1948 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
1952 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
1957 struct glyph_string
*s
;
1959 if (s
->font
== FRAME_FONT (s
->f
)
1960 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
1961 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
1963 s
->gc
= s
->f
->output_data
.mac
->cursor_gc
;
1966 /* Cursor on non-default face: must merge. */
1970 xgcv
.background
= s
->f
->output_data
.mac
->cursor_pixel
;
1971 xgcv
.foreground
= s
->face
->background
;
1973 /* If the glyph would be invisible, try a different foreground. */
1974 if (xgcv
.foreground
== xgcv
.background
)
1975 xgcv
.foreground
= s
->face
->foreground
;
1976 if (xgcv
.foreground
== xgcv
.background
)
1977 xgcv
.foreground
= s
->f
->output_data
.mac
->cursor_foreground_pixel
;
1978 if (xgcv
.foreground
== xgcv
.background
)
1979 xgcv
.foreground
= s
->face
->foreground
;
1981 /* Make sure the cursor is distinct from text in this face. */
1982 if (xgcv
.background
== s
->face
->background
1983 && xgcv
.foreground
== s
->face
->foreground
)
1985 xgcv
.background
= s
->face
->foreground
;
1986 xgcv
.foreground
= s
->face
->background
;
1989 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1990 xgcv
.font
= s
->font
;
1991 mask
= GCForeground
| GCBackground
| GCFont
;
1993 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1994 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1997 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1998 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2000 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2005 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2008 x_set_mouse_face_gc (s
)
2009 struct glyph_string
*s
;
2014 /* What face has to be used last for the mouse face? */
2015 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2016 face
= FACE_FROM_ID (s
->f
, face_id
);
2018 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2020 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2021 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2023 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2024 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2025 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2027 /* If font in this face is same as S->font, use it. */
2028 if (s
->font
== s
->face
->font
)
2029 s
->gc
= s
->face
->gc
;
2032 /* Otherwise construct scratch_cursor_gc with values from FACE
2037 xgcv
.background
= s
->face
->background
;
2038 xgcv
.foreground
= s
->face
->foreground
;
2039 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2040 xgcv
.font
= s
->font
;
2041 mask
= GCForeground
| GCBackground
| GCFont
;
2043 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2044 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2047 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2048 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2050 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2053 xassert (s
->gc
!= 0);
2057 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2058 Faces to use in the mode line have already been computed when the
2059 matrix was built, so there isn't much to do, here. */
2062 x_set_mode_line_face_gc (s
)
2063 struct glyph_string
*s
;
2065 s
->gc
= s
->face
->gc
;
2069 /* Set S->gc of glyph string S for drawing that glyph string. Set
2070 S->stippled_p to a non-zero value if the face of S has a stipple
2074 x_set_glyph_string_gc (s
)
2075 struct glyph_string
*s
;
2077 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2079 if (s
->hl
== DRAW_NORMAL_TEXT
)
2081 s
->gc
= s
->face
->gc
;
2082 s
->stippled_p
= s
->face
->stipple
!= 0;
2084 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2086 x_set_mode_line_face_gc (s
);
2087 s
->stippled_p
= s
->face
->stipple
!= 0;
2089 else if (s
->hl
== DRAW_CURSOR
)
2091 x_set_cursor_gc (s
);
2094 else if (s
->hl
== DRAW_MOUSE_FACE
)
2096 x_set_mouse_face_gc (s
);
2097 s
->stippled_p
= s
->face
->stipple
!= 0;
2099 else if (s
->hl
== DRAW_IMAGE_RAISED
2100 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2102 s
->gc
= s
->face
->gc
;
2103 s
->stippled_p
= s
->face
->stipple
!= 0;
2107 s
->gc
= s
->face
->gc
;
2108 s
->stippled_p
= s
->face
->stipple
!= 0;
2111 /* GC must have been set. */
2112 xassert (s
->gc
!= 0);
2116 /* Set clipping for output of glyph string S. S may be part of a mode
2117 line or menu if we don't have X toolkit support. */
2120 x_set_glyph_string_clipping (s
)
2121 struct glyph_string
*s
;
2123 Rect rects
[MAX_CLIP_RECTS
];
2126 n
= get_glyph_string_clip_rects (s
, rects
, MAX_CLIP_RECTS
);
2127 mac_set_clip_rectangles (s
->display
, s
->gc
, rects
, n
);
2132 Compute left and right overhang of glyph string S. If S is a glyph
2133 string for a composition, assume overhangs don't exist. */
2136 mac_compute_glyph_string_overhangs (s
)
2137 struct glyph_string
*s
;
2140 && s
->first_glyph
->type
== CHAR_GLYPH
)
2143 MacFontStruct
*font
= s
->font
;
2146 if (font
->mac_style
)
2149 ATSUTextLayout text_layout
;
2153 SetRect (&r
, 0, 0, 0, 0);
2154 buf
= xmalloc (sizeof (UniChar
) * s
->nchars
);
2157 for (i
= 0; i
< s
->nchars
; i
++)
2158 buf
[i
] = (s
->char2b
[i
].byte1
<< 8) + s
->char2b
[i
].byte2
;
2160 err
= atsu_get_text_layout_with_text_ptr (buf
, s
->nchars
,
2164 err
= ATSUMeasureTextImage (text_layout
,
2165 kATSUFromTextBeginning
,
2174 TextFont (font
->mac_fontnum
);
2175 TextSize (font
->mac_fontsize
);
2176 TextFace (font
->mac_fontface
);
2179 QDTextBounds (s
->nchars
* 2, (char *)s
->char2b
, &r
);
2183 char *buf
= xmalloc (s
->nchars
);
2186 SetRect (&r
, 0, 0, 0, 0);
2189 for (i
= 0; i
< s
->nchars
; ++i
)
2190 buf
[i
] = s
->char2b
[i
].byte2
;
2191 QDTextBounds (s
->nchars
, buf
, &r
);
2199 s
->right_overhang
= r
.right
> s
->width
? r
.right
- s
->width
: 0;
2200 s
->left_overhang
= r
.left
< 0 ? -r
.left
: 0;
2205 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
2208 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
2209 struct glyph_string
*s
;
2212 mac_erase_rectangle (s
->f
, s
->gc
, x
, y
, w
, h
);
2216 /* We prefer not to use XDrawImageString (srcCopy text transfer mode)
2217 on Mac OS X because:
2218 - Screen is double-buffered. (In srcCopy mode, a text is drawn
2219 into an offscreen graphics world first. So performance gain
2220 cannot be expected.)
2221 - It lowers rendering quality.
2222 - Some fonts leave garbage on cursor movement. */
2224 /* Draw the background of glyph_string S. If S->background_filled_p
2225 is non-zero don't draw it. FORCE_P non-zero means draw the
2226 background even if it wouldn't be drawn normally. This is used
2227 when a string preceding S draws into the background of S, or S
2228 contains the first component of a composition. */
2231 x_draw_glyph_string_background (s
, force_p
)
2232 struct glyph_string
*s
;
2235 /* Nothing to do if background has already been drawn or if it
2236 shouldn't be drawn in the first place. */
2237 if (!s
->background_filled_p
)
2239 int box_line_width
= max (s
->face
->box_line_width
, 0);
2241 #if 0 /* MAC_TODO: stipple */
2244 /* Fill background with a stipple pattern. */
2245 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2246 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
2247 s
->y
+ box_line_width
,
2248 s
->background_width
,
2249 s
->height
- 2 * box_line_width
);
2250 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2251 s
->background_filled_p
= 1;
2255 #if defined (MAC_OS8) && !USE_ATSUI
2256 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
2257 || s
->font_not_found_p
2258 || s
->extends_to_end_of_line_p
2262 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
2263 s
->background_width
,
2264 s
->height
- 2 * box_line_width
);
2265 s
->background_filled_p
= 1;
2271 /* Draw the foreground of glyph string S. */
2274 x_draw_glyph_string_foreground (s
)
2275 struct glyph_string
*s
;
2279 /* If first glyph of S has a left box line, start drawing the text
2280 of S to the right of that box line. */
2281 if (s
->face
->box
!= FACE_NO_BOX
2282 && s
->first_glyph
->left_box_line_p
)
2283 x
= s
->x
+ abs (s
->face
->box_line_width
);
2287 /* Draw characters of S as rectangles if S's font could not be
2289 if (s
->font_not_found_p
)
2291 for (i
= 0; i
< s
->nchars
; ++i
)
2293 struct glyph
*g
= s
->first_glyph
+ i
;
2294 mac_draw_rectangle (s
->f
, s
->gc
, x
, s
->y
,
2295 g
->pixel_width
- 1, s
->height
- 1);
2296 x
+= g
->pixel_width
;
2301 char *char1b
= (char *) s
->char2b
;
2302 int boff
= s
->font_info
->baseline_offset
;
2304 if (s
->font_info
->vertical_centering
)
2305 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
2307 /* If we can use 8-bit functions, condense S->char2b. */
2310 && GC_FONT (s
->gc
)->mac_style
== NULL
2313 for (i
= 0; i
< s
->nchars
; ++i
)
2314 char1b
[i
] = s
->char2b
[i
].byte2
;
2316 #if defined (MAC_OS8) && !USE_ATSUI
2317 /* Draw text with XDrawString if background has already been
2318 filled. Otherwise, use XDrawImageString. (Note that
2319 XDrawImageString is usually faster than XDrawString.) Always
2320 use XDrawImageString when drawing the cursor so that there is
2321 no chance that characters under a box cursor are invisible. */
2323 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
2326 /* Draw characters with 16-bit or 8-bit functions. */
2329 || GC_FONT (s
->gc
)->mac_style
2332 #if USE_CG_TEXT_DRAWING
2334 && mac_draw_string_cg (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2335 s
->char2b
, s
->nchars
))
2339 mac_draw_string_16 (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2340 s
->char2b
, s
->nchars
);
2342 mac_draw_string (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2345 #if defined (MAC_OS8) && !USE_ATSUI
2349 mac_draw_image_string_16 (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2350 s
->char2b
, s
->nchars
);
2352 mac_draw_image_string (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2359 /* Draw the foreground of composite glyph string S. */
2362 x_draw_composite_glyph_string_foreground (s
)
2363 struct glyph_string
*s
;
2367 /* If first glyph of S has a left box line, start drawing the text
2368 of S to the right of that box line. */
2369 if (s
->face
->box
!= FACE_NO_BOX
2370 && s
->first_glyph
->left_box_line_p
)
2371 x
= s
->x
+ abs (s
->face
->box_line_width
);
2375 /* S is a glyph string for a composition. S->gidx is the index of
2376 the first character drawn for glyphs of this composition.
2377 S->gidx == 0 means we are drawing the very first character of
2378 this composition. */
2380 /* Draw a rectangle for the composition if the font for the very
2381 first character of the composition could not be loaded. */
2382 if (s
->font_not_found_p
)
2385 mac_draw_rectangle (s
->f
, s
->gc
, x
, s
->y
,
2386 s
->width
- 1, s
->height
- 1);
2390 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
2391 mac_draw_string_16 (s
->f
, s
->gc
,
2392 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
2393 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
2399 #ifdef USE_X_TOOLKIT
2401 static struct frame
*x_frame_of_widget
P_ ((Widget
));
2404 /* Return the frame on which widget WIDGET is used.. Abort if frame
2405 cannot be determined. */
2407 static struct frame
*
2408 x_frame_of_widget (widget
)
2411 struct x_display_info
*dpyinfo
;
2415 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
2417 /* Find the top-level shell of the widget. Note that this function
2418 can be called when the widget is not yet realized, so XtWindow
2419 (widget) == 0. That's the reason we can't simply use
2420 x_any_window_to_frame. */
2421 while (!XtIsTopLevelShell (widget
))
2422 widget
= XtParent (widget
);
2424 /* Look for a frame with that top-level widget. Allocate the color
2425 on that frame to get the right gamma correction value. */
2426 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
2427 if (GC_FRAMEP (XCAR (tail
))
2428 && (f
= XFRAME (XCAR (tail
)),
2429 (f
->output_data
.nothing
!= 1
2430 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
2431 && f
->output_data
.x
->widget
== widget
)
2438 /* Allocate the color COLOR->pixel on the screen and display of
2439 widget WIDGET in colormap CMAP. If an exact match cannot be
2440 allocated, try the nearest color available. Value is non-zero
2441 if successful. This is called from lwlib. */
2444 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
2449 struct frame
*f
= x_frame_of_widget (widget
);
2450 return x_alloc_nearest_color (f
, cmap
, color
);
2454 #endif /* USE_X_TOOLKIT */
2456 #if 0 /* MAC_TODO */
2458 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
2459 CMAP. If an exact match can't be allocated, try the nearest color
2460 available. Value is non-zero if successful. Set *COLOR to the
2464 x_alloc_nearest_color (f
, cmap
, color
)
2469 Display
*display
= FRAME_X_DISPLAY (f
);
2470 Screen
*screen
= FRAME_X_SCREEN (f
);
2473 gamma_correct (f
, color
);
2474 rc
= XAllocColor (display
, cmap
, color
);
2477 /* If we got to this point, the colormap is full, so we're going
2478 to try to get the next closest color. The algorithm used is
2479 a least-squares matching, which is what X uses for closest
2480 color matching with StaticColor visuals. */
2482 unsigned long nearest_delta
= ~0;
2483 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
2484 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
2486 for (i
= 0; i
< ncells
; ++i
)
2488 XQueryColors (display
, cmap
, cells
, ncells
);
2490 for (nearest
= i
= 0; i
< ncells
; ++i
)
2492 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
2493 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
2494 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
2495 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
2497 if (delta
< nearest_delta
)
2500 nearest_delta
= delta
;
2504 color
->red
= cells
[nearest
].red
;
2505 color
->green
= cells
[nearest
].green
;
2506 color
->blue
= cells
[nearest
].blue
;
2507 rc
= XAllocColor (display
, cmap
, color
);
2510 #ifdef DEBUG_X_COLORS
2512 register_color (color
->pixel
);
2513 #endif /* DEBUG_X_COLORS */
2519 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
2520 It's necessary to do this instead of just using PIXEL directly to
2521 get color reference counts right. */
2524 x_copy_color (f
, pixel
)
2526 unsigned long pixel
;
2530 color
.pixel
= pixel
;
2532 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2533 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2535 #ifdef DEBUG_X_COLORS
2536 register_color (pixel
);
2542 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
2543 It's necessary to do this instead of just using PIXEL directly to
2544 get color reference counts right. */
2547 x_copy_dpy_color (dpy
, cmap
, pixel
)
2550 unsigned long pixel
;
2554 color
.pixel
= pixel
;
2556 XQueryColor (dpy
, cmap
, &color
);
2557 XAllocColor (dpy
, cmap
, &color
);
2559 #ifdef DEBUG_X_COLORS
2560 register_color (pixel
);
2565 #endif /* MAC_TODO */
2568 /* Brightness beyond which a color won't have its highlight brightness
2571 Nominally, highlight colors for `3d' faces are calculated by
2572 brightening an object's color by a constant scale factor, but this
2573 doesn't yield good results for dark colors, so for colors who's
2574 brightness is less than this value (on a scale of 0-255) have to
2575 use an additional additive factor.
2577 The value here is set so that the default menu-bar/mode-line color
2578 (grey75) will not have its highlights changed at all. */
2579 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
2582 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
2583 or DELTA. Try a color with RGB values multiplied by FACTOR first.
2584 If this produces the same color as COLOR, try a color where all RGB
2585 values have DELTA added. Return the allocated color in *COLOR.
2586 DISPLAY is the X display, CMAP is the colormap to operate on.
2587 Value is non-zero if successful. */
2590 mac_alloc_lighter_color (f
, color
, factor
, delta
)
2592 unsigned long *color
;
2599 /* On Mac, RGB values are 0-255, not 0-65535, so scale delta. */
2602 /* Change RGB values by specified FACTOR. Avoid overflow! */
2603 xassert (factor
>= 0);
2604 new = RGB_TO_ULONG (min (0xff, (int) (factor
* RED_FROM_ULONG (*color
))),
2605 min (0xff, (int) (factor
* GREEN_FROM_ULONG (*color
))),
2606 min (0xff, (int) (factor
* BLUE_FROM_ULONG (*color
))));
2608 /* Calculate brightness of COLOR. */
2609 bright
= (2 * RED_FROM_ULONG (*color
) + 3 * GREEN_FROM_ULONG (*color
)
2610 + BLUE_FROM_ULONG (*color
)) / 6;
2612 /* We only boost colors that are darker than
2613 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
2614 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
2615 /* Make an additive adjustment to NEW, because it's dark enough so
2616 that scaling by FACTOR alone isn't enough. */
2618 /* How far below the limit this color is (0 - 1, 1 being darker). */
2619 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
2620 /* The additive adjustment. */
2621 int min_delta
= delta
* dimness
* factor
/ 2;
2624 new = RGB_TO_ULONG (max (0, min (0xff, (int) (RED_FROM_ULONG (*color
)) - min_delta
)),
2625 max (0, min (0xff, (int) (GREEN_FROM_ULONG (*color
)) - min_delta
)),
2626 max (0, min (0xff, (int) (BLUE_FROM_ULONG (*color
)) - min_delta
)));
2628 new = RGB_TO_ULONG (max (0, min (0xff, (int) (min_delta
+ RED_FROM_ULONG (*color
)))),
2629 max (0, min (0xff, (int) (min_delta
+ GREEN_FROM_ULONG (*color
)))),
2630 max (0, min (0xff, (int) (min_delta
+ BLUE_FROM_ULONG (*color
)))));
2634 new = RGB_TO_ULONG (max (0, min (0xff, (int) (delta
+ RED_FROM_ULONG (*color
)))),
2635 max (0, min (0xff, (int) (delta
+ GREEN_FROM_ULONG (*color
)))),
2636 max (0, min (0xff, (int) (delta
+ BLUE_FROM_ULONG (*color
)))));
2638 /* MAC_TODO: Map to palette and retry with delta if same? */
2639 /* MAC_TODO: Free colors (if using palette)? */
2650 /* Set up the foreground color for drawing relief lines of glyph
2651 string S. RELIEF is a pointer to a struct relief containing the GC
2652 with which lines will be drawn. Use a color that is FACTOR or
2653 DELTA lighter or darker than the relief's background which is found
2654 in S->f->output_data.x->relief_background. If such a color cannot
2655 be allocated, use DEFAULT_PIXEL, instead. */
2658 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
2660 struct relief
*relief
;
2663 unsigned long default_pixel
;
2666 struct mac_output
*di
= f
->output_data
.mac
;
2667 unsigned long mask
= GCForeground
;
2668 unsigned long pixel
;
2669 unsigned long background
= di
->relief_background
;
2670 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
2672 /* MAC_TODO: Free colors (if using palette)? */
2674 /* Allocate new color. */
2675 xgcv
.foreground
= default_pixel
;
2677 if (dpyinfo
->n_planes
!= 1
2678 && mac_alloc_lighter_color (f
, &pixel
, factor
, delta
))
2680 relief
->allocated_p
= 1;
2681 xgcv
.foreground
= relief
->pixel
= pixel
;
2684 if (relief
->gc
== 0)
2686 #if 0 /* MAC_TODO: stipple */
2687 xgcv
.stipple
= dpyinfo
->gray
;
2690 relief
->gc
= XCreateGC (NULL
, FRAME_MAC_WINDOW (f
), mask
, &xgcv
);
2693 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
2697 /* Set up colors for the relief lines around glyph string S. */
2700 x_setup_relief_colors (s
)
2701 struct glyph_string
*s
;
2703 struct mac_output
*di
= s
->f
->output_data
.mac
;
2704 unsigned long color
;
2706 if (s
->face
->use_box_color_for_shadows_p
)
2707 color
= s
->face
->box_color
;
2708 else if (s
->first_glyph
->type
== IMAGE_GLYPH
2710 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
2711 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
2716 /* Get the background color of the face. */
2717 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
2718 color
= xgcv
.background
;
2721 if (di
->white_relief
.gc
== 0
2722 || color
!= di
->relief_background
)
2724 di
->relief_background
= color
;
2725 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
2726 WHITE_PIX_DEFAULT (s
->f
));
2727 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
2728 BLACK_PIX_DEFAULT (s
->f
));
2733 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2734 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2735 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
2736 relief. LEFT_P non-zero means draw a relief on the left side of
2737 the rectangle. RIGHT_P non-zero means draw a relief on the right
2738 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2742 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
2743 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
2745 int left_x
, top_y
, right_x
, bottom_y
, width
;
2746 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
2749 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
2754 gc
= f
->output_data
.mac
->white_relief
.gc
;
2756 gc
= f
->output_data
.mac
->black_relief
.gc
;
2757 mac_set_clip_rectangles (dpy
, gc
, clip_rect
, 1);
2761 for (i
= 0; i
< width
; ++i
)
2762 mac_draw_line (f
, gc
,
2763 left_x
+ i
* left_p
, top_y
+ i
,
2764 right_x
- i
* right_p
, top_y
+ i
);
2768 for (i
= 0; i
< width
; ++i
)
2769 mac_draw_line (f
, gc
,
2770 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
2772 mac_reset_clip_rectangles (dpy
, gc
);
2774 gc
= f
->output_data
.mac
->black_relief
.gc
;
2776 gc
= f
->output_data
.mac
->white_relief
.gc
;
2777 mac_set_clip_rectangles (dpy
, gc
, clip_rect
, 1);
2781 for (i
= 0; i
< width
; ++i
)
2782 mac_draw_line (f
, gc
,
2783 left_x
+ i
* left_p
, bottom_y
- i
,
2784 right_x
- i
* right_p
, bottom_y
- i
);
2788 for (i
= 0; i
< width
; ++i
)
2789 mac_draw_line (f
, gc
,
2790 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
- 1);
2792 mac_reset_clip_rectangles (dpy
, gc
);
2796 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2797 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2798 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2799 left side of the rectangle. RIGHT_P non-zero means draw a line
2800 on the right side of the rectangle. CLIP_RECT is the clipping
2801 rectangle to use when drawing. */
2804 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2805 left_p
, right_p
, clip_rect
)
2806 struct glyph_string
*s
;
2807 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2812 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2813 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2814 mac_set_clip_rectangles (s
->display
, s
->gc
, clip_rect
, 1);
2817 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, top_y
,
2818 right_x
- left_x
+ 1, width
);
2822 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, top_y
,
2823 width
, bottom_y
- top_y
+ 1);
2826 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, bottom_y
- width
+ 1,
2827 right_x
- left_x
+ 1, width
);
2831 mac_fill_rectangle (s
->f
, s
->gc
, right_x
- width
+ 1,
2832 top_y
, width
, bottom_y
- top_y
+ 1);
2834 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2835 mac_reset_clip_rectangles (s
->display
, s
->gc
);
2839 /* Draw a box around glyph string S. */
2842 x_draw_glyph_string_box (s
)
2843 struct glyph_string
*s
;
2845 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2846 int left_p
, right_p
;
2847 struct glyph
*last_glyph
;
2850 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2851 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2852 : window_box_right (s
->w
, s
->area
));
2854 /* The glyph that may have a right box line. */
2855 last_glyph
= (s
->cmp
|| s
->img
2857 : s
->first_glyph
+ s
->nchars
- 1);
2859 width
= abs (s
->face
->box_line_width
);
2860 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2862 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2864 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2866 bottom_y
= top_y
+ s
->height
- 1;
2868 left_p
= (s
->first_glyph
->left_box_line_p
2869 || (s
->hl
== DRAW_MOUSE_FACE
2871 || s
->prev
->hl
!= s
->hl
)));
2872 right_p
= (last_glyph
->right_box_line_p
2873 || (s
->hl
== DRAW_MOUSE_FACE
2875 || s
->next
->hl
!= s
->hl
)));
2877 get_glyph_string_clip_rect (s
, &clip_rect
);
2879 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2880 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2881 left_p
, right_p
, &clip_rect
);
2884 x_setup_relief_colors (s
);
2885 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2886 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2891 /* Draw foreground of image glyph string S. */
2894 x_draw_image_foreground (s
)
2895 struct glyph_string
*s
;
2898 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2900 /* If first glyph of S has a left box line, start drawing it to the
2901 right of that line. */
2902 if (s
->face
->box
!= FACE_NO_BOX
2903 && s
->first_glyph
->left_box_line_p
2905 x
+= abs (s
->face
->box_line_width
);
2907 /* If there is a margin around the image, adjust x- and y-position
2909 if (s
->slice
.x
== 0)
2910 x
+= s
->img
->hmargin
;
2911 if (s
->slice
.y
== 0)
2912 y
+= s
->img
->vmargin
;
2916 x_set_glyph_string_clipping (s
);
2919 mac_copy_area_with_mask (s
->img
->pixmap
, s
->img
->mask
,
2920 s
->f
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
2921 s
->slice
.width
, s
->slice
.height
, x
, y
);
2924 mac_copy_area (s
->img
->pixmap
,
2925 s
->f
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
2926 s
->slice
.width
, s
->slice
.height
, x
, y
);
2928 /* When the image has a mask, we can expect that at
2929 least part of a mouse highlight or a block cursor will
2930 be visible. If the image doesn't have a mask, make
2931 a block cursor visible by drawing a rectangle around
2932 the image. I believe it's looking better if we do
2933 nothing here for mouse-face. */
2934 if (s
->hl
== DRAW_CURSOR
)
2936 int r
= s
->img
->relief
;
2938 mac_draw_rectangle (s
->f
, s
->gc
, x
- r
, y
- r
,
2939 s
->slice
.width
+ r
*2 - 1,
2940 s
->slice
.height
+ r
*2 - 1);
2945 /* Draw a rectangle if image could not be loaded. */
2946 mac_draw_rectangle (s
->f
, s
->gc
, x
, y
,
2947 s
->slice
.width
- 1, s
->slice
.height
- 1);
2951 /* Draw a relief around the image glyph string S. */
2954 x_draw_image_relief (s
)
2955 struct glyph_string
*s
;
2957 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2960 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2962 /* If first glyph of S has a left box line, start drawing it to the
2963 right of that line. */
2964 if (s
->face
->box
!= FACE_NO_BOX
2965 && s
->first_glyph
->left_box_line_p
2967 x
+= abs (s
->face
->box_line_width
);
2969 /* If there is a margin around the image, adjust x- and y-position
2971 if (s
->slice
.x
== 0)
2972 x
+= s
->img
->hmargin
;
2973 if (s
->slice
.y
== 0)
2974 y
+= s
->img
->vmargin
;
2976 if (s
->hl
== DRAW_IMAGE_SUNKEN
2977 || s
->hl
== DRAW_IMAGE_RAISED
)
2979 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2980 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2984 thick
= abs (s
->img
->relief
);
2985 raised_p
= s
->img
->relief
> 0;
2990 x1
= x
+ s
->slice
.width
+ thick
- 1;
2991 y1
= y
+ s
->slice
.height
+ thick
- 1;
2993 x_setup_relief_colors (s
);
2994 get_glyph_string_clip_rect (s
, &r
);
2995 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
2997 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
2999 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
3004 /* Draw part of the background of glyph string S. X, Y, W, and H
3005 give the rectangle to draw. */
3008 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3009 struct glyph_string
*s
;
3012 #if 0 /* MAC_TODO: stipple */
3015 /* Fill background with a stipple pattern. */
3016 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3017 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3018 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3021 #endif /* MAC_TODO */
3022 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3026 /* Draw image glyph string S.
3029 s->x +-------------------------
3032 | +-------------------------
3035 | | +-------------------
3041 x_draw_image_glyph_string (s
)
3042 struct glyph_string
*s
;
3045 int box_line_hwidth
= abs (s
->face
->box_line_width
);
3046 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
3050 height
= s
->height
- 2 * box_line_vwidth
;
3053 /* Fill background with face under the image. Do it only if row is
3054 taller than image or if image has a clip mask to reduce
3056 s
->stippled_p
= s
->face
->stipple
!= 0;
3057 if (height
> s
->slice
.height
3061 || s
->img
->pixmap
== 0
3062 || s
->width
!= s
->background_width
)
3065 if (s
->first_glyph
->left_box_line_p
3067 x
+= box_line_hwidth
;
3070 if (s
->slice
.y
== 0)
3071 y
+= box_line_vwidth
;
3073 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
3075 s
->background_filled_p
= 1;
3078 /* Draw the foreground. */
3079 x_draw_image_foreground (s
);
3081 /* If we must draw a relief around the image, do it. */
3083 || s
->hl
== DRAW_IMAGE_RAISED
3084 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3085 x_draw_image_relief (s
);
3089 /* Draw stretch glyph string S. */
3092 x_draw_stretch_glyph_string (s
)
3093 struct glyph_string
*s
;
3095 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
3096 s
->stippled_p
= s
->face
->stipple
!= 0;
3098 if (s
->hl
== DRAW_CURSOR
3099 && !x_stretch_cursor_p
)
3101 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
3102 as wide as the stretch glyph. */
3103 int width
= min (FRAME_COLUMN_WIDTH (s
->f
), s
->background_width
);
3106 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
3108 /* Clear rest using the GC of the original non-cursor face. */
3109 if (width
< s
->background_width
)
3111 int x
= s
->x
+ width
, y
= s
->y
;
3112 int w
= s
->background_width
- width
, h
= s
->height
;
3116 if (s
->row
->mouse_face_p
3117 && cursor_in_mouse_face_p (s
->w
))
3119 x_set_mouse_face_gc (s
);
3125 get_glyph_string_clip_rect (s
, &r
);
3126 mac_set_clip_rectangles (s
->display
, gc
, &r
, 1);
3128 #if 0 /* MAC_TODO: stipple */
3129 if (s
->face
->stipple
)
3131 /* Fill background with a stipple pattern. */
3132 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
3133 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3134 XSetFillStyle (s
->display
, gc
, FillSolid
);
3137 #endif /* MAC_TODO */
3138 mac_erase_rectangle (s
->f
, gc
, x
, y
, w
, h
);
3141 else if (!s
->background_filled_p
)
3142 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
3145 s
->background_filled_p
= 1;
3149 /* Draw glyph string S. */
3152 x_draw_glyph_string (s
)
3153 struct glyph_string
*s
;
3155 int relief_drawn_p
= 0;
3157 /* If S draws into the background of its successor that does not
3158 draw a cursor, draw the background of the successor first so that
3159 S can draw into it. This makes S->next use XDrawString instead
3160 of XDrawImageString. */
3161 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
3162 && s
->next
->hl
!= DRAW_CURSOR
)
3164 xassert (s
->next
->img
== NULL
);
3165 x_set_glyph_string_gc (s
->next
);
3166 x_set_glyph_string_clipping (s
->next
);
3167 x_draw_glyph_string_background (s
->next
, 1);
3170 /* Set up S->gc, set clipping and draw S. */
3171 x_set_glyph_string_gc (s
);
3173 /* Draw relief (if any) in advance for char/composition so that the
3174 glyph string can be drawn over it. */
3175 if (!s
->for_overlaps
3176 && s
->face
->box
!= FACE_NO_BOX
3177 && (s
->first_glyph
->type
== CHAR_GLYPH
3178 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
3181 x_set_glyph_string_clipping (s
);
3182 x_draw_glyph_string_background (s
, 1);
3183 x_draw_glyph_string_box (s
);
3184 x_set_glyph_string_clipping (s
);
3188 x_set_glyph_string_clipping (s
);
3190 switch (s
->first_glyph
->type
)
3193 x_draw_image_glyph_string (s
);
3197 x_draw_stretch_glyph_string (s
);
3201 if (s
->for_overlaps
)
3202 s
->background_filled_p
= 1;
3204 x_draw_glyph_string_background (s
, 0);
3205 x_draw_glyph_string_foreground (s
);
3208 case COMPOSITE_GLYPH
:
3209 if (s
->for_overlaps
|| s
->gidx
> 0)
3210 s
->background_filled_p
= 1;
3212 x_draw_glyph_string_background (s
, 1);
3213 x_draw_composite_glyph_string_foreground (s
);
3220 if (!s
->for_overlaps
)
3222 /* Draw underline. */
3223 if (s
->face
->underline_p
)
3225 unsigned long h
= 1;
3226 unsigned long dy
= s
->height
- h
;
3228 if (s
->face
->underline_defaulted_p
)
3229 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3234 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3235 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
3236 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3238 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3242 /* Draw overline. */
3243 if (s
->face
->overline_p
)
3245 unsigned long dy
= 0, h
= 1;
3247 if (s
->face
->overline_color_defaulted_p
)
3248 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3253 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3254 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
3255 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3257 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3261 /* Draw strike-through. */
3262 if (s
->face
->strike_through_p
)
3264 unsigned long h
= 1;
3265 unsigned long dy
= (s
->height
- h
) / 2;
3267 if (s
->face
->strike_through_color_defaulted_p
)
3268 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3273 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3274 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
3275 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3277 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3281 /* Draw relief if not yet drawn. */
3282 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3283 x_draw_glyph_string_box (s
);
3286 /* Reset clipping. */
3287 mac_reset_clip_rectangles (s
->display
, s
->gc
);
3290 /* Shift display to make room for inserted glyphs. */
3293 mac_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
3295 int x
, y
, width
, height
, shift_by
;
3297 mac_scroll_area (f
, f
->output_data
.mac
->normal_gc
,
3298 x
, y
, width
, height
,
3302 /* Delete N glyphs at the nominal cursor position. Not implemented
3313 /* Clear entire frame. If updating_frame is non-null, clear that
3314 frame. Otherwise clear the selected frame. */
3324 f
= SELECTED_FRAME ();
3326 /* Clearing the frame will erase any cursor, so mark them all as no
3328 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3329 output_cursor
.hpos
= output_cursor
.vpos
= 0;
3330 output_cursor
.x
= -1;
3332 /* We don't set the output cursor here because there will always
3333 follow an explicit cursor_to. */
3335 mac_clear_window (f
);
3337 /* We have to clear the scroll bars, too. If we have changed
3338 colors or something like that, then they should be notified. */
3339 x_scroll_bar_clear (f
);
3341 XFlush (FRAME_MAC_DISPLAY (f
));
3347 /* Invert the middle quarter of the frame for .15 sec. */
3349 /* We use the select system call to do the waiting, so we have to make
3350 sure it's available. If it isn't, we just won't do visual bells. */
3352 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3355 /* Subtract the `struct timeval' values X and Y, storing the result in
3356 *RESULT. Return 1 if the difference is negative, otherwise 0. */
3359 timeval_subtract (result
, x
, y
)
3360 struct timeval
*result
, x
, y
;
3362 /* Perform the carry for the later subtraction by updating y. This
3363 is safer because on some systems the tv_sec member is unsigned. */
3364 if (x
.tv_usec
< y
.tv_usec
)
3366 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
3367 y
.tv_usec
-= 1000000 * nsec
;
3371 if (x
.tv_usec
- y
.tv_usec
> 1000000)
3373 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
3374 y
.tv_usec
+= 1000000 * nsec
;
3378 /* Compute the time remaining to wait. tv_usec is certainly
3380 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
3381 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
3383 /* Return indication of whether the result should be considered
3385 return x
.tv_sec
< y
.tv_sec
;
3392 /* Get the height not including a menu bar widget. */
3393 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
3394 /* Height of each line to flash. */
3395 int flash_height
= FRAME_LINE_HEIGHT (f
);
3396 /* These will be the left and right margins of the rectangles. */
3397 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3398 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3402 /* Don't flash the area between a scroll bar and the frame
3403 edge it is next to. */
3404 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
3406 case vertical_scroll_bar_left
:
3407 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3410 case vertical_scroll_bar_right
:
3411 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3418 width
= flash_right
- flash_left
;
3422 /* If window is tall, flash top and bottom line. */
3423 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3425 mac_invert_rectangle (f
, flash_left
,
3426 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3427 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3428 width
, flash_height
);
3429 mac_invert_rectangle (f
, flash_left
,
3430 (height
- flash_height
3431 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3432 width
, flash_height
);
3435 /* If it is short, flash it all. */
3436 mac_invert_rectangle (f
, flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3437 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3442 struct timeval wakeup
;
3444 EMACS_GET_TIME (wakeup
);
3446 /* Compute time to wait until, propagating carry from usecs. */
3447 wakeup
.tv_usec
+= 150000;
3448 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
3449 wakeup
.tv_usec
%= 1000000;
3451 /* Keep waiting until past the time wakeup or any input gets
3453 while (! detect_input_pending ())
3455 struct timeval current
;
3456 struct timeval timeout
;
3458 EMACS_GET_TIME (current
);
3460 /* Break if result would be negative. */
3461 if (timeval_subtract (¤t
, wakeup
, current
))
3464 /* How long `select' should wait. */
3466 timeout
.tv_usec
= 10000;
3468 /* Try to wait that long--but we might wake up sooner. */
3469 select (0, NULL
, NULL
, NULL
, &timeout
);
3473 /* If window is tall, flash top and bottom line. */
3474 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3476 mac_invert_rectangle (f
, flash_left
,
3477 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3478 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3479 width
, flash_height
);
3480 mac_invert_rectangle (f
, flash_left
,
3481 (height
- flash_height
3482 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3483 width
, flash_height
);
3486 /* If it is short, flash it all. */
3487 mac_invert_rectangle (f
, flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3488 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3495 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3498 /* Make audible bell. */
3503 struct frame
*f
= SELECTED_FRAME ();
3505 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3513 XFlush (FRAME_MAC_DISPLAY (f
));
3519 /* Specify how many text lines, from the top of the window,
3520 should be affected by insert-lines and delete-lines operations.
3521 This, and those operations, are used only within an update
3522 that is bounded by calls to x_update_begin and x_update_end. */
3525 XTset_terminal_window (n
)
3528 /* This function intentionally left blank. */
3533 /***********************************************************************
3535 ***********************************************************************/
3537 /* Perform an insert-lines or delete-lines operation, inserting N
3538 lines or deleting -N lines at vertical position VPOS. */
3541 x_ins_del_lines (vpos
, n
)
3548 /* Scroll part of the display as described by RUN. */
3551 x_scroll_run (w
, run
)
3555 struct frame
*f
= XFRAME (w
->frame
);
3556 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3558 /* Get frame-relative bounding box of the text display area of W,
3559 without mode lines. Include in this box the left and right
3561 window_box (w
, -1, &x
, &y
, &width
, &height
);
3563 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3564 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3565 bottom_y
= y
+ height
;
3569 /* Scrolling up. Make sure we don't copy part of the mode
3570 line at the bottom. */
3571 if (from_y
+ run
->height
> bottom_y
)
3572 height
= bottom_y
- from_y
;
3574 height
= run
->height
;
3578 /* Scolling down. Make sure we don't copy over the mode line.
3580 if (to_y
+ run
->height
> bottom_y
)
3581 height
= bottom_y
- to_y
;
3583 height
= run
->height
;
3588 /* Cursor off. Will be switched on again in x_update_window_end. */
3592 mac_scroll_area (f
, f
->output_data
.mac
->normal_gc
,
3602 /***********************************************************************
3604 ***********************************************************************/
3612 ControlRef root_control
;
3615 err
= GetRootControl (FRAME_MAC_WINDOW (f
), &root_control
);
3617 ActivateControl (root_control
);
3619 x_update_cursor (f
, 1);
3623 frame_unhighlight (f
)
3627 ControlRef root_control
;
3630 err
= GetRootControl (FRAME_MAC_WINDOW (f
), &root_control
);
3632 DeactivateControl (root_control
);
3634 x_update_cursor (f
, 1);
3637 /* The focus has changed. Update the frames as necessary to reflect
3638 the new situation. Note that we can't change the selected frame
3639 here, because the Lisp code we are interrupting might become confused.
3640 Each event gets marked with the frame in which it occurred, so the
3641 Lisp code can tell when the switch took place by examining the events. */
3644 x_new_focus_frame (dpyinfo
, frame
)
3645 struct x_display_info
*dpyinfo
;
3646 struct frame
*frame
;
3648 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3650 if (frame
!= dpyinfo
->x_focus_frame
)
3652 /* Set this before calling other routines, so that they see
3653 the correct value of x_focus_frame. */
3654 dpyinfo
->x_focus_frame
= frame
;
3656 if (old_focus
&& old_focus
->auto_lower
)
3657 x_lower_frame (old_focus
);
3660 selected_frame
= frame
;
3661 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
3663 Fselect_window (selected_frame
->selected_window
, Qnil
);
3664 choose_minibuf_frame ();
3667 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3668 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3670 pending_autoraise_frame
= 0;
3673 x_frame_rehighlight (dpyinfo
);
3676 /* Handle FocusIn and FocusOut state changes for FRAME.
3677 If FRAME has focus and there exists more than one frame, puts
3678 a FOCUS_IN_EVENT into *BUFP. */
3681 mac_focus_changed (type
, dpyinfo
, frame
, bufp
)
3683 struct mac_display_info
*dpyinfo
;
3684 struct frame
*frame
;
3685 struct input_event
*bufp
;
3687 if (type
== activeFlag
)
3689 if (dpyinfo
->x_focus_event_frame
!= frame
)
3691 x_new_focus_frame (dpyinfo
, frame
);
3692 dpyinfo
->x_focus_event_frame
= frame
;
3694 /* Don't stop displaying the initial startup message
3695 for a switch-frame event we don't need. */
3696 if (GC_NILP (Vterminal_frame
)
3697 && GC_CONSP (Vframe_list
)
3698 && !GC_NILP (XCDR (Vframe_list
)))
3700 bufp
->kind
= FOCUS_IN_EVENT
;
3701 XSETFRAME (bufp
->frame_or_window
, frame
);
3707 if (dpyinfo
->x_focus_event_frame
== frame
)
3709 dpyinfo
->x_focus_event_frame
= 0;
3710 x_new_focus_frame (dpyinfo
, 0);
3715 /* The focus may have changed. Figure out if it is a real focus change,
3716 by checking both FocusIn/Out and Enter/LeaveNotify events.
3718 Returns FOCUS_IN_EVENT event in *BUFP. */
3721 x_detect_focus_change (dpyinfo
, event
, bufp
)
3722 struct mac_display_info
*dpyinfo
;
3724 struct input_event
*bufp
;
3726 struct frame
*frame
;
3728 frame
= mac_window_to_frame ((WindowPtr
) event
->message
);
3732 /* On Mac, this is only called from focus events, so no switch needed. */
3733 mac_focus_changed ((event
->modifiers
& activeFlag
),
3734 dpyinfo
, frame
, bufp
);
3738 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3741 x_mouse_leave (dpyinfo
)
3742 struct x_display_info
*dpyinfo
;
3744 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3747 /* The focus has changed, or we have redirected a frame's focus to
3748 another frame (this happens when a frame uses a surrogate
3749 mini-buffer frame). Shift the highlight as appropriate.
3751 The FRAME argument doesn't necessarily have anything to do with which
3752 frame is being highlighted or un-highlighted; we only use it to find
3753 the appropriate X display info. */
3756 XTframe_rehighlight (frame
)
3757 struct frame
*frame
;
3759 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3763 x_frame_rehighlight (dpyinfo
)
3764 struct x_display_info
*dpyinfo
;
3766 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3768 if (dpyinfo
->x_focus_frame
)
3770 dpyinfo
->x_highlight_frame
3771 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3772 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3773 : dpyinfo
->x_focus_frame
);
3774 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3776 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
3777 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3781 dpyinfo
->x_highlight_frame
= 0;
3783 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3786 frame_unhighlight (old_highlight
);
3787 if (dpyinfo
->x_highlight_frame
)
3788 frame_highlight (dpyinfo
->x_highlight_frame
);
3794 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3796 #if 0 /* MAC_TODO */
3797 /* Initialize mode_switch_bit and modifier_meaning. */
3799 x_find_modifier_meanings (dpyinfo
)
3800 struct x_display_info
*dpyinfo
;
3802 int min_code
, max_code
;
3805 XModifierKeymap
*mods
;
3807 dpyinfo
->meta_mod_mask
= 0;
3808 dpyinfo
->shift_lock_mask
= 0;
3809 dpyinfo
->alt_mod_mask
= 0;
3810 dpyinfo
->super_mod_mask
= 0;
3811 dpyinfo
->hyper_mod_mask
= 0;
3814 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3816 min_code
= dpyinfo
->display
->min_keycode
;
3817 max_code
= dpyinfo
->display
->max_keycode
;
3820 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3821 min_code
, max_code
- min_code
+ 1,
3823 mods
= XGetModifierMapping (dpyinfo
->display
);
3825 /* Scan the modifier table to see which modifier bits the Meta and
3826 Alt keysyms are on. */
3828 int row
, col
; /* The row and column in the modifier table. */
3830 for (row
= 3; row
< 8; row
++)
3831 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3834 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3836 /* Zeroes are used for filler. Skip them. */
3840 /* Are any of this keycode's keysyms a meta key? */
3844 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3846 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3852 dpyinfo
->meta_mod_mask
|= (1 << row
);
3857 dpyinfo
->alt_mod_mask
|= (1 << row
);
3862 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3867 dpyinfo
->super_mod_mask
|= (1 << row
);
3871 /* Ignore this if it's not on the lock modifier. */
3872 if ((1 << row
) == LockMask
)
3873 dpyinfo
->shift_lock_mask
= LockMask
;
3881 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3882 if (! dpyinfo
->meta_mod_mask
)
3884 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3885 dpyinfo
->alt_mod_mask
= 0;
3888 /* If some keys are both alt and meta,
3889 make them just meta, not alt. */
3890 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3892 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3895 XFree ((char *) syms
);
3896 XFreeModifiermap (mods
);
3899 #endif /* MAC_TODO */
3901 /* Convert between the modifier bits X uses and the modifier bits
3905 x_mac_to_emacs_modifiers (dpyinfo
, state
)
3906 struct x_display_info
*dpyinfo
;
3907 unsigned short state
;
3909 return (((state
& shiftKey
) ? shift_modifier
: 0)
3910 | ((state
& controlKey
) ? ctrl_modifier
: 0)
3911 | ((state
& cmdKey
) ? meta_modifier
: 0)
3912 | ((state
& optionKey
) ? alt_modifier
: 0));
3915 #if 0 /* MAC_TODO */
3916 static unsigned short
3917 x_emacs_to_x_modifiers (dpyinfo
, state
)
3918 struct x_display_info
*dpyinfo
;
3921 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
3922 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
3923 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
3924 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3925 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3926 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
3928 #endif /* MAC_TODO */
3930 /* Convert a keysym to its name. */
3933 x_get_keysym_name (keysym
)
3940 value
= XKeysymToString (keysym
);
3951 /* Function to report a mouse movement to the mainstream Emacs code.
3952 The input handler calls this.
3954 We have received a mouse movement event, which is given in *event.
3955 If the mouse is over a different glyph than it was last time, tell
3956 the mainstream emacs code by setting mouse_moved. If not, ask for
3957 another motion event, so we can check again the next time it moves. */
3959 static Point last_mouse_motion_position
;
3960 static Lisp_Object last_mouse_motion_frame
;
3963 note_mouse_movement (frame
, pos
)
3967 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (frame
);
3968 #if TARGET_API_MAC_CARBON
3972 last_mouse_movement_time
= TickCount () * (1000 / 60); /* to milliseconds */
3973 last_mouse_motion_position
= *pos
;
3974 XSETFRAME (last_mouse_motion_frame
, frame
);
3976 #if TARGET_API_MAC_CARBON
3977 if (!PtInRect (*pos
, GetWindowPortBounds (FRAME_MAC_WINDOW (frame
), &r
)))
3979 if (!PtInRect (*pos
, &FRAME_MAC_WINDOW (frame
)->portRect
))
3982 if (frame
== dpyinfo
->mouse_face_mouse_frame
)
3983 /* This case corresponds to LeaveNotify in X11. */
3985 /* If we move outside the frame, then we're certainly no
3986 longer on any text in the frame. */
3987 clear_mouse_face (dpyinfo
);
3988 dpyinfo
->mouse_face_mouse_frame
= 0;
3989 if (!dpyinfo
->grabbed
)
3990 rif
->define_frame_cursor (frame
,
3991 frame
->output_data
.mac
->nontext_cursor
);
3995 /* Has the mouse moved off the glyph it was on at the last sighting? */
3996 if (frame
!= last_mouse_glyph_frame
3997 || !PtInRect (*pos
, &last_mouse_glyph
))
3999 frame
->mouse_moved
= 1;
4000 last_mouse_scroll_bar
= Qnil
;
4001 note_mouse_highlight (frame
, pos
->h
, pos
->v
);
4002 /* Remember which glyph we're now on. */
4003 remember_mouse_glyph (frame
, pos
->h
, pos
->v
, &last_mouse_glyph
);
4004 last_mouse_glyph_frame
= frame
;
4012 /************************************************************************
4014 ************************************************************************/
4016 /* MAC TODO: This should be called from somewhere (or removed) ++KFS */
4019 redo_mouse_highlight ()
4021 if (!NILP (last_mouse_motion_frame
)
4022 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
4023 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
4024 last_mouse_motion_position
.h
,
4025 last_mouse_motion_position
.v
);
4029 static struct frame
*
4030 mac_focus_frame (dpyinfo
)
4031 struct mac_display_info
*dpyinfo
;
4033 if (dpyinfo
->x_focus_frame
)
4034 return dpyinfo
->x_focus_frame
;
4036 /* Mac version may get events, such as a menu bar click, even when
4037 all the frames are invisible. In this case, we regard the
4038 event came to the selected frame. */
4039 return SELECTED_FRAME ();
4043 /* Return the current position of the mouse.
4044 *FP should be a frame which indicates which display to ask about.
4046 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
4047 and *PART to the frame, window, and scroll bar part that the mouse
4048 is over. Set *X and *Y to the portion and whole of the mouse's
4049 position on the scroll bar.
4051 If the mouse movement started elsewhere, set *FP to the frame the
4052 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
4055 Set *TIME to the server time-stamp for the time at which the mouse
4056 was at this position.
4058 Don't store anything if we don't have a valid set of values to report.
4060 This clears the mouse_moved flag, so we can wait for the next mouse
4064 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
4067 Lisp_Object
*bar_window
;
4068 enum scroll_bar_part
*part
;
4070 unsigned long *time
;
4076 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
4077 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
4080 Lisp_Object frame
, tail
;
4082 /* Clear the mouse-moved flag for every frame on this display. */
4083 FOR_EACH_FRAME (tail
, frame
)
4084 XFRAME (frame
)->mouse_moved
= 0;
4086 last_mouse_scroll_bar
= Qnil
;
4088 if (FRAME_MAC_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
4089 && FRAME_LIVE_P (last_mouse_frame
))
4090 f1
= last_mouse_frame
;
4092 f1
= mac_focus_frame (FRAME_MAC_DISPLAY_INFO (*fp
));
4096 /* Ok, we found a frame. Store all the values.
4097 last_mouse_glyph is a rectangle used to reduce the
4098 generation of mouse events. To not miss any motion
4099 events, we must divide the frame into rectangles of the
4100 size of the smallest character that could be displayed
4101 on it, i.e. into the same rectangles that matrices on
4102 the frame are divided into. */
4105 SetPortWindowPort (FRAME_MAC_WINDOW (f1
));
4106 GetMouse (&mouse_pos
);
4107 remember_mouse_glyph (f1
, mouse_pos
.h
, mouse_pos
.v
,
4109 last_mouse_glyph_frame
= f1
;
4114 XSETINT (*x
, mouse_pos
.h
);
4115 XSETINT (*y
, mouse_pos
.v
);
4116 *time
= last_mouse_movement_time
;
4124 /************************************************************************
4126 ************************************************************************/
4128 #ifdef USE_TOOLKIT_SCROLL_BARS
4130 static pascal void scroll_bar_timer_callback
P_ ((EventLoopTimerRef
, void *));
4131 static OSStatus install_scroll_bar_timer
P_ ((void));
4132 static OSStatus set_scroll_bar_timer
P_ ((EventTimerInterval
));
4133 static int control_part_code_to_scroll_bar_part
P_ ((ControlPartCode
));
4134 static void construct_scroll_bar_click
P_ ((struct scroll_bar
*, int,
4135 struct input_event
*));
4136 static OSErr get_control_part_bounds
P_ ((ControlHandle
, ControlPartCode
,
4138 static void x_scroll_bar_handle_press
P_ ((struct scroll_bar
*,
4140 struct input_event
*));
4141 static void x_scroll_bar_handle_release
P_ ((struct scroll_bar
*,
4142 struct input_event
*));
4143 static void x_scroll_bar_handle_drag
P_ ((WindowPtr
, struct scroll_bar
*,
4144 Point
, struct input_event
*));
4145 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
4148 /* Last scroll bar part sent in x_scroll_bar_handle_*. */
4150 static int last_scroll_bar_part
;
4152 static EventLoopTimerRef scroll_bar_timer
;
4154 static int scroll_bar_timer_event_posted_p
;
4156 #define SCROLL_BAR_FIRST_DELAY 0.5
4157 #define SCROLL_BAR_CONTINUOUS_DELAY (1.0 / 15)
4160 scroll_bar_timer_callback (timer
, data
)
4161 EventLoopTimerRef timer
;
4164 EventRef event
= NULL
;
4167 err
= CreateEvent (NULL
, kEventClassMouse
, kEventMouseMoved
, 0,
4168 kEventAttributeNone
, &event
);
4173 GetMouse (&mouse_pos
);
4174 LocalToGlobal (&mouse_pos
);
4175 err
= SetEventParameter (event
, kEventParamMouseLocation
, typeQDPoint
,
4176 sizeof (Point
), &mouse_pos
);
4180 UInt32 modifiers
= GetCurrentKeyModifiers ();
4182 err
= SetEventParameter (event
, kEventParamKeyModifiers
, typeUInt32
,
4183 sizeof (UInt32
), &modifiers
);
4186 err
= PostEventToQueue (GetCurrentEventQueue (), event
,
4187 kEventPriorityStandard
);
4189 scroll_bar_timer_event_posted_p
= 1;
4192 ReleaseEvent (event
);
4196 install_scroll_bar_timer ()
4198 static EventLoopTimerUPP scroll_bar_timer_callbackUPP
= NULL
;
4200 if (scroll_bar_timer_callbackUPP
== NULL
)
4201 scroll_bar_timer_callbackUPP
=
4202 NewEventLoopTimerUPP (scroll_bar_timer_callback
);
4204 if (scroll_bar_timer
== NULL
)
4205 /* Mac OS X and CarbonLib 1.5 and later allow us to specify
4206 kEventDurationForever as delays. */
4208 InstallEventLoopTimer (GetCurrentEventLoop (),
4209 kEventDurationForever
, kEventDurationForever
,
4210 scroll_bar_timer_callbackUPP
, NULL
,
4215 set_scroll_bar_timer (delay
)
4216 EventTimerInterval delay
;
4218 if (scroll_bar_timer
== NULL
)
4219 install_scroll_bar_timer ();
4221 scroll_bar_timer_event_posted_p
= 0;
4223 return SetEventLoopTimerNextFireTime (scroll_bar_timer
, delay
);
4227 control_part_code_to_scroll_bar_part (part_code
)
4228 ControlPartCode part_code
;
4232 case kControlUpButtonPart
: return scroll_bar_up_arrow
;
4233 case kControlDownButtonPart
: return scroll_bar_down_arrow
;
4234 case kControlPageUpPart
: return scroll_bar_above_handle
;
4235 case kControlPageDownPart
: return scroll_bar_below_handle
;
4236 case kControlIndicatorPart
: return scroll_bar_handle
;
4243 construct_scroll_bar_click (bar
, part
, bufp
)
4244 struct scroll_bar
*bar
;
4246 struct input_event
*bufp
;
4248 bufp
->kind
= SCROLL_BAR_CLICK_EVENT
;
4249 bufp
->frame_or_window
= bar
->window
;
4253 XSETINT (bufp
->x
, 0);
4254 XSETINT (bufp
->y
, 0);
4255 bufp
->modifiers
= 0;
4259 get_control_part_bounds (ch
, part_code
, rect
)
4261 ControlPartCode part_code
;
4264 RgnHandle region
= NewRgn ();
4267 err
= GetControlRegion (ch
, part_code
, region
);
4269 GetRegionBounds (region
, rect
);
4270 DisposeRgn (region
);
4276 x_scroll_bar_handle_press (bar
, part_code
, bufp
)
4277 struct scroll_bar
*bar
;
4278 ControlPartCode part_code
;
4279 struct input_event
*bufp
;
4281 int part
= control_part_code_to_scroll_bar_part (part_code
);
4286 if (part
!= scroll_bar_handle
)
4288 construct_scroll_bar_click (bar
, part
, bufp
);
4289 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), part_code
);
4290 set_scroll_bar_timer (SCROLL_BAR_FIRST_DELAY
);
4293 last_scroll_bar_part
= part
;
4294 bar
->dragging
= Qnil
;
4295 tracked_scroll_bar
= bar
;
4299 x_scroll_bar_handle_release (bar
, bufp
)
4300 struct scroll_bar
*bar
;
4301 struct input_event
*bufp
;
4303 if (last_scroll_bar_part
!= scroll_bar_handle
4304 || !GC_NILP (bar
->dragging
))
4305 construct_scroll_bar_click (bar
, scroll_bar_end_scroll
, bufp
);
4307 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), 0);
4308 set_scroll_bar_timer (kEventDurationForever
);
4310 last_scroll_bar_part
= -1;
4311 bar
->dragging
= Qnil
;
4312 tracked_scroll_bar
= NULL
;
4316 x_scroll_bar_handle_drag (win
, bar
, mouse_pos
, bufp
)
4318 struct scroll_bar
*bar
;
4320 struct input_event
*bufp
;
4322 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4324 if (last_scroll_bar_part
== scroll_bar_handle
)
4329 get_control_part_bounds (SCROLL_BAR_CONTROL_HANDLE (bar
),
4330 kControlIndicatorPart
, &r
);
4332 if (GC_NILP (bar
->dragging
))
4333 XSETINT (bar
->dragging
, mouse_pos
.v
- r
.top
);
4335 top
= mouse_pos
.v
- XINT (bar
->dragging
) - XINT (bar
->track_top
);
4336 top_range
= (XINT (bar
->track_height
) - (r
.bottom
- r
.top
)) *
4337 (1.0 + (float) GetControlViewSize (ch
) / GetControl32BitMaximum (ch
))
4342 if (top
> top_range
)
4345 construct_scroll_bar_click (bar
, scroll_bar_handle
, bufp
);
4346 XSETINT (bufp
->x
, top
);
4347 XSETINT (bufp
->y
, top_range
);
4351 ControlPartCode part_code
;
4352 int unhilite_p
= 0, part
;
4354 if (ch
!= FindControlUnderMouse (mouse_pos
, win
, &part_code
))
4358 part
= control_part_code_to_scroll_bar_part (part_code
);
4360 switch (last_scroll_bar_part
)
4362 case scroll_bar_above_handle
:
4363 case scroll_bar_below_handle
:
4364 if (part
!= scroll_bar_above_handle
4365 && part
!= scroll_bar_below_handle
)
4369 case scroll_bar_up_arrow
:
4370 case scroll_bar_down_arrow
:
4371 if (part
!= scroll_bar_up_arrow
4372 && part
!= scroll_bar_down_arrow
)
4379 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), 0);
4380 else if (part
!= last_scroll_bar_part
4381 || scroll_bar_timer_event_posted_p
)
4383 construct_scroll_bar_click (bar
, part
, bufp
);
4384 last_scroll_bar_part
= part
;
4385 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), part_code
);
4386 set_scroll_bar_timer (SCROLL_BAR_CONTINUOUS_DELAY
);
4391 /* Set the thumb size and position of scroll bar BAR. We are currently
4392 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4395 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4396 struct scroll_bar
*bar
;
4397 int portion
, position
, whole
;
4399 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4401 int value
, viewsize
, maximum
;
4403 if (whole
== 0 || XINT (bar
->track_height
) == 0)
4404 value
= 0, viewsize
= 1, maximum
= 0;
4409 maximum
= max (0, whole
- portion
);
4414 SetControl32BitMinimum (ch
, 0);
4415 SetControl32BitMaximum (ch
, maximum
);
4416 SetControl32BitValue (ch
, value
);
4417 SetControlViewSize (ch
, viewsize
);
4422 #endif /* USE_TOOLKIT_SCROLL_BARS */
4426 /************************************************************************
4427 Scroll bars, general
4428 ************************************************************************/
4430 /* Create a scroll bar and return the scroll bar vector for it. W is
4431 the Emacs window on which to create the scroll bar. TOP, LEFT,
4432 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4435 static struct scroll_bar
*
4436 x_scroll_bar_create (w
, top
, left
, width
, height
, disp_top
, disp_height
)
4438 int top
, left
, width
, height
, disp_top
, disp_height
;
4440 struct frame
*f
= XFRAME (w
->frame
);
4441 struct scroll_bar
*bar
4442 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
4450 r
.right
= left
+ width
;
4451 r
.bottom
= disp_top
+ disp_height
;
4453 #if TARGET_API_MAC_CARBON
4454 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p", width
< disp_height
,
4455 0, 0, 0, kControlScrollBarProc
, (long) bar
);
4457 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p", width
< disp_height
,
4458 0, 0, 0, scrollBarProc
, (long) bar
);
4460 SET_SCROLL_BAR_CONTROL_HANDLE (bar
, ch
);
4462 XSETWINDOW (bar
->window
, w
);
4463 XSETINT (bar
->top
, top
);
4464 XSETINT (bar
->left
, left
);
4465 XSETINT (bar
->width
, width
);
4466 XSETINT (bar
->height
, height
);
4467 XSETINT (bar
->start
, 0);
4468 XSETINT (bar
->end
, 0);
4469 bar
->dragging
= Qnil
;
4470 #ifdef USE_TOOLKIT_SCROLL_BARS
4471 bar
->track_top
= Qnil
;
4472 bar
->track_height
= Qnil
;
4475 /* Add bar to its frame's list of scroll bars. */
4476 bar
->next
= FRAME_SCROLL_BARS (f
);
4478 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4479 if (!NILP (bar
->next
))
4480 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4487 /* Draw BAR's handle in the proper position.
4489 If the handle is already drawn from START to END, don't bother
4490 redrawing it, unless REBUILD is non-zero; in that case, always
4491 redraw it. (REBUILD is handy for drawing the handle after expose
4494 Normally, we want to constrain the start and end of the handle to
4495 fit inside its rectangle, but if the user is dragging the scroll
4496 bar handle, we want to let them drag it down all the way, so that
4497 the bar's top is as far down as it goes; otherwise, there's no way
4498 to move to the very end of the buffer. */
4500 #ifndef USE_TOOLKIT_SCROLL_BARS
4503 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
4504 struct scroll_bar
*bar
;
4508 int dragging
= ! NILP (bar
->dragging
);
4509 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4510 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4511 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
4512 int length
= end
- start
;
4514 /* If the display is already accurate, do nothing. */
4516 && start
== XINT (bar
->start
)
4517 && end
== XINT (bar
->end
))
4522 /* Make sure the values are reasonable, and try to preserve the
4523 distance between start and end. */
4526 else if (start
> top_range
)
4528 end
= start
+ length
;
4532 else if (end
> top_range
&& ! dragging
)
4535 /* Store the adjusted setting in the scroll bar. */
4536 XSETINT (bar
->start
, start
);
4537 XSETINT (bar
->end
, end
);
4539 /* Clip the end position, just for display. */
4540 if (end
> top_range
)
4543 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
4544 top positions, to make sure the handle is always at least that
4545 many pixels tall. */
4546 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4548 SetControlMinimum (ch
, 0);
4549 /* Don't inadvertently activate deactivated scroll bars */
4550 if (GetControlMaximum (ch
) != -1)
4551 SetControlMaximum (ch
, top_range
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
4553 SetControlValue (ch
, start
);
4554 #if TARGET_API_MAC_CARBON
4555 SetControlViewSize (ch
, end
- start
);
4561 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4563 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4567 x_scroll_bar_remove (bar
)
4568 struct scroll_bar
*bar
;
4570 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4574 /* Destroy the Mac scroll bar control */
4575 DisposeControl (SCROLL_BAR_CONTROL_HANDLE (bar
));
4577 /* Disassociate this scroll bar from its window. */
4578 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
4584 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4585 that we are displaying PORTION characters out of a total of WHOLE
4586 characters, starting at POSITION. If WINDOW has no scroll bar,
4590 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
4592 int portion
, whole
, position
;
4594 struct frame
*f
= XFRAME (w
->frame
);
4595 struct scroll_bar
*bar
;
4596 int top
, height
, left
, sb_left
, width
, sb_width
, disp_top
, disp_height
;
4597 int window_y
, window_height
;
4599 /* Get window dimensions. */
4600 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
4602 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
4603 height
= window_height
;
4605 /* Compute the left edge of the scroll bar area. */
4606 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
4608 /* Compute the width of the scroll bar which might be less than
4609 the width of the area reserved for the scroll bar. */
4610 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
4611 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
4615 /* Compute the left edge of the scroll bar. */
4616 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
4619 sb_left
= left
+ width
- sb_width
;
4621 /* Adjustments according to Inside Macintosh to make it look nice */
4623 disp_height
= height
;
4629 else if (disp_top
== FRAME_PIXEL_HEIGHT (f
) - 16)
4635 if (sb_left
+ sb_width
== FRAME_PIXEL_WIDTH (f
))
4638 /* Does the scroll bar exist yet? */
4639 if (NILP (w
->vertical_scroll_bar
))
4642 mac_clear_area (f
, left
, top
, width
, height
);
4644 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
, disp_top
,
4646 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
4650 /* It may just need to be moved and resized. */
4653 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
4654 ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4658 /* If already correctly positioned, do nothing. */
4659 if (!(XINT (bar
->left
) == sb_left
4660 && XINT (bar
->top
) == top
4661 && XINT (bar
->width
) == sb_width
4662 && XINT (bar
->height
) == height
))
4664 /* Since toolkit scroll bars are smaller than the space reserved
4665 for them on the frame, we have to clear "under" them. */
4666 mac_clear_area (f
, left
, top
, width
, height
);
4669 MoveControl (ch
, sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
, disp_top
);
4670 SizeControl (ch
, sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4672 if (sb_width
< disp_height
)
4675 /* Remember new settings. */
4676 XSETINT (bar
->left
, sb_left
);
4677 XSETINT (bar
->top
, top
);
4678 XSETINT (bar
->width
, sb_width
);
4679 XSETINT (bar
->height
, height
);
4680 #ifdef USE_TOOLKIT_SCROLL_BARS
4681 bar
->track_top
= Qnil
;
4682 bar
->track_height
= Qnil
;
4689 #ifdef USE_TOOLKIT_SCROLL_BARS
4690 if (NILP (bar
->track_top
))
4692 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4697 SetControl32BitMinimum (ch
, 0);
4698 SetControl32BitMaximum (ch
, 1);
4699 SetControlViewSize (ch
, 1);
4701 /* Move the scroll bar thumb to the top. */
4702 SetControl32BitValue (ch
, 0);
4703 get_control_part_bounds (ch
, kControlIndicatorPart
, &r0
);
4705 /* Move the scroll bar thumb to the bottom. */
4706 SetControl32BitValue (ch
, 1);
4707 get_control_part_bounds (ch
, kControlIndicatorPart
, &r1
);
4709 UnionRect (&r0
, &r1
, &r0
);
4710 XSETINT (bar
->track_top
, r0
.top
);
4711 XSETINT (bar
->track_height
, r0
.bottom
- r0
.top
);
4716 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4717 #else /* not USE_TOOLKIT_SCROLL_BARS */
4718 /* Set the scroll bar's current state, unless we're currently being
4720 if (NILP (bar
->dragging
))
4722 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
4725 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
4728 int start
= ((double) position
* top_range
) / whole
;
4729 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
4730 x_scroll_bar_set_handle (bar
, start
, end
, 0);
4733 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4737 /* The following three hooks are used when we're doing a thorough
4738 redisplay of the frame. We don't explicitly know which scroll bars
4739 are going to be deleted, because keeping track of when windows go
4740 away is a real pain - "Can you say set-window-configuration, boys
4741 and girls?" Instead, we just assert at the beginning of redisplay
4742 that *all* scroll bars are to be removed, and then save a scroll bar
4743 from the fiery pit when we actually redisplay its window. */
4745 /* Arrange for all scroll bars on FRAME to be removed at the next call
4746 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
4747 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
4750 XTcondemn_scroll_bars (frame
)
4753 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
4754 while (! NILP (FRAME_SCROLL_BARS (frame
)))
4757 bar
= FRAME_SCROLL_BARS (frame
);
4758 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
4759 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
4760 XSCROLL_BAR (bar
)->prev
= Qnil
;
4761 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
4762 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
4763 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
4768 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
4769 Note that WINDOW isn't necessarily condemned at all. */
4772 XTredeem_scroll_bar (window
)
4773 struct window
*window
;
4775 struct scroll_bar
*bar
;
4778 /* We can't redeem this window's scroll bar if it doesn't have one. */
4779 if (NILP (window
->vertical_scroll_bar
))
4782 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
4784 /* Unlink it from the condemned list. */
4785 f
= XFRAME (WINDOW_FRAME (window
));
4786 if (NILP (bar
->prev
))
4788 /* If the prev pointer is nil, it must be the first in one of
4790 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
4791 /* It's not condemned. Everything's fine. */
4793 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
4794 window
->vertical_scroll_bar
))
4795 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
4797 /* If its prev pointer is nil, it must be at the front of
4798 one or the other! */
4802 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
4804 if (! NILP (bar
->next
))
4805 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
4807 bar
->next
= FRAME_SCROLL_BARS (f
);
4809 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4810 if (! NILP (bar
->next
))
4811 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4814 /* Remove all scroll bars on FRAME that haven't been saved since the
4815 last call to `*condemn_scroll_bars_hook'. */
4818 XTjudge_scroll_bars (f
)
4821 Lisp_Object bar
, next
;
4823 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
4825 /* Clear out the condemned list now so we won't try to process any
4826 more events on the hapless scroll bars. */
4827 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
4829 for (; ! NILP (bar
); bar
= next
)
4831 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
4833 x_scroll_bar_remove (b
);
4836 b
->next
= b
->prev
= Qnil
;
4839 /* Now there should be no references to the condemned scroll bars,
4840 and they should get garbage-collected. */
4844 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
4845 is set to something other than NO_EVENT, it is enqueued.
4847 This may be called from a signal handler, so we have to ignore GC
4851 x_scroll_bar_handle_click (bar
, part_code
, er
, bufp
)
4852 struct scroll_bar
*bar
;
4853 ControlPartCode part_code
;
4855 struct input_event
*bufp
;
4857 int win_y
, top_range
;
4859 if (! GC_WINDOWP (bar
->window
))
4862 bufp
->kind
= SCROLL_BAR_CLICK_EVENT
;
4863 bufp
->frame_or_window
= bar
->window
;
4866 bar
->dragging
= Qnil
;
4870 case kControlUpButtonPart
:
4871 bufp
->part
= scroll_bar_up_arrow
;
4873 case kControlDownButtonPart
:
4874 bufp
->part
= scroll_bar_down_arrow
;
4876 case kControlPageUpPart
:
4877 bufp
->part
= scroll_bar_above_handle
;
4879 case kControlPageDownPart
:
4880 bufp
->part
= scroll_bar_below_handle
;
4882 #if TARGET_API_MAC_CARBON
4885 case kControlIndicatorPart
:
4887 if (er
->what
== mouseDown
)
4888 bar
->dragging
= make_number (0);
4889 XSETVECTOR (last_mouse_scroll_bar
, bar
);
4890 bufp
->part
= scroll_bar_handle
;
4894 win_y
= XINT (bufp
->y
) - XINT (bar
->top
);
4895 top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (0/*dummy*/, XINT (bar
->height
));
4897 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
4901 if (! NILP (bar
->dragging
))
4902 win_y
-= XINT (bar
->dragging
);
4906 if (win_y
> top_range
)
4909 XSETINT (bufp
->x
, win_y
);
4910 XSETINT (bufp
->y
, top_range
);
4913 #ifndef USE_TOOLKIT_SCROLL_BARS
4915 /* Handle some mouse motion while someone is dragging the scroll bar.
4917 This may be called from a signal handler, so we have to ignore GC
4921 x_scroll_bar_note_movement (bar
, y_pos
, t
)
4922 struct scroll_bar
*bar
;
4926 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
4928 last_mouse_movement_time
= t
;
4931 XSETVECTOR (last_mouse_scroll_bar
, bar
);
4933 /* If we're dragging the bar, display it. */
4934 if (! GC_NILP (bar
->dragging
))
4936 /* Where should the handle be now? */
4937 int new_start
= y_pos
- 24;
4939 if (new_start
!= XINT (bar
->start
))
4941 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
4943 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
4948 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4950 /* Return information to the user about the current position of the mouse
4951 on the scroll bar. */
4954 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
4956 Lisp_Object
*bar_window
;
4957 enum scroll_bar_part
*part
;
4959 unsigned long *time
;
4961 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
4962 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4963 #if TARGET_API_MAC_CARBON
4964 WindowPtr wp
= GetControlOwner (ch
);
4966 WindowPtr wp
= (*ch
)->contrlOwner
;
4969 struct frame
*f
= mac_window_to_frame (wp
);
4970 int win_y
, top_range
;
4972 SetPortWindowPort (wp
);
4974 GetMouse (&mouse_pos
);
4976 win_y
= mouse_pos
.v
- XINT (bar
->top
);
4977 top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
4979 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
4983 if (! NILP (bar
->dragging
))
4984 win_y
-= XINT (bar
->dragging
);
4988 if (win_y
> top_range
)
4992 *bar_window
= bar
->window
;
4994 if (! NILP (bar
->dragging
))
4995 *part
= scroll_bar_handle
;
4996 else if (win_y
< XINT (bar
->start
))
4997 *part
= scroll_bar_above_handle
;
4998 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
4999 *part
= scroll_bar_handle
;
5001 *part
= scroll_bar_below_handle
;
5003 XSETINT (*x
, win_y
);
5004 XSETINT (*y
, top_range
);
5007 last_mouse_scroll_bar
= Qnil
;
5009 *time
= last_mouse_movement_time
;
5013 /* The screen has been cleared so we may have changed foreground or
5014 background colors, and the scroll bars may need to be redrawn.
5015 Clear out the scroll bars, and ask for expose events, so we can
5019 x_scroll_bar_clear (f
)
5022 XTcondemn_scroll_bars (f
);
5023 XTjudge_scroll_bars (f
);
5027 /***********************************************************************
5029 ***********************************************************************/
5031 /* Set clipping for output in glyph row ROW. W is the window in which
5032 we operate. GC is the graphics context to set clipping in.
5034 ROW may be a text row or, e.g., a mode line. Text rows must be
5035 clipped to the interior of the window dedicated to text display,
5036 mode lines must be clipped to the whole window. */
5039 x_clip_to_row (w
, row
, area
, gc
)
5041 struct glyph_row
*row
;
5045 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5047 int window_x
, window_y
, window_width
;
5049 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
5051 clip_rect
.left
= window_x
;
5052 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
5053 clip_rect
.top
= max (clip_rect
.top
, window_y
);
5054 clip_rect
.right
= clip_rect
.left
+ window_width
;
5055 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
5057 mac_set_clip_rectangles (FRAME_MAC_DISPLAY (f
), gc
, &clip_rect
, 1);
5061 /* Draw a hollow box cursor on window W in glyph row ROW. */
5064 x_draw_hollow_cursor (w
, row
)
5066 struct glyph_row
*row
;
5068 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5069 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
5070 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
5073 struct glyph
*cursor_glyph
;
5076 /* Get the glyph the cursor is on. If we can't tell because
5077 the current matrix is invalid or such, give up. */
5078 cursor_glyph
= get_phys_cursor_glyph (w
);
5079 if (cursor_glyph
== NULL
)
5082 /* Compute frame-relative coordinates for phys cursor. */
5083 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
5084 y
= get_phys_cursor_geometry (w
, row
, cursor_glyph
, &h
);
5085 wd
= w
->phys_cursor_width
;
5087 /* The foreground of cursor_gc is typically the same as the normal
5088 background color, which can cause the cursor box to be invisible. */
5089 xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
5090 if (dpyinfo
->scratch_cursor_gc
)
5091 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
5093 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_MAC_WINDOW (f
),
5094 GCForeground
, &xgcv
);
5095 gc
= dpyinfo
->scratch_cursor_gc
;
5097 /* Set clipping, draw the rectangle, and reset clipping again. */
5098 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
5099 mac_draw_rectangle (f
, gc
, x
, y
, wd
, h
);
5100 mac_reset_clip_rectangles (dpy
, gc
);
5104 /* Draw a bar cursor on window W in glyph row ROW.
5106 Implementation note: One would like to draw a bar cursor with an
5107 angle equal to the one given by the font property XA_ITALIC_ANGLE.
5108 Unfortunately, I didn't find a font yet that has this property set.
5112 x_draw_bar_cursor (w
, row
, width
, kind
)
5114 struct glyph_row
*row
;
5116 enum text_cursor_kinds kind
;
5118 struct frame
*f
= XFRAME (w
->frame
);
5119 struct glyph
*cursor_glyph
;
5121 /* If cursor is out of bounds, don't draw garbage. This can happen
5122 in mini-buffer windows when switching between echo area glyphs
5124 cursor_glyph
= get_phys_cursor_glyph (w
);
5125 if (cursor_glyph
== NULL
)
5128 /* If on an image, draw like a normal cursor. That's usually better
5129 visible than drawing a bar, esp. if the image is large so that
5130 the bar might not be in the window. */
5131 if (cursor_glyph
->type
== IMAGE_GLYPH
)
5133 struct glyph_row
*row
;
5134 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
5135 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
5139 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
5140 Window window
= FRAME_MAC_WINDOW (f
);
5141 GC gc
= FRAME_MAC_DISPLAY_INFO (f
)->scratch_cursor_gc
;
5142 unsigned long mask
= GCForeground
| GCBackground
;
5143 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
5146 /* If the glyph's background equals the color we normally draw
5147 the bar cursor in, the bar cursor in its normal color is
5148 invisible. Use the glyph's foreground color instead in this
5149 case, on the assumption that the glyph's colors are chosen so
5150 that the glyph is legible. */
5151 if (face
->background
== f
->output_data
.mac
->cursor_pixel
)
5152 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
5154 xgcv
.background
= xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
5157 XChangeGC (dpy
, gc
, mask
, &xgcv
);
5160 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
5161 FRAME_MAC_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
5165 width
= FRAME_CURSOR_WIDTH (f
);
5166 width
= min (cursor_glyph
->pixel_width
, width
);
5168 w
->phys_cursor_width
= width
;
5169 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
5171 if (kind
== BAR_CURSOR
)
5172 mac_fill_rectangle (f
, gc
,
5173 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
5174 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
5175 width
, row
->height
);
5177 mac_fill_rectangle (f
, gc
,
5178 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
5179 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
5180 row
->height
- width
),
5181 cursor_glyph
->pixel_width
,
5184 mac_reset_clip_rectangles (dpy
, gc
);
5189 /* RIF: Define cursor CURSOR on frame F. */
5192 mac_define_frame_cursor (f
, cursor
)
5196 SetThemeCursor (cursor
);
5200 /* RIF: Clear area on frame F. */
5203 mac_clear_frame_area (f
, x
, y
, width
, height
)
5205 int x
, y
, width
, height
;
5207 mac_clear_area (f
, x
, y
, width
, height
);
5211 /* RIF: Draw cursor on window W. */
5214 mac_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
5216 struct glyph_row
*glyph_row
;
5218 int cursor_type
, cursor_width
;
5223 w
->phys_cursor_type
= cursor_type
;
5224 w
->phys_cursor_on_p
= 1;
5226 if (glyph_row
->exact_window_width_line_p
5227 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
5229 glyph_row
->cursor_in_fringe_p
= 1;
5230 draw_fringe_bitmap (w
, glyph_row
, 0);
5233 switch (cursor_type
)
5235 case HOLLOW_BOX_CURSOR
:
5236 x_draw_hollow_cursor (w
, glyph_row
);
5239 case FILLED_BOX_CURSOR
:
5240 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
5244 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
5248 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
5252 w
->phys_cursor_width
= 0;
5264 #if 0 /* MAC_TODO: no icon support yet. */
5266 x_bitmap_icon (f
, icon
)
5272 if (FRAME_W32_WINDOW (f
) == 0)
5276 hicon
= LoadIcon (hinst
, EMACS_CLASS
);
5277 else if (STRINGP (icon
))
5278 hicon
= LoadImage (NULL
, (LPCTSTR
) SDATA (icon
), IMAGE_ICON
, 0, 0,
5279 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
5280 else if (SYMBOLP (icon
))
5284 if (EQ (icon
, intern ("application")))
5285 name
= (LPCTSTR
) IDI_APPLICATION
;
5286 else if (EQ (icon
, intern ("hand")))
5287 name
= (LPCTSTR
) IDI_HAND
;
5288 else if (EQ (icon
, intern ("question")))
5289 name
= (LPCTSTR
) IDI_QUESTION
;
5290 else if (EQ (icon
, intern ("exclamation")))
5291 name
= (LPCTSTR
) IDI_EXCLAMATION
;
5292 else if (EQ (icon
, intern ("asterisk")))
5293 name
= (LPCTSTR
) IDI_ASTERISK
;
5294 else if (EQ (icon
, intern ("winlogo")))
5295 name
= (LPCTSTR
) IDI_WINLOGO
;
5299 hicon
= LoadIcon (NULL
, name
);
5307 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
5312 #endif /* MAC_TODO */
5314 /************************************************************************
5316 ************************************************************************/
5318 /* Display Error Handling functions not used on W32. Listing them here
5319 helps diff stay in step when comparing w32term.c with xterm.c.
5321 x_error_catcher (display, error)
5322 x_catch_errors (dpy)
5323 x_catch_errors_unwind (old_val)
5324 x_check_errors (dpy, format)
5325 x_had_errors_p (dpy)
5326 x_clear_errors (dpy)
5327 x_uncatch_errors (dpy, count)
5329 x_connection_signal (signalnum)
5330 x_connection_closed (dpy, error_message)
5331 x_error_quitter (display, error)
5332 x_error_handler (display, error)
5333 x_io_error_quitter (display)
5338 /* Changing the font of the frame. */
5340 /* Give frame F the font named FONTNAME as its default font, and
5341 return the full name of that font. FONTNAME may be a wildcard
5342 pattern; in that case, we choose some font that fits the pattern.
5343 The return value shows which font we chose. */
5346 x_new_font (f
, fontname
)
5348 register char *fontname
;
5350 struct font_info
*fontp
5351 = FS_LOAD_FONT (f
, 0, fontname
, -1);
5356 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
5357 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
5358 FRAME_FONTSET (f
) = -1;
5360 FRAME_COLUMN_WIDTH (f
) = fontp
->average_width
;
5361 FRAME_SPACE_WIDTH (f
) = fontp
->space_width
;
5362 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (FRAME_FONT (f
));
5364 compute_fringe_widths (f
, 1);
5366 /* Compute the scroll bar width in character columns. */
5367 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
5369 int wid
= FRAME_COLUMN_WIDTH (f
);
5370 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
5371 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
5375 int wid
= FRAME_COLUMN_WIDTH (f
);
5376 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
5379 /* Now make the frame display the given font. */
5380 if (FRAME_MAC_WINDOW (f
) != 0)
5382 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->normal_gc
,
5384 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->reverse_gc
,
5386 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->cursor_gc
,
5389 /* Don't change the size of a tip frame; there's no point in
5390 doing it because it's done in Fx_show_tip, and it leads to
5391 problems because the tip frame has no widget. */
5392 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
5393 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
5396 return build_string (fontp
->full_name
);
5399 /* Give frame F the fontset named FONTSETNAME as its default font, and
5400 return the full name of that fontset. FONTSETNAME may be a wildcard
5401 pattern; in that case, we choose some fontset that fits the pattern.
5402 The return value shows which fontset we chose. */
5405 x_new_fontset (f
, fontsetname
)
5409 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
5415 if (FRAME_FONTSET (f
) == fontset
)
5416 /* This fontset is already set in frame F. There's nothing more
5418 return fontset_name (fontset
);
5420 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
5422 if (!STRINGP (result
))
5423 /* Can't load ASCII font. */
5426 /* Since x_new_font doesn't update any fontset information, do it now. */
5427 FRAME_FONTSET (f
) = fontset
;
5429 return build_string (fontsetname
);
5433 /***********************************************************************
5434 TODO: W32 Input Methods
5435 ***********************************************************************/
5436 /* Listing missing functions from xterm.c helps diff stay in step.
5438 xim_destroy_callback (xim, client_data, call_data)
5439 xim_open_dpy (dpyinfo, resource_name)
5441 xim_instantiate_callback (display, client_data, call_data)
5442 xim_initialize (dpyinfo, resource_name)
5443 xim_close_dpy (dpyinfo)
5449 mac_get_window_bounds (f
, inner
, outer
)
5451 Rect
*inner
, *outer
;
5453 #if TARGET_API_MAC_CARBON
5454 GetWindowBounds (FRAME_MAC_WINDOW (f
), kWindowContentRgn
, inner
);
5455 GetWindowBounds (FRAME_MAC_WINDOW (f
), kWindowStructureRgn
, outer
);
5456 #else /* not TARGET_API_MAC_CARBON */
5457 RgnHandle region
= NewRgn ();
5459 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowContentRgn
, region
);
5460 *inner
= (*region
)->rgnBBox
;
5461 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowStructureRgn
, region
);
5462 *outer
= (*region
)->rgnBBox
;
5463 DisposeRgn (region
);
5464 #endif /* not TARGET_API_MAC_CARBON */
5469 /* Calculate the absolute position in frame F
5470 from its current recorded position values and gravity. */
5473 x_calc_absolute_position (f
)
5476 int width_diff
= 0, height_diff
= 0;
5477 int flags
= f
->size_hint_flags
;
5480 /* We have nothing to do if the current position
5481 is already for the top-left corner. */
5482 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
5485 /* Find the offsets of the outside upper-left corner of
5486 the inner window, with respect to the outer window. */
5487 mac_get_window_bounds (f
, &inner
, &outer
);
5489 width_diff
= (outer
.right
- outer
.left
) - (inner
.right
- inner
.left
);
5490 height_diff
= (outer
.bottom
- outer
.top
) - (inner
.bottom
- inner
.top
);
5492 /* Treat negative positions as relative to the leftmost bottommost
5493 position that fits on the screen. */
5494 if (flags
& XNegative
)
5495 f
->left_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->width
5497 - FRAME_PIXEL_WIDTH (f
)
5500 if (flags
& YNegative
)
5501 f
->top_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->height
5503 - FRAME_PIXEL_HEIGHT (f
)
5506 /* The left_pos and top_pos
5507 are now relative to the top and left screen edges,
5508 so the flags should correspond. */
5509 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5512 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
5513 to really change the position, and 0 when calling from
5514 x_make_frame_visible (in that case, XOFF and YOFF are the current
5515 position values). It is -1 when calling from x_set_frame_parameters,
5516 which means, do adjust for borders but don't change the gravity. */
5519 x_set_offset (f
, xoff
, yoff
, change_gravity
)
5521 register int xoff
, yoff
;
5524 if (change_gravity
> 0)
5528 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5530 f
->size_hint_flags
|= XNegative
;
5532 f
->size_hint_flags
|= YNegative
;
5533 f
->win_gravity
= NorthWestGravity
;
5535 x_calc_absolute_position (f
);
5538 x_wm_set_size_hint (f
, (long) 0, 0);
5540 #if TARGET_API_MAC_CARBON
5541 MoveWindowStructure (FRAME_MAC_WINDOW (f
), f
->left_pos
, f
->top_pos
);
5542 /* If the title bar is completely outside the screen, adjust the
5544 ConstrainWindowToScreen (FRAME_MAC_WINDOW (f
), kWindowTitleBarRgn
,
5545 kWindowConstrainMoveRegardlessOfFit
5546 | kWindowConstrainAllowPartial
, NULL
, NULL
);
5547 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
5550 Rect inner
, outer
, screen_rect
, dummy
;
5551 RgnHandle region
= NewRgn ();
5553 mac_get_window_bounds (f
, &inner
, &outer
);
5554 f
->x_pixels_diff
= inner
.left
- outer
.left
;
5555 f
->y_pixels_diff
= inner
.top
- outer
.top
;
5556 MoveWindow (FRAME_MAC_WINDOW (f
), f
->left_pos
+ f
->x_pixels_diff
,
5557 f
->top_pos
+ f
->y_pixels_diff
, false);
5559 /* If the title bar is completely outside the screen, adjust the
5560 position. The variable `outer' holds the title bar rectangle.
5561 The variable `inner' holds slightly smaller one than `outer',
5562 so that the calculation of overlapping may not become too
5564 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowTitleBarRgn
, region
);
5565 outer
= (*region
)->rgnBBox
;
5566 DisposeRgn (region
);
5568 InsetRect (&inner
, 8, 8);
5569 screen_rect
= qd
.screenBits
.bounds
;
5570 screen_rect
.top
+= GetMBarHeight ();
5572 if (!SectRect (&inner
, &screen_rect
, &dummy
))
5574 if (inner
.right
<= screen_rect
.left
)
5575 f
->left_pos
= screen_rect
.left
;
5576 else if (inner
.left
>= screen_rect
.right
)
5577 f
->left_pos
= screen_rect
.right
- (outer
.right
- outer
.left
);
5579 if (inner
.bottom
<= screen_rect
.top
)
5580 f
->top_pos
= screen_rect
.top
;
5581 else if (inner
.top
>= screen_rect
.bottom
)
5582 f
->top_pos
= screen_rect
.bottom
- (outer
.bottom
- outer
.top
);
5584 MoveWindow (FRAME_MAC_WINDOW (f
), f
->left_pos
+ f
->x_pixels_diff
,
5585 f
->top_pos
+ f
->y_pixels_diff
, false);
5593 /* Call this to change the size of frame F's x-window.
5594 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
5595 for this size change and subsequent size changes.
5596 Otherwise we leave the window gravity unchanged. */
5599 x_set_window_size (f
, change_gravity
, cols
, rows
)
5604 int pixelwidth
, pixelheight
;
5608 check_frame_size (f
, &rows
, &cols
);
5609 f
->scroll_bar_actual_width
5610 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
5612 compute_fringe_widths (f
, 0);
5614 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
5615 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
5617 f
->win_gravity
= NorthWestGravity
;
5618 x_wm_set_size_hint (f
, (long) 0, 0);
5620 SizeWindow (FRAME_MAC_WINDOW (f
), pixelwidth
, pixelheight
, 0);
5621 #if TARGET_API_MAC_CARBON
5622 if (f
->output_data
.mac
->hourglass_control
)
5623 MoveControl (f
->output_data
.mac
->hourglass_control
,
5624 pixelwidth
- HOURGLASS_WIDTH
, 0);
5627 /* Now, strictly speaking, we can't be sure that this is accurate,
5628 but the window manager will get around to dealing with the size
5629 change request eventually, and we'll hear how it went when the
5630 ConfigureNotify event gets here.
5632 We could just not bother storing any of this information here,
5633 and let the ConfigureNotify event set everything up, but that
5634 might be kind of confusing to the Lisp code, since size changes
5635 wouldn't be reported in the frame parameters until some random
5636 point in the future when the ConfigureNotify event arrives.
5638 We pass 1 for DELAY since we can't run Lisp code inside of
5640 change_frame_size (f
, rows
, cols
, 0, 1, 0);
5641 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
5642 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
5644 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
5645 receive in the ConfigureNotify event; if we get what we asked
5646 for, then the event won't cause the screen to become garbaged, so
5647 we have to make sure to do it here. */
5648 SET_FRAME_GARBAGED (f
);
5650 XFlush (FRAME_X_DISPLAY (f
));
5652 /* If cursor was outside the new size, mark it as off. */
5653 mark_window_cursors_off (XWINDOW (f
->root_window
));
5655 /* Clear out any recollection of where the mouse highlighting was,
5656 since it might be in a place that's outside the new frame size.
5657 Actually checking whether it is outside is a pain in the neck,
5658 so don't try--just let the highlighting be done afresh with new size. */
5659 cancel_mouse_face (f
);
5664 /* Mouse warping. */
5666 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
5669 x_set_mouse_position (f
, x
, y
)
5675 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
5676 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
5678 if (pix_x
< 0) pix_x
= 0;
5679 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
5681 if (pix_y
< 0) pix_y
= 0;
5682 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
5684 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
5688 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
5692 #if 0 /* MAC_TODO: CursorDeviceMoveTo is non-Carbon */
5695 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
5696 0, 0, 0, 0, pix_x
, pix_y
);
5701 /* focus shifting, raising and lowering. */
5704 x_focus_on_frame (f
)
5707 #if 0 /* This proves to be unpleasant. */
5711 /* I don't think that the ICCCM allows programs to do things like this
5712 without the interaction of the window manager. Whatever you end up
5713 doing with this code, do it to x_unfocus_frame too. */
5714 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5715 RevertToPointerRoot
, CurrentTime
);
5725 /* Raise frame F. */
5731 if (f
->async_visible
)
5734 SelectWindow (FRAME_MAC_WINDOW (f
));
5739 /* Lower frame F. */
5745 if (f
->async_visible
)
5748 SendBehind (FRAME_MAC_WINDOW (f
), nil
);
5754 XTframe_raise_lower (f
, raise_flag
)
5764 /* Change of visibility. */
5767 mac_handle_visibility_change (f
)
5770 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
5771 int visible
= 0, iconified
= 0;
5772 struct input_event buf
;
5774 if (IsWindowVisible (wp
))
5775 if (IsWindowCollapsed (wp
))
5780 if (!f
->async_visible
&& visible
)
5784 /* wait_reading_process_output will notice this and update
5785 the frame's display structures. If we were made
5786 invisible, we should not set garbaged, because that stops
5787 redrawing on Update events. */
5788 SET_FRAME_GARBAGED (f
);
5791 buf
.kind
= DEICONIFY_EVENT
;
5792 XSETFRAME (buf
.frame_or_window
, f
);
5793 kbd_buffer_store_event (&buf
);
5795 else if (! NILP (Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
5796 /* Force a redisplay sooner or later to update the
5797 frame titles in case this is the second frame. */
5798 record_asynch_buffer_change ();
5800 else if (f
->async_visible
&& !visible
)
5804 buf
.kind
= ICONIFY_EVENT
;
5805 XSETFRAME (buf
.frame_or_window
, f
);
5806 kbd_buffer_store_event (&buf
);
5809 f
->async_visible
= visible
;
5810 f
->async_iconified
= iconified
;
5813 /* This tries to wait until the frame is really visible.
5814 However, if the window manager asks the user where to position
5815 the frame, this will return before the user finishes doing that.
5816 The frame will not actually be visible at that time,
5817 but it will become visible later when the window manager
5818 finishes with it. */
5821 x_make_frame_visible (f
)
5825 int original_top
, original_left
;
5829 if (! FRAME_VISIBLE_P (f
))
5831 /* We test FRAME_GARBAGED_P here to make sure we don't
5832 call x_set_offset a second time
5833 if we get to x_make_frame_visible a second time
5834 before the window gets really visible. */
5835 if (! FRAME_ICONIFIED_P (f
)
5836 && ! f
->output_data
.mac
->asked_for_visible
)
5837 #if TARGET_API_MAC_CARBON
5838 if (!(FRAME_SIZE_HINTS (f
)->flags
& (USPosition
| PPosition
)))
5840 struct frame
*sf
= SELECTED_FRAME ();
5841 if (!FRAME_MAC_P (sf
))
5842 RepositionWindow (FRAME_MAC_WINDOW (f
), NULL
,
5843 kWindowCenterOnMainScreen
);
5845 RepositionWindow (FRAME_MAC_WINDOW (f
),
5846 FRAME_MAC_WINDOW (sf
),
5847 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
5848 kWindowCascadeStartAtParentWindowScreen
5850 kWindowCascadeOnParentWindowScreen
5853 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
5857 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
5859 f
->output_data
.mac
->asked_for_visible
= 1;
5861 SelectWindow (FRAME_MAC_WINDOW (f
));
5862 CollapseWindow (FRAME_MAC_WINDOW (f
), false);
5863 ShowWindow (FRAME_MAC_WINDOW (f
));
5866 XFlush (FRAME_MAC_DISPLAY (f
));
5868 /* Synchronize to ensure Emacs knows the frame is visible
5869 before we do anything else. We do this loop with input not blocked
5870 so that incoming events are handled. */
5875 /* This must come after we set COUNT. */
5878 XSETFRAME (frame
, f
);
5880 /* Wait until the frame is visible. Process X events until a
5881 MapNotify event has been seen, or until we think we won't get a
5882 MapNotify at all.. */
5883 for (count
= input_signal_count
+ 10;
5884 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
5886 /* Force processing of queued events. */
5889 /* Machines that do polling rather than SIGIO have been
5890 observed to go into a busy-wait here. So we'll fake an
5891 alarm signal to let the handler know that there's something
5892 to be read. We used to raise a real alarm, but it seems
5893 that the handler isn't always enabled here. This is
5895 if (input_polling_used ())
5897 /* It could be confusing if a real alarm arrives while
5898 processing the fake one. Turn it off and let the
5899 handler reset it. */
5900 extern void poll_for_input_1
P_ ((void));
5901 int old_poll_suppress_count
= poll_suppress_count
;
5902 poll_suppress_count
= 1;
5903 poll_for_input_1 ();
5904 poll_suppress_count
= old_poll_suppress_count
;
5907 /* See if a MapNotify event has been processed. */
5908 FRAME_SAMPLE_VISIBILITY (f
);
5913 /* Change from mapped state to withdrawn state. */
5915 /* Make the frame visible (mapped and not iconified). */
5918 x_make_frame_invisible (f
)
5921 /* A deactivate event does not occur when the last visible frame is
5922 made invisible. So if we clear the highlight here, it will not
5923 be rehighlighted when it is made visible. */
5925 /* Don't keep the highlight on an invisible frame. */
5926 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5927 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5932 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
5933 that the current position of the window is user-specified, rather than
5934 program-specified, so that when the window is mapped again, it will be
5935 placed at the same location, without forcing the user to position it
5936 by hand again (they have already done that once for this window.) */
5937 x_wm_set_size_hint (f
, (long) 0, 1);
5939 HideWindow (FRAME_MAC_WINDOW (f
));
5943 #if !USE_CARBON_EVENTS
5944 mac_handle_visibility_change (f
);
5948 /* Change window state from mapped to iconified. */
5956 /* A deactivate event does not occur when the last visible frame is
5957 iconified. So if we clear the highlight here, it will not be
5958 rehighlighted when it is deiconified. */
5960 /* Don't keep the highlight on an invisible frame. */
5961 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5962 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5965 if (f
->async_iconified
)
5970 FRAME_SAMPLE_VISIBILITY (f
);
5972 if (! FRAME_VISIBLE_P (f
))
5973 ShowWindow (FRAME_MAC_WINDOW (f
));
5975 err
= CollapseWindow (FRAME_MAC_WINDOW (f
), true);
5980 error ("Can't notify window manager of iconification");
5982 #if !USE_CARBON_EVENTS
5983 mac_handle_visibility_change (f
);
5988 /* Free X resources of frame F. */
5991 x_free_frame_resources (f
)
5994 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
5995 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
5999 if (wp
!= tip_window
)
6000 remove_window_handler (wp
);
6003 if (wp
== tip_window
)
6004 /* Neither WaitNextEvent nor ReceiveNextEvent receives `window
6005 closed' event. So we reset tip_window here. */
6008 free_frame_menubar (f
);
6010 if (FRAME_FACE_CACHE (f
))
6011 free_frame_faces (f
);
6015 if (FRAME_SIZE_HINTS (f
))
6016 xfree (FRAME_SIZE_HINTS (f
));
6018 xfree (f
->output_data
.mac
);
6019 f
->output_data
.mac
= NULL
;
6021 if (f
== dpyinfo
->x_focus_frame
)
6022 dpyinfo
->x_focus_frame
= 0;
6023 if (f
== dpyinfo
->x_focus_event_frame
)
6024 dpyinfo
->x_focus_event_frame
= 0;
6025 if (f
== dpyinfo
->x_highlight_frame
)
6026 dpyinfo
->x_highlight_frame
= 0;
6028 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6030 dpyinfo
->mouse_face_beg_row
6031 = dpyinfo
->mouse_face_beg_col
= -1;
6032 dpyinfo
->mouse_face_end_row
6033 = dpyinfo
->mouse_face_end_col
= -1;
6034 dpyinfo
->mouse_face_window
= Qnil
;
6035 dpyinfo
->mouse_face_deferred_gc
= 0;
6036 dpyinfo
->mouse_face_mouse_frame
= 0;
6043 /* Destroy the X window of frame F. */
6046 x_destroy_window (f
)
6049 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6051 x_free_frame_resources (f
);
6053 dpyinfo
->reference_count
--;
6057 /* Setting window manager hints. */
6059 /* Set the normal size hints for the window manager, for frame F.
6060 FLAGS is the flags word to use--or 0 meaning preserve the flags
6061 that the window now has.
6062 If USER_POSITION is nonzero, we set the USPosition
6063 flag (this is useful when FLAGS is 0). */
6065 x_wm_set_size_hint (f
, flags
, user_position
)
6070 int base_width
, base_height
, width_inc
, height_inc
;
6071 int min_rows
= 0, min_cols
= 0;
6072 XSizeHints
*size_hints
;
6074 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
6075 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
6076 width_inc
= FRAME_COLUMN_WIDTH (f
);
6077 height_inc
= FRAME_LINE_HEIGHT (f
);
6079 check_frame_size (f
, &min_rows
, &min_cols
);
6081 size_hints
= FRAME_SIZE_HINTS (f
);
6082 if (size_hints
== NULL
)
6084 size_hints
= FRAME_SIZE_HINTS (f
) = xmalloc (sizeof (XSizeHints
));
6085 bzero (size_hints
, sizeof (XSizeHints
));
6088 size_hints
->flags
|= PResizeInc
| PMinSize
| PBaseSize
;
6089 size_hints
->width_inc
= width_inc
;
6090 size_hints
->height_inc
= height_inc
;
6091 size_hints
->min_width
= base_width
+ min_cols
* width_inc
;
6092 size_hints
->min_height
= base_height
+ min_rows
* height_inc
;
6093 size_hints
->base_width
= base_width
;
6094 size_hints
->base_height
= base_height
;
6097 size_hints
->flags
= flags
;
6098 else if (user_position
)
6100 size_hints
->flags
&= ~ PPosition
;
6101 size_hints
->flags
|= USPosition
;
6105 #if 0 /* MAC_TODO: hide application instead of iconify? */
6106 /* Used for IconicState or NormalState */
6109 x_wm_set_window_state (f
, state
)
6113 #ifdef USE_X_TOOLKIT
6116 XtSetArg (al
[0], XtNinitialState
, state
);
6117 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6118 #else /* not USE_X_TOOLKIT */
6119 Window window
= FRAME_X_WINDOW (f
);
6121 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
6122 f
->output_data
.x
->wm_hints
.initial_state
= state
;
6124 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6125 #endif /* not USE_X_TOOLKIT */
6129 x_wm_set_icon_pixmap (f
, pixmap_id
)
6135 #ifndef USE_X_TOOLKIT
6136 Window window
= FRAME_X_WINDOW (f
);
6141 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
6142 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
6146 /* It seems there is no way to turn off use of an icon pixmap.
6147 The following line does it, only if no icon has yet been created,
6148 for some window managers. But with mwm it crashes.
6149 Some people say it should clear the IconPixmapHint bit in this case,
6150 but that doesn't work, and the X consortium said it isn't the
6151 right thing at all. Since there is no way to win,
6152 best to explicitly give up. */
6154 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
6160 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
6164 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
6165 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6168 #else /* not USE_X_TOOLKIT */
6170 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
6171 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6173 #endif /* not USE_X_TOOLKIT */
6176 #endif /* MAC_TODO */
6179 x_wm_set_icon_position (f
, icon_x
, icon_y
)
6183 #if 0 /* MAC_TODO: no icons on Mac */
6184 #ifdef USE_X_TOOLKIT
6185 Window window
= XtWindow (f
->output_data
.x
->widget
);
6187 Window window
= FRAME_X_WINDOW (f
);
6190 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
6191 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
6192 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
6194 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6195 #endif /* MAC_TODO */
6199 /***********************************************************************
6201 ***********************************************************************/
6203 /* An XLFD pattern is divided into blocks delimited by '*'. This
6204 structure holds information for each block. */
6205 struct xlfdpat_block
6207 /* Length of the pattern string in this block. Non-zero except for
6208 the first and the last blocks. */
6211 /* Pattern string except the last character in this block. The last
6212 character is replaced with NUL in order to use it as a
6214 unsigned char *pattern
;
6216 /* Last character of the pattern string. Must not be '?'. */
6217 unsigned char last_char
;
6219 /* One of the tables for the Boyer-Moore string search. It
6220 specifies the number of positions to proceed for each character
6221 with which the match fails. */
6224 /* The skip value for the last character in the above `skip' is
6225 assigned to `infinity' in order to simplify a loop condition.
6226 The original value is saved here. */
6232 /* Normalized pattern string. "Normalized" means that capital
6233 letters are lowered, blocks are not empty except the first and
6234 the last ones, and trailing '?'s in a block that is not the last
6235 one are moved to the next one. The last character in each block
6236 is replaced with NUL. */
6239 /* Number of characters except '*'s and trailing '?'s in the
6240 normalized pattern string. */
6243 /* Number of trailing '?'s in the normalized pattern string. */
6244 int trailing_anychars
;
6246 /* Number of blocks and information for each block. The latter is
6247 NULL if the pattern is exact (no '*' or '?' in it). */
6249 struct xlfdpat_block
*blocks
;
6253 xlfdpat_destroy (pat
)
6254 struct xlfdpat
*pat
;
6261 xfree (pat
->blocks
);
6268 static struct xlfdpat
*
6269 xlfdpat_create (pattern
)
6272 struct xlfdpat
*pat
;
6273 int nblocks
, i
, skip
;
6274 unsigned char last_char
, *p
, *q
, *anychar_head
;
6275 struct xlfdpat_block
*blk
;
6277 pat
= xmalloc (sizeof (struct xlfdpat
));
6281 pat
->buf
= xmalloc (strlen (pattern
) + 1);
6282 if (pat
->buf
== NULL
)
6285 /* Normalize the pattern string and store it to `pat->buf'. */
6287 anychar_head
= NULL
;
6290 for (p
= pattern
; *p
; p
++)
6292 unsigned char c
= *p
;
6295 if (last_char
== '*')
6296 /* ...a** -> ...a* */
6300 if (last_char
== '?')
6301 if (anychar_head
> pat
->buf
&& *(anychar_head
- 1) == '*')
6302 /* ...*??* -> ...*?? */
6305 /* ...a??* -> ...a*?? */
6307 *anychar_head
++ = '*';
6314 if (last_char
!= '?')
6318 /* On Mac OS X 10.3, tolower also converts non-ASCII
6319 characters for some locales. */
6323 *q
++ = last_char
= c
;
6327 pat
->nblocks
= nblocks
;
6328 if (last_char
!= '?')
6329 pat
->trailing_anychars
= 0;
6332 pat
->trailing_anychars
= q
- anychar_head
;
6335 pat
->nchars
= q
- pat
->buf
- (nblocks
- 1);
6337 if (anychar_head
== NULL
&& nblocks
== 1)
6339 /* The pattern is exact. */
6344 pat
->blocks
= xmalloc (sizeof (struct xlfdpat_block
) * nblocks
);
6345 if (pat
->blocks
== NULL
)
6348 /* Divide the normalized pattern into blocks. */
6350 for (blk
= pat
->blocks
; blk
< pat
->blocks
+ nblocks
- 1; blk
++)
6355 blk
->len
= p
- blk
->pattern
;
6359 blk
->len
= q
- blk
->pattern
;
6361 /* Setup a table for the Boyer-Moore string search. */
6362 for (blk
= pat
->blocks
; blk
< pat
->blocks
+ nblocks
; blk
++)
6365 blk
->last_char
= blk
->pattern
[blk
->len
- 1];
6366 blk
->pattern
[blk
->len
- 1] = '\0';
6368 for (skip
= 1; skip
< blk
->len
; skip
++)
6369 if (blk
->pattern
[blk
->len
- skip
- 1] == '?')
6372 for (i
= 0; i
< 256; i
++)
6373 blk
->skip
[i
] = skip
;
6375 p
= blk
->pattern
+ (blk
->len
- skip
);
6377 blk
->skip
[*p
++] = skip
;
6379 blk
->last_char_skip
= blk
->skip
[blk
->last_char
];
6385 xlfdpat_destroy (pat
);
6390 xlfdpat_exact_p (pat
)
6391 struct xlfdpat
*pat
;
6393 return pat
->blocks
== NULL
;
6396 /* Return the first string in STRING + 0, ..., STRING + START_MAX such
6397 that the pattern in *BLK matches with its prefix. Return NULL
6398 there is no such strings. STRING must be lowered in advance. */
6401 xlfdpat_block_match_1 (blk
, string
, start_max
)
6402 struct xlfdpat_block
*blk
;
6403 unsigned char *string
;
6406 int start
, infinity
;
6407 unsigned char *p
, *s
;
6409 xassert (blk
->len
> 0);
6410 xassert (start_max
+ blk
->len
<= strlen (string
));
6411 xassert (blk
->last_char
!= '?');
6413 /* See the comments in the function `boyer_moore' (search.c) for the
6414 use of `infinity'. */
6415 infinity
= start_max
+ blk
->len
+ 1;
6416 blk
->skip
[blk
->last_char
] = infinity
;
6421 /* Check the last character of the pattern. */
6422 s
= string
+ blk
->len
- 1;
6425 start
+= blk
->skip
[*(s
+ start
)];
6427 while (start
<= start_max
);
6429 if (start
< infinity
)
6430 /* Couldn't find the last character. */
6433 /* No less than `infinity' means we could find the last
6434 character at `s[start - infinity]'. */
6437 /* Check the remaining characters. We prefer making no-'?'
6438 cases faster because the use of '?' is really rare. */
6443 while (*p
++ == *s
++)
6446 while (*(p
- 1) == '?');
6448 if (*(p
- 1) == '\0')
6450 return string
+ start
;
6453 start
+= blk
->last_char_skip
;
6455 while (start
<= start_max
);
6460 #define xlfdpat_block_match(b, s, m) \
6461 ((b)->len == 1 ? memchr ((s), (b)->last_char, (m) + 1) \
6462 : xlfdpat_block_match_1 (b, s, m))
6464 /* Check if XLFD pattern PAT, which is generated by `xfldpat_create',
6465 matches with STRING. STRING must be lowered in advance. */
6468 xlfdpat_match (pat
, string
)
6469 struct xlfdpat
*pat
;
6470 unsigned char *string
;
6472 int str_len
, nblocks
, i
, start_max
;
6473 struct xlfdpat_block
*blk
;
6476 xassert (pat
->nblocks
> 0);
6478 if (xlfdpat_exact_p (pat
))
6479 return strcmp (pat
->buf
, string
) == 0;
6481 /* The number of the characters in the string must not be smaller
6482 than that in the pattern. */
6483 str_len
= strlen (string
);
6484 if (str_len
< pat
->nchars
+ pat
->trailing_anychars
)
6487 /* Chop off the trailing '?'s. */
6488 str_len
-= pat
->trailing_anychars
;
6490 /* The last block. When it is non-empty, it must match at the end
6492 nblocks
= pat
->nblocks
;
6493 blk
= pat
->blocks
+ (nblocks
- 1);
6495 /* The last block is also the first one. */
6496 return (str_len
== blk
->len
6497 && (blk
->len
== 0 || xlfdpat_block_match (blk
, string
, 0)));
6498 else if (blk
->len
!= 0)
6499 if (!xlfdpat_block_match (blk
, string
+ (str_len
- blk
->len
), 0))
6502 /* The first block. When it is non-empty, it must match at the
6503 beginning of the string. */
6507 s
= xlfdpat_block_match (blk
, string
, 0);
6510 string
= s
+ blk
->len
;
6513 /* The rest of the blocks. */
6514 start_max
= str_len
- pat
->nchars
;
6515 for (i
= 1, blk
++; i
< nblocks
- 1; i
++, blk
++)
6517 s
= xlfdpat_block_match (blk
, string
, start_max
);
6520 start_max
-= s
- string
;
6521 string
= s
+ blk
->len
;
6528 /***********************************************************************
6530 ***********************************************************************/
6532 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6535 x_get_font_info (f
, font_idx
)
6539 return (FRAME_MAC_FONT_TABLE (f
) + font_idx
);
6542 /* the global font name table */
6543 static char **font_name_table
= NULL
;
6544 static int font_name_table_size
= 0;
6545 static int font_name_count
= 0;
6547 /* Alist linking font family names to Font Manager font family
6548 references (which can also be used as QuickDraw font IDs). We use
6549 an alist because hash tables are not ready when the terminal frame
6550 for Mac OS Classic is created. */
6551 static Lisp_Object fm_font_family_alist
;
6553 /* Hash table linking font family names to ATSU font IDs. */
6554 static Lisp_Object atsu_font_id_hash
;
6557 /* Alist linking character set strings to Mac text encoding and Emacs
6559 static Lisp_Object Vmac_charset_info_alist
;
6562 create_text_encoding_info_alist ()
6564 Lisp_Object result
= Qnil
, rest
;
6566 for (rest
= Vmac_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
6568 Lisp_Object charset_info
= XCAR (rest
);
6569 Lisp_Object charset
, coding_system
, text_encoding
;
6570 Lisp_Object existing_info
;
6572 if (!(CONSP (charset_info
)
6573 && STRINGP (charset
= XCAR (charset_info
))
6574 && CONSP (XCDR (charset_info
))
6575 && INTEGERP (text_encoding
= XCAR (XCDR (charset_info
)))
6576 && CONSP (XCDR (XCDR (charset_info
)))
6577 && SYMBOLP (coding_system
= XCAR (XCDR (XCDR (charset_info
))))))
6580 existing_info
= assq_no_quit (text_encoding
, result
);
6581 if (NILP (existing_info
))
6582 result
= Fcons (list3 (text_encoding
, coding_system
, charset
),
6585 if (NILP (Fmember (charset
, XCDR (XCDR (existing_info
)))))
6586 XSETCDR (XCDR (existing_info
),
6587 Fcons (charset
, XCDR (XCDR (existing_info
))));
6595 decode_mac_font_name (name
, size
, coding_system
)
6598 Lisp_Object coding_system
;
6600 struct coding_system coding
;
6603 if (!NILP (coding_system
) && !NILP (Fcoding_system_p (coding_system
)))
6605 for (p
= name
; *p
; p
++)
6606 if (!isascii (*p
) || iscntrl (*p
))
6611 setup_coding_system (coding_system
, &coding
);
6612 coding
.src_multibyte
= 0;
6613 coding
.dst_multibyte
= 1;
6614 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6615 coding
.composing
= COMPOSITION_DISABLED
;
6616 buf
= (char *) alloca (size
);
6618 decode_coding (&coding
, name
, buf
, strlen (name
), size
- 1);
6619 bcopy (buf
, name
, coding
.produced
);
6620 name
[coding
.produced
] = '\0';
6624 /* If there's just one occurrence of '-' in the family name, it is
6625 replaced with '_'. (More than one occurrence of '-' means a
6626 "FOUNDRY-FAMILY-CHARSET"-style name.) */
6627 p
= strchr (name
, '-');
6628 if (p
&& strchr (p
+ 1, '-') == NULL
)
6631 for (p
= name
; *p
; p
++)
6632 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
6633 for some locales. */
6640 mac_to_x_fontname (name
, size
, style
, charset
)
6648 char xf
[256], *result
;
6651 if (sscanf (name
, "%31[^-]-%255[^-]-%31s", foundry
, family
, cs
) == 3)
6655 strcpy(foundry
, "Apple");
6656 strcpy(family
, name
);
6659 sprintf (xf
, "%s-%c-normal--%d-%d-%d-%d-m-%d-%s",
6660 style
& bold
? "bold" : "medium", style
& italic
? 'i' : 'r',
6661 size
, size
* 10, size
? 72 : 0, size
? 72 : 0, size
* 10, charset
);
6663 result
= xmalloc (strlen (foundry
) + strlen (family
) + strlen (xf
) + 3 + 1);
6664 sprintf (result
, "-%s-%s-%s", foundry
, family
, xf
);
6665 for (p
= result
; *p
; p
++)
6666 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
6667 for some locales. */
6674 /* Parse fully-specified and instantiated X11 font spec XF, and store
6675 the results to FAMILY, *SIZE, *STYLE, and CHARSET. Return 1 if the
6676 parsing succeeded, and 0 otherwise. For FAMILY and CHARSET, the
6677 caller must allocate at least 256 and 32 bytes respectively. For
6678 ordinary Mac fonts, the value stored to FAMILY should just be their
6679 names, like "monaco", "Taipei", etc. Fonts converted from the GNU
6680 intlfonts collection contain their charset designation in their
6681 names, like "ETL-Fixed-iso8859-1", "ETL-Fixed-koi8-r", etc. Both
6682 types of font names are handled accordingly. */
6684 const int kDefaultFontSize
= 12;
6687 parse_x_font_name (xf
, family
, size
, style
, charset
)
6693 Str31 foundry
, weight
;
6694 int point_size
, avgwidth
;
6697 if (sscanf (xf
, "-%31[^-]-%255[^-]-%31[^-]-%1[^-]-%*[^-]-%*[^-]-%d-%d-%*[^-]-%*[^-]-%*c-%d-%31s",
6698 foundry
, family
, weight
, slant
, size
,
6699 &point_size
, &avgwidth
, charset
) != 8
6700 && sscanf (xf
, "-%31[^-]-%255[^-]-%31[^-]-%1[^-]-%*[^-]--%d-%d-%*[^-]-%*[^-]-%*c-%d-%31s",
6701 foundry
, family
, weight
, slant
, size
,
6702 &point_size
, &avgwidth
, charset
) != 8)
6708 *size
= point_size
/ 10;
6709 else if (avgwidth
> 0)
6710 *size
= avgwidth
/ 10;
6713 *size
= kDefaultFontSize
;
6716 if (strcmp (weight
, "bold") == 0)
6721 if (NILP (Fassoc (build_string (charset
), Vmac_charset_info_alist
)))
6723 int foundry_len
= strlen (foundry
), family_len
= strlen (family
);
6725 if (foundry_len
+ family_len
+ strlen (charset
) + 2 < sizeof (Str255
))
6727 /* Like sprintf (family, "%s-%s-%s", foundry, family, charset),
6728 but take overlap into account. */
6729 memmove (family
+ foundry_len
+ 1, family
, family_len
);
6730 memcpy (family
, foundry
, foundry_len
);
6731 family
[foundry_len
] = '-';
6732 family
[foundry_len
+ 1 + family_len
] = '-';
6733 strcpy (family
+ foundry_len
+ 1 + family_len
+ 1, charset
);
6739 for (p
= family
; *p
; p
++)
6740 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
6741 for some locales. */
6750 add_font_name_table_entry (char *font_name
)
6752 if (font_name_table_size
== 0)
6754 font_name_table_size
= 256;
6755 font_name_table
= (char **)
6756 xmalloc (font_name_table_size
* sizeof (char *));
6758 else if (font_name_count
+ 1 >= font_name_table_size
)
6760 font_name_table_size
*= 2;
6761 font_name_table
= (char **)
6762 xrealloc (font_name_table
,
6763 font_name_table_size
* sizeof (char *));
6766 font_name_table
[font_name_count
++] = font_name
;
6769 /* Sets up the table font_name_table to contain the list of all fonts
6770 in the system the first time the table is used so that the Resource
6771 Manager need not be accessed every time this information is
6775 init_font_name_table ()
6777 #if TARGET_API_MAC_CARBON
6778 FMFontFamilyIterator ffi
;
6779 FMFontFamilyInstanceIterator ffii
;
6781 Lisp_Object text_encoding_info_alist
;
6782 struct gcpro gcpro1
;
6784 text_encoding_info_alist
= create_text_encoding_info_alist ();
6787 if (!NILP (assq_no_quit (make_number (kTextEncodingMacUnicode
),
6788 text_encoding_info_alist
)))
6791 ItemCount nfonts
, i
;
6792 ATSUFontID
*font_ids
= NULL
;
6793 Ptr name
, prev_name
= NULL
;
6797 make_hash_table (Qequal
, make_number (DEFAULT_HASH_SIZE
),
6798 make_float (DEFAULT_REHASH_SIZE
),
6799 make_float (DEFAULT_REHASH_THRESHOLD
),
6801 err
= ATSUFontCount (&nfonts
);
6803 font_ids
= xmalloc (sizeof (ATSUFontID
) * nfonts
);
6805 err
= ATSUGetFontIDs (font_ids
, nfonts
, NULL
);
6807 for (i
= 0; i
< nfonts
; i
++)
6809 err
= ATSUFindFontName (font_ids
[i
], kFontFamilyName
,
6810 kFontMacintoshPlatform
, kFontNoScript
,
6811 kFontNoLanguage
, 0, NULL
, &name_len
, NULL
);
6814 name
= xmalloc (name_len
+ 1);
6817 name
[name_len
] = '\0';
6818 err
= ATSUFindFontName (font_ids
[i
], kFontFamilyName
,
6819 kFontMacintoshPlatform
, kFontNoScript
,
6820 kFontNoLanguage
, name_len
, name
,
6823 decode_mac_font_name (name
, name_len
+ 1, Qnil
);
6826 && (prev_name
== NULL
6827 || strcmp (name
, prev_name
) != 0))
6829 static char *cs
= "iso10646-1";
6831 add_font_name_table_entry (mac_to_x_fontname (name
, 0,
6833 add_font_name_table_entry (mac_to_x_fontname (name
, 0,
6835 add_font_name_table_entry (mac_to_x_fontname (name
, 0,
6837 add_font_name_table_entry (mac_to_x_fontname (name
, 0,
6838 italic
| bold
, cs
));
6839 Fputhash (make_unibyte_string (name
, name_len
),
6840 long_to_cons (font_ids
[i
]), atsu_font_id_hash
);
6854 /* Create a dummy instance iterator here to avoid creating and
6855 destroying it in the loop. */
6856 if (FMCreateFontFamilyInstanceIterator (0, &ffii
) != noErr
)
6858 /* Create an iterator to enumerate the font families. */
6859 if (FMCreateFontFamilyIterator (NULL
, NULL
, kFMDefaultOptions
, &ffi
)
6862 FMDisposeFontFamilyInstanceIterator (&ffii
);
6866 GCPRO1 (text_encoding_info_alist
);
6868 while (FMGetNextFontFamily (&ffi
, &ff
) == noErr
)
6874 TextEncoding encoding
;
6875 TextEncodingBase sc
;
6876 Lisp_Object text_encoding_info
;
6878 if (FMGetFontFamilyName (ff
, name
) != noErr
)
6884 if (FMGetFontFamilyTextEncoding (ff
, &encoding
) != noErr
)
6886 sc
= GetTextEncodingBase (encoding
);
6887 text_encoding_info
= assq_no_quit (make_number (sc
),
6888 text_encoding_info_alist
);
6889 if (NILP (text_encoding_info
))
6890 text_encoding_info
= assq_no_quit (make_number (kTextEncodingMacRoman
),
6891 text_encoding_info_alist
);
6892 decode_mac_font_name (name
, sizeof (name
),
6893 XCAR (XCDR (text_encoding_info
)));
6894 fm_font_family_alist
= Fcons (Fcons (build_string (name
),
6896 fm_font_family_alist
);
6898 /* Point the instance iterator at the current font family. */
6899 if (FMResetFontFamilyInstanceIterator (ff
, &ffii
) != noErr
)
6902 while (FMGetNextFontFamilyInstance (&ffii
, &font
, &style
, &size
)
6905 Lisp_Object rest
= XCDR (XCDR (text_encoding_info
));
6907 if (size
> 0 || style
== normal
)
6908 for (; !NILP (rest
); rest
= XCDR (rest
))
6910 char *cs
= SDATA (XCAR (rest
));
6914 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
6916 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
6918 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
6920 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
6926 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
6935 /* Dispose of the iterators. */
6936 FMDisposeFontFamilyIterator (&ffi
);
6937 FMDisposeFontFamilyInstanceIterator (&ffii
);
6938 #else /* !TARGET_API_MAC_CARBON */
6940 SInt16 fontnum
, old_fontnum
;
6941 int num_mac_fonts
= CountResources('FOND');
6943 Handle font_handle
, font_handle_2
;
6944 short id
, scriptcode
;
6947 struct FontAssoc
*fat
;
6948 struct AsscEntry
*assc_entry
;
6949 Lisp_Object text_encoding_info_alist
, text_encoding_info
;
6950 struct gcpro gcpro1
;
6952 GetPort (&port
); /* save the current font number used */
6953 old_fontnum
= port
->txFont
;
6955 text_encoding_info_alist
= create_text_encoding_info_alist ();
6957 GCPRO1 (text_encoding_info_alist
);
6959 for (i
= 1; i
<= num_mac_fonts
; i
++) /* get all available fonts */
6961 font_handle
= GetIndResource ('FOND', i
);
6965 GetResInfo (font_handle
, &id
, &type
, name
);
6966 GetFNum (name
, &fontnum
);
6972 scriptcode
= FontToScript (fontnum
);
6973 text_encoding_info
= assq_no_quit (make_number (scriptcode
),
6974 text_encoding_info_alist
);
6975 if (NILP (text_encoding_info
))
6976 text_encoding_info
= assq_no_quit (make_number (smRoman
),
6977 text_encoding_info_alist
);
6978 decode_mac_font_name (name
, sizeof (name
),
6979 XCAR (XCDR (text_encoding_info
)));
6980 fm_font_family_alist
= Fcons (Fcons (build_string (name
),
6981 make_number (fontnum
)),
6982 fm_font_family_alist
);
6985 HLock (font_handle
);
6987 if (GetResourceSizeOnDisk (font_handle
)
6988 >= sizeof (struct FamRec
))
6990 fat
= (struct FontAssoc
*) (*font_handle
6991 + sizeof (struct FamRec
));
6993 = (struct AsscEntry
*) (*font_handle
6994 + sizeof (struct FamRec
)
6995 + sizeof (struct FontAssoc
));
6997 for (j
= 0; j
<= fat
->numAssoc
; j
++, assc_entry
++)
6999 Lisp_Object rest
= XCDR (XCDR (text_encoding_info
));
7001 for (; !NILP (rest
); rest
= XCDR (rest
))
7003 char *cs
= SDATA (XCAR (rest
));
7005 add_font_name_table_entry (mac_to_x_fontname (name
,
7006 assc_entry
->fontSize
,
7007 assc_entry
->fontStyle
,
7013 HUnlock (font_handle
);
7014 font_handle_2
= GetNextFOND (font_handle
);
7015 ReleaseResource (font_handle
);
7016 font_handle
= font_handle_2
;
7018 while (ResError () == noErr
&& font_handle
);
7023 TextFont (old_fontnum
);
7024 #endif /* !TARGET_API_MAC_CARBON */
7029 mac_clear_font_name_table ()
7033 for (i
= 0; i
< font_name_count
; i
++)
7034 xfree (font_name_table
[i
]);
7035 xfree (font_name_table
);
7036 font_name_table
= NULL
;
7037 font_name_table_size
= font_name_count
= 0;
7038 fm_font_family_alist
= Qnil
;
7042 enum xlfd_scalable_field_index
7044 XLFD_SCL_PIXEL_SIZE
,
7045 XLFD_SCL_POINT_SIZE
,
7050 static int xlfd_scalable_fields
[] =
7059 mac_do_list_fonts (pattern
, maxnames
)
7064 Lisp_Object font_list
= Qnil
;
7065 struct xlfdpat
*pat
;
7067 int scl_val
[XLFD_SCL_LAST
], *field
, *val
;
7070 if (font_name_table
== NULL
) /* Initialize when first used. */
7071 init_font_name_table ();
7073 for (i
= 0; i
< XLFD_SCL_LAST
; i
++)
7076 /* If the pattern contains 14 dashes and one of PIXEL_SIZE,
7077 POINT_SIZE, and AVGWIDTH fields is explicitly specified, scalable
7078 fonts are scaled according to the specified size. */
7081 field
= xlfd_scalable_fields
;
7089 if ('0' <= *ptr
&& *ptr
<= '9')
7091 *val
= *ptr
++ - '0';
7092 while ('0' <= *ptr
&& *ptr
<= '9' && *val
< 10000)
7093 *val
= *val
* 10 + *ptr
++ - '0';
7100 ptr
= strchr (ptr
, '-');
7103 while (ptr
&& i
< 14);
7105 if (i
== 14 && ptr
== NULL
)
7107 if (scl_val
[XLFD_SCL_PIXEL_SIZE
] < 0)
7108 scl_val
[XLFD_SCL_PIXEL_SIZE
] =
7109 (scl_val
[XLFD_SCL_POINT_SIZE
] > 0 ? scl_val
[XLFD_SCL_POINT_SIZE
] / 10
7110 : (scl_val
[XLFD_SCL_AVGWIDTH
] > 0 ? scl_val
[XLFD_SCL_AVGWIDTH
] / 10
7112 if (scl_val
[XLFD_SCL_POINT_SIZE
] < 0)
7113 scl_val
[XLFD_SCL_POINT_SIZE
] =
7114 (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0 ? scl_val
[XLFD_SCL_PIXEL_SIZE
] * 10
7115 : (scl_val
[XLFD_SCL_AVGWIDTH
] > 0 ? scl_val
[XLFD_SCL_AVGWIDTH
]
7117 if (scl_val
[XLFD_SCL_AVGWIDTH
] < 0)
7118 scl_val
[XLFD_SCL_AVGWIDTH
] =
7119 (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0 ? scl_val
[XLFD_SCL_PIXEL_SIZE
] * 10
7120 : (scl_val
[XLFD_SCL_POINT_SIZE
] > 0 ? scl_val
[XLFD_SCL_POINT_SIZE
]
7124 scl_val
[XLFD_SCL_PIXEL_SIZE
] = -1;
7126 pat
= xlfdpat_create (pattern
);
7130 exact
= xlfdpat_exact_p (pat
);
7132 for (i
= 0; i
< font_name_count
; i
++)
7134 if (xlfdpat_match (pat
, font_name_table
[i
]))
7136 font_list
= Fcons (build_string (font_name_table
[i
]), font_list
);
7137 if (exact
|| maxnames
> 0 && ++n_fonts
>= maxnames
)
7140 else if (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0
7141 && (ptr
= strstr (font_name_table
[i
], "-0-0-0-0-m-0-")))
7143 int former_len
= ptr
- font_name_table
[i
];
7145 scaled
= xmalloc (strlen (font_name_table
[i
]) + 20 + 1);
7148 memcpy (scaled
, font_name_table
[i
], former_len
);
7149 sprintf (scaled
+ former_len
,
7150 "-%d-%d-72-72-m-%d-%s",
7151 scl_val
[XLFD_SCL_PIXEL_SIZE
],
7152 scl_val
[XLFD_SCL_POINT_SIZE
],
7153 scl_val
[XLFD_SCL_AVGWIDTH
],
7154 ptr
+ sizeof ("-0-0-0-0-m-0-") - 1);
7156 if (xlfdpat_match (pat
, scaled
))
7158 font_list
= Fcons (build_string (scaled
), font_list
);
7160 if (exact
|| maxnames
> 0 && ++n_fonts
>= maxnames
)
7168 xlfdpat_destroy (pat
);
7173 /* Return a list of names of available fonts matching PATTERN on frame F.
7175 Frame F null means we have not yet created any frame on Mac, and
7176 consult the first display in x_display_list. MAXNAMES sets a limit
7177 on how many fonts to match. */
7180 x_list_fonts (f
, pattern
, size
, maxnames
)
7182 Lisp_Object pattern
;
7185 Lisp_Object list
= Qnil
, patterns
, tem
, key
;
7186 struct mac_display_info
*dpyinfo
7187 = f
? FRAME_MAC_DISPLAY_INFO (f
) : x_display_list
;
7189 xassert (size
<= 0);
7191 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
7192 if (NILP (patterns
))
7193 patterns
= Fcons (pattern
, Qnil
);
7195 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
7197 pattern
= XCAR (patterns
);
7199 if (!STRINGP (pattern
))
7202 tem
= XCAR (XCDR (dpyinfo
->name_list_element
));
7203 key
= Fcons (pattern
, make_number (maxnames
));
7205 list
= Fassoc (key
, tem
);
7208 list
= Fcdr_safe (list
);
7209 /* We have a cashed list. Don't have to get the list again. */
7214 list
= mac_do_list_fonts (SDATA (pattern
), maxnames
);
7217 /* MAC_TODO: add code for matching outline fonts here */
7219 /* Now store the result in the cache. */
7220 XSETCAR (XCDR (dpyinfo
->name_list_element
),
7221 Fcons (Fcons (key
, list
),
7222 XCAR (XCDR (dpyinfo
->name_list_element
))));
7225 if (NILP (list
)) continue; /* Try the remaining alternatives. */
7234 /* Check that FONT is valid on frame F. It is if it can be found in F's
7238 x_check_font (f
, font
)
7243 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7245 xassert (font
!= NULL
);
7247 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7248 if (dpyinfo
->font_table
[i
].name
7249 && font
== dpyinfo
->font_table
[i
].font
)
7252 xassert (i
< dpyinfo
->n_fonts
);
7255 #endif /* GLYPH_DEBUG != 0 */
7257 /* Set *W to the minimum width, *H to the minimum font height of FONT.
7258 Note: There are (broken) X fonts out there with invalid XFontStruct
7259 min_bounds contents. For example, handa@etl.go.jp reports that
7260 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
7261 have font->min_bounds.width == 0. */
7264 x_font_min_bounds (font
, w
, h
)
7265 MacFontStruct
*font
;
7268 *h
= FONT_HEIGHT (font
);
7269 *w
= font
->min_bounds
.width
;
7273 /* Compute the smallest character width and smallest font height over
7274 all fonts available on frame F. Set the members smallest_char_width
7275 and smallest_font_height in F's x_display_info structure to
7276 the values computed. Value is non-zero if smallest_font_height or
7277 smallest_char_width become smaller than they were before. */
7280 x_compute_min_glyph_bounds (f
)
7284 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7285 MacFontStruct
*font
;
7286 int old_width
= dpyinfo
->smallest_char_width
;
7287 int old_height
= dpyinfo
->smallest_font_height
;
7289 dpyinfo
->smallest_font_height
= 100000;
7290 dpyinfo
->smallest_char_width
= 100000;
7292 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
7293 if (dpyinfo
->font_table
[i
].name
)
7295 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
7298 font
= (MacFontStruct
*) fontp
->font
;
7299 xassert (font
!= (MacFontStruct
*) ~0);
7300 x_font_min_bounds (font
, &w
, &h
);
7302 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
7303 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
7306 xassert (dpyinfo
->smallest_char_width
> 0
7307 && dpyinfo
->smallest_font_height
> 0);
7309 return (dpyinfo
->n_fonts
== 1
7310 || dpyinfo
->smallest_char_width
< old_width
7311 || dpyinfo
->smallest_font_height
< old_height
);
7315 /* Determine whether given string is a fully-specified XLFD: all 14
7316 fields are present, none is '*'. */
7319 is_fully_specified_xlfd (char *p
)
7327 for (i
= 0; i
< 13; i
++)
7329 q
= strchr (p
+ 1, '-');
7332 if (q
- p
== 2 && *(p
+ 1) == '*')
7337 if (strchr (p
+ 1, '-') != NULL
)
7340 if (*(p
+ 1) == '*' && *(p
+ 2) == '\0')
7347 /* XLoadQueryFont creates and returns an internal representation for a
7348 font in a MacFontStruct struct. There is really no concept
7349 corresponding to "loading" a font on the Mac. But we check its
7350 existence and find the font number and all other information for it
7351 and store them in the returned MacFontStruct. */
7353 static MacFontStruct
*
7354 XLoadQueryFont (Display
*dpy
, char *fontname
)
7356 int i
, size
, char_width
;
7362 static ATSUFontID font_id
;
7363 ATSUStyle mac_style
= NULL
;
7366 #if TARGET_API_MAC_CARBON
7367 TextEncoding encoding
;
7372 MacFontStruct
*font
;
7374 if (is_fully_specified_xlfd (fontname
))
7378 Lisp_Object matched_fonts
;
7380 matched_fonts
= mac_do_list_fonts (fontname
, 1);
7381 if (NILP (matched_fonts
))
7383 name
= SDATA (XCAR (matched_fonts
));
7386 if (parse_x_font_name (name
, family
, &size
, &fontface
, charset
) == 0)
7390 if (strcmp (charset
, "iso10646-1") == 0) /* XXX */
7393 ATSUAttributeTag tags
[] = {kATSUFontTag
, kATSUSizeTag
,
7394 kATSUQDBoldfaceTag
, kATSUQDItalicTag
};
7395 ByteCount sizes
[] = {sizeof (ATSUFontID
), sizeof (Fixed
),
7396 sizeof (Boolean
), sizeof (Boolean
)};
7397 static Fixed size_fixed
;
7398 static Boolean bold_p
, italic_p
;
7399 ATSUAttributeValuePtr values
[] = {&font_id
, &size_fixed
,
7400 &bold_p
, &italic_p
};
7401 ATSUFontFeatureType types
[] = {kAllTypographicFeaturesType
};
7402 ATSUFontFeatureSelector selectors
[] = {kAllTypeFeaturesOffSelector
};
7403 Lisp_Object font_id_cons
;
7405 font_id_cons
= Fgethash (make_unibyte_string (family
, strlen (family
)),
7406 atsu_font_id_hash
, Qnil
);
7407 if (NILP (font_id_cons
))
7409 font_id
= cons_to_long (font_id_cons
);
7410 size_fixed
= Long2Fix (size
);
7411 bold_p
= (fontface
& bold
) != 0;
7412 italic_p
= (fontface
& italic
) != 0;
7413 err
= ATSUCreateStyle (&mac_style
);
7416 err
= ATSUSetFontFeatures (mac_style
, sizeof (types
) / sizeof (types
[0]),
7420 err
= ATSUSetAttributes (mac_style
, sizeof (tags
) / sizeof (tags
[0]),
7421 tags
, sizes
, values
);
7423 scriptcode
= kTextEncodingMacUnicode
;
7428 Lisp_Object tmp
= Fassoc (build_string (family
), fm_font_family_alist
);
7432 fontnum
= XINT (XCDR (tmp
));
7433 #if TARGET_API_MAC_CARBON
7434 if (FMGetFontFamilyTextEncoding (fontnum
, &encoding
) != noErr
)
7436 scriptcode
= GetTextEncodingBase (encoding
);
7438 scriptcode
= FontToScript (fontnum
);
7442 font
= (MacFontStruct
*) xmalloc (sizeof (struct MacFontStruct
));
7444 font
->mac_fontnum
= fontnum
;
7445 font
->mac_fontsize
= size
;
7446 font
->mac_fontface
= fontface
;
7447 font
->mac_scriptcode
= scriptcode
;
7449 font
->mac_style
= mac_style
;
7450 #if USE_CG_TEXT_DRAWING
7451 font
->cg_font
= NULL
;
7452 font
->cg_glyphs
= NULL
;
7456 /* Apple Japanese (SJIS) font is listed as both
7457 "*-jisx0208.1983-sjis" (Japanese script) and "*-jisx0201.1976-0"
7458 (Roman script) in init_font_name_table (). The latter should be
7459 treated as a one-byte font. */
7460 if (scriptcode
== smJapanese
&& strcmp (charset
, "jisx0201.1976-0") == 0)
7461 font
->mac_scriptcode
= smRoman
;
7463 font
->full_name
= mac_to_x_fontname (family
, size
, fontface
, charset
);
7466 if (font
->mac_style
)
7469 ATSUTextLayout text_layout
;
7471 Rect char_bounds
, min_bounds
, max_bounds
;
7472 int min_width
, max_width
;
7473 ATSTrapezoid glyph_bounds
;
7475 font
->per_char
= xmalloc (sizeof (XCharStruct
) * 0x10000);
7476 if (font
->per_char
== NULL
)
7478 mac_unload_font (&one_mac_display_info
, font
);
7481 bzero (font
->per_char
, sizeof (XCharStruct
) * 0x10000);
7483 #if USE_CG_TEXT_DRAWING
7485 FMFontFamily font_family
;
7487 ATSFontRef ats_font
;
7489 err
= FMGetFontFamilyInstanceFromFont (font_id
, &font_family
, &style
);
7491 err
= FMGetFontFromFontFamilyInstance (font_family
, fontface
,
7493 /* Use CG text drawing if italic/bold is not synthesized. */
7494 if (err
== noErr
&& style
== fontface
)
7496 ats_font
= FMGetATSFontRefFromFont (font_id
);
7497 font
->cg_font
= CGFontCreateWithPlatformFont (&ats_font
);
7502 font
->cg_glyphs
= xmalloc (sizeof (CGGlyph
) * 0x100);
7503 if (font
->cg_glyphs
)
7504 bzero (font
->cg_glyphs
, sizeof (CGGlyph
) * 0x100);
7507 err
= atsu_get_text_layout_with_text_ptr (&c
, 1,
7512 mac_unload_font (&one_mac_display_info
, font
);
7516 for (c
= 0x20; c
<= 0xff; c
++)
7519 /* Soft hyphen is not supported in ATSUI. */
7523 STORE_XCHARSTRUCT (font
->min_bounds
, min_width
, min_bounds
);
7524 STORE_XCHARSTRUCT (font
->max_bounds
, max_width
, max_bounds
);
7529 err
= ATSUClearLayoutCache (text_layout
, kATSUFromTextBeginning
);
7531 err
= ATSUMeasureTextImage (text_layout
,
7532 kATSUFromTextBeginning
, kATSUToTextEnd
,
7533 0, 0, &char_bounds
);
7535 err
= ATSUGetGlyphBounds (text_layout
, 0, 0,
7536 kATSUFromTextBeginning
, kATSUToTextEnd
,
7537 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
7538 kATSUseFractionalOrigins
,
7540 kATSUseDeviceOrigins
,
7542 1, &glyph_bounds
, NULL
);
7545 xassert (glyph_bounds
.lowerRight
.x
- glyph_bounds
.lowerLeft
.x
7546 == glyph_bounds
.upperRight
.x
- glyph_bounds
.upperLeft
.x
);
7548 char_width
= Fix2Long (glyph_bounds
.upperRight
.x
7549 - glyph_bounds
.upperLeft
.x
);
7550 STORE_XCHARSTRUCT (font
->per_char
[c
],
7551 char_width
, char_bounds
);
7554 min_width
= max_width
= char_width
;
7555 min_bounds
= max_bounds
= char_bounds
;
7556 font
->ascent
= -Fix2Long (glyph_bounds
.upperLeft
.y
);
7557 font
->descent
= Fix2Long (glyph_bounds
.lowerLeft
.y
);
7563 min_width
= min (min_width
, char_width
);
7564 max_width
= max (max_width
, char_width
);
7566 if (!EmptyRect (&char_bounds
))
7568 SetRect (&min_bounds
,
7569 max (min_bounds
.left
, char_bounds
.left
),
7570 max (min_bounds
.top
, char_bounds
.top
),
7571 min (min_bounds
.right
, char_bounds
.right
),
7572 min (min_bounds
.bottom
, char_bounds
.bottom
));
7573 UnionRect (&max_bounds
, &char_bounds
, &max_bounds
);
7577 #if USE_CG_TEXT_DRAWING
7578 if (err
== noErr
&& char_width
> 0 && font
->cg_font
)
7580 ATSUGlyphInfoArray glyph_info_array
;
7581 ByteCount count
= sizeof (ATSUGlyphInfoArray
);
7583 err
= ATSUMatchFontsToText (text_layout
, kATSUFromTextBeginning
,
7584 kATSUToTextEnd
, NULL
, NULL
, NULL
);
7586 err
= ATSUGetGlyphInfo (text_layout
, kATSUFromTextBeginning
,
7587 kATSUToTextEnd
, &count
,
7590 font
->cg_glyphs
[c
] = glyph_info_array
.glyphs
[0].glyphID
;
7593 /* Don't use CG text drawing if font substitution
7594 occurs in ASCII or Latin-1 characters. */
7595 CGFontRelease (font
->cg_font
);
7596 font
->cg_font
= NULL
;
7597 xfree (font
->cg_glyphs
);
7598 font
->cg_glyphs
= NULL
;
7604 font
->min_byte1
= 0;
7605 font
->max_byte1
= 0xff;
7606 font
->min_char_or_byte2
= 0;
7607 font
->max_char_or_byte2
= 0xff;
7613 SInt16 old_fontnum
, old_fontsize
;
7615 FontInfo the_fontinfo
;
7616 int is_two_byte_font
;
7618 /* Save the current font number used. */
7620 #if TARGET_API_MAC_CARBON
7621 old_fontnum
= GetPortTextFont (port
);
7622 old_fontsize
= GetPortTextSize (port
);
7623 old_fontface
= GetPortTextFace (port
);
7625 old_fontnum
= port
->txFont
;
7626 old_fontsize
= port
->txSize
;
7627 old_fontface
= port
->txFace
;
7632 TextFace (fontface
);
7634 GetFontInfo (&the_fontinfo
);
7636 font
->ascent
= the_fontinfo
.ascent
;
7637 font
->descent
= the_fontinfo
.descent
;
7639 is_two_byte_font
= (font
->mac_scriptcode
== smJapanese
7640 || font
->mac_scriptcode
== smTradChinese
7641 || font
->mac_scriptcode
== smSimpChinese
7642 || font
->mac_scriptcode
== smKorean
);
7644 if (is_two_byte_font
)
7646 font
->min_byte1
= 0xa1;
7647 font
->max_byte1
= 0xfe;
7648 font
->min_char_or_byte2
= 0xa1;
7649 font
->max_char_or_byte2
= 0xfe;
7651 /* Use the width of an "ideographic space" of that font
7652 because the_fontinfo.widMax returns the wrong width for
7654 switch (font
->mac_scriptcode
)
7657 font
->min_byte1
= 0x81;
7658 font
->max_byte1
= 0xfc;
7659 font
->min_char_or_byte2
= 0x40;
7660 font
->max_char_or_byte2
= 0xfc;
7661 char_width
= StringWidth("\p\x81\x40");
7664 font
->min_char_or_byte2
= 0x40;
7665 char_width
= StringWidth("\p\xa1\x40");
7668 char_width
= StringWidth("\p\xa1\xa1");
7671 char_width
= StringWidth("\p\xa1\xa1");
7677 font
->min_byte1
= font
->max_byte1
= 0;
7678 font
->min_char_or_byte2
= 0x20;
7679 font
->max_char_or_byte2
= 0xff;
7681 /* Do this instead of use the_fontinfo.widMax, which
7682 incorrectly returns 15 for 12-point Monaco! */
7683 char_width
= CharWidth ('m');
7686 if (is_two_byte_font
)
7688 font
->per_char
= NULL
;
7690 if (fontface
& italic
)
7691 font
->max_bounds
.rbearing
= char_width
+ 1;
7693 font
->max_bounds
.rbearing
= char_width
;
7694 font
->max_bounds
.lbearing
= 0;
7695 font
->max_bounds
.width
= char_width
;
7696 font
->max_bounds
.ascent
= the_fontinfo
.ascent
;
7697 font
->max_bounds
.descent
= the_fontinfo
.descent
;
7699 font
->min_bounds
= font
->max_bounds
;
7703 int c
, min_width
, max_width
;
7704 Rect char_bounds
, min_bounds
, max_bounds
;
7707 font
->per_char
= xmalloc (sizeof (XCharStruct
) * (0xff - 0x20 + 1));
7708 bzero (font
->per_char
, sizeof (XCharStruct
) * (0xff - 0x20 + 1));
7710 min_width
= max_width
= char_width
;
7711 SetRect (&min_bounds
, -32767, -32767, 32767, 32767);
7712 SetRect (&max_bounds
, 0, 0, 0, 0);
7713 for (c
= 0x20; c
<= 0xff; c
++)
7717 STORE_XCHARSTRUCT (font
->min_bounds
, min_width
, min_bounds
);
7718 STORE_XCHARSTRUCT (font
->max_bounds
, max_width
, max_bounds
);
7723 char_width
= CharWidth (ch
);
7724 QDTextBounds (1, &ch
, &char_bounds
);
7725 STORE_XCHARSTRUCT (font
->per_char
[c
- 0x20],
7726 char_width
, char_bounds
);
7727 /* Some Japanese fonts (in SJIS encoding) return 0 as
7728 the character width of 0x7f. */
7731 min_width
= min (min_width
, char_width
);
7732 max_width
= max (max_width
, char_width
);
7734 if (!EmptyRect (&char_bounds
))
7736 SetRect (&min_bounds
,
7737 max (min_bounds
.left
, char_bounds
.left
),
7738 max (min_bounds
.top
, char_bounds
.top
),
7739 min (min_bounds
.right
, char_bounds
.right
),
7740 min (min_bounds
.bottom
, char_bounds
.bottom
));
7741 UnionRect (&max_bounds
, &char_bounds
, &max_bounds
);
7744 if (min_width
== max_width
7745 && max_bounds
.left
>= 0 && max_bounds
.right
<= max_width
)
7747 /* Fixed width and no overhangs. */
7748 xfree (font
->per_char
);
7749 font
->per_char
= NULL
;
7753 /* Restore previous font number, size and face. */
7754 TextFont (old_fontnum
);
7755 TextSize (old_fontsize
);
7756 TextFace (old_fontface
);
7759 #if !defined (MAC_OS8) || USE_ATSUI
7760 /* AppKit and WebKit do some adjustment to the heights of Courier,
7761 Helvetica, and Times. This only works on the environments where
7762 the XDrawImageString counterpart is never used. */
7763 if (strcmp (family
, "courier") == 0 || strcmp (family
, "helvetica") == 0
7764 || strcmp (family
, "times") == 0)
7765 font
->ascent
+= (font
->ascent
+ font
->descent
) * .15 + 0.5;
7773 mac_unload_font (dpyinfo
, font
)
7774 struct mac_display_info
*dpyinfo
;
7777 xfree (font
->full_name
);
7779 xfree (font
->per_char
);
7781 if (font
->mac_style
)
7782 ATSUDisposeStyle (font
->mac_style
);
7783 #if USE_CG_TEXT_DRAWING
7785 CGFontRelease (font
->cg_font
);
7786 if (font
->cg_glyphs
)
7787 xfree (font
->cg_glyphs
);
7794 /* Load font named FONTNAME of the size SIZE for frame F, and return a
7795 pointer to the structure font_info while allocating it dynamically.
7796 If SIZE is 0, load any size of font.
7797 If loading is failed, return NULL. */
7800 x_load_font (f
, fontname
, size
)
7802 register char *fontname
;
7805 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7806 Lisp_Object font_names
;
7808 /* Get a list of all the fonts that match this name. Once we
7809 have a list of matching fonts, we compare them against the fonts
7810 we already have by comparing names. */
7811 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
7813 if (!NILP (font_names
))
7818 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7819 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
7820 if (dpyinfo
->font_table
[i
].name
7821 && (!strcmp (dpyinfo
->font_table
[i
].name
,
7822 SDATA (XCAR (tail
)))
7823 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
7824 SDATA (XCAR (tail
)))))
7825 return (dpyinfo
->font_table
+ i
);
7830 /* Load the font and add it to the table. */
7833 struct MacFontStruct
*font
;
7834 struct font_info
*fontp
;
7835 unsigned long value
;
7838 fontname
= (char *) SDATA (XCAR (font_names
));
7841 font
= (MacFontStruct
*) XLoadQueryFont (FRAME_MAC_DISPLAY (f
), fontname
);
7846 /* Find a free slot in the font table. */
7847 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
7848 if (dpyinfo
->font_table
[i
].name
== NULL
)
7851 /* If no free slot found, maybe enlarge the font table. */
7852 if (i
== dpyinfo
->n_fonts
7853 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
7856 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
7857 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
7859 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
7862 fontp
= dpyinfo
->font_table
+ i
;
7863 if (i
== dpyinfo
->n_fonts
)
7866 /* Now fill in the slots of *FONTP. */
7868 bzero (fontp
, sizeof (*fontp
));
7870 fontp
->font_idx
= i
;
7871 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
7872 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
7874 if (font
->min_bounds
.width
== font
->max_bounds
.width
)
7876 /* Fixed width font. */
7877 fontp
->average_width
= fontp
->space_width
= font
->min_bounds
.width
;
7884 char2b
.byte1
= 0x00, char2b
.byte2
= 0x20;
7885 pcm
= mac_per_char_metric (font
, &char2b
, 0);
7887 fontp
->space_width
= pcm
->width
;
7889 fontp
->space_width
= FONT_WIDTH (font
);
7893 int width
= pcm
->width
;
7894 for (char2b
.byte2
= 33; char2b
.byte2
<= 126; char2b
.byte2
++)
7895 if ((pcm
= mac_per_char_metric (font
, &char2b
, 0)) != NULL
)
7896 width
+= pcm
->width
;
7897 fontp
->average_width
= width
/ 95;
7900 fontp
->average_width
= FONT_WIDTH (font
);
7903 fontp
->full_name
= (char *) xmalloc (strlen (font
->full_name
) + 1);
7904 bcopy (font
->full_name
, fontp
->full_name
, strlen (font
->full_name
) + 1);
7906 fontp
->size
= font
->max_bounds
.width
;
7907 fontp
->height
= FONT_HEIGHT (font
);
7909 /* For some font, ascent and descent in max_bounds field is
7910 larger than the above value. */
7911 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
7912 if (max_height
> fontp
->height
)
7913 fontp
->height
= max_height
;
7916 /* The slot `encoding' specifies how to map a character
7917 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
7918 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
7919 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
7920 2:0xA020..0xFF7F). For the moment, we don't know which charset
7921 uses this font. So, we set information in fontp->encoding[1]
7922 which is never used by any charset. If mapping can't be
7923 decided, set FONT_ENCODING_NOT_DECIDED. */
7924 if (font
->mac_scriptcode
== smJapanese
)
7925 fontp
->encoding
[1] = 4;
7929 = (font
->max_byte1
== 0
7931 ? (font
->min_char_or_byte2
< 0x80
7932 ? (font
->max_char_or_byte2
< 0x80
7933 ? 0 /* 0x20..0x7F */
7934 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
7935 : 1) /* 0xA0..0xFF */
7937 : (font
->min_byte1
< 0x80
7938 ? (font
->max_byte1
< 0x80
7939 ? (font
->min_char_or_byte2
< 0x80
7940 ? (font
->max_char_or_byte2
< 0x80
7941 ? 0 /* 0x2020..0x7F7F */
7942 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
7943 : 3) /* 0x20A0..0x7FFF */
7944 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
7945 : (font
->min_char_or_byte2
< 0x80
7946 ? (font
->max_char_or_byte2
< 0x80
7947 ? 2 /* 0xA020..0xFF7F */
7948 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
7949 : 1))); /* 0xA0A0..0xFFFF */
7952 #if 0 /* MAC_TODO: fill these out with more reasonably values */
7953 fontp
->baseline_offset
7954 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
7955 ? (long) value
: 0);
7956 fontp
->relative_compose
7957 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
7958 ? (long) value
: 0);
7959 fontp
->default_ascent
7960 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
7961 ? (long) value
: 0);
7963 fontp
->baseline_offset
= 0;
7964 fontp
->relative_compose
= 0;
7965 fontp
->default_ascent
= 0;
7968 /* Set global flag fonts_changed_p to non-zero if the font loaded
7969 has a character with a smaller width than any other character
7970 before, or if the font loaded has a smaller height than any
7971 other font loaded before. If this happens, it will make a
7972 glyph matrix reallocation necessary. */
7973 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
7980 /* Return a pointer to struct font_info of a font named FONTNAME for
7981 frame F. If no such font is loaded, return NULL. */
7984 x_query_font (f
, fontname
)
7986 register char *fontname
;
7988 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7991 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7992 if (dpyinfo
->font_table
[i
].name
7993 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
7994 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
7995 return (dpyinfo
->font_table
+ i
);
8000 /* Find a CCL program for a font specified by FONTP, and set the member
8001 `encoder' of the structure. */
8004 x_find_ccl_program (fontp
)
8005 struct font_info
*fontp
;
8007 Lisp_Object list
, elt
;
8009 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
8013 && STRINGP (XCAR (elt
))
8014 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
8020 struct ccl_program
*ccl
8021 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
8023 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
8026 fontp
->font_encoder
= ccl
;
8032 /* The Mac Event loop code */
8034 #if !TARGET_API_MAC_CARBON
8036 #include <Quickdraw.h>
8037 #include <Balloons.h>
8038 #include <Devices.h>
8040 #include <Gestalt.h>
8042 #include <Processes.h>
8044 #include <ToolUtils.h>
8045 #include <TextUtils.h>
8046 #include <Dialogs.h>
8049 #include <Resources.h>
8054 #endif /* ! TARGET_API_MAC_CARBON */
8059 #define WINDOW_RESOURCE 128
8060 #define TERM_WINDOW_RESOURCE 129
8062 #define DEFAULT_NUM_COLS 80
8064 #define MIN_DOC_SIZE 64
8065 #define MAX_DOC_SIZE 32767
8067 #define EXTRA_STACK_ALLOC (256 * 1024)
8069 #define ARGV_STRING_LIST_ID 129
8070 #define ABOUT_ALERT_ID 128
8071 #define RAM_TOO_LARGE_ALERT_ID 129
8073 /* Contains the string "reverse", which is a constant for mouse button emu.*/
8074 Lisp_Object Qreverse
;
8077 /* Modifier associated with the control key, or nil to ignore. */
8078 Lisp_Object Vmac_control_modifier
;
8080 /* Modifier associated with the option key, or nil to ignore. */
8081 Lisp_Object Vmac_option_modifier
;
8083 /* Modifier associated with the command key, or nil to ignore. */
8084 Lisp_Object Vmac_command_modifier
;
8086 /* Modifier associated with the function key, or nil to ignore. */
8087 Lisp_Object Vmac_function_modifier
;
8089 /* True if the option and command modifiers should be used to emulate
8090 a three button mouse */
8091 Lisp_Object Vmac_emulate_three_button_mouse
;
8093 #if USE_CARBON_EVENTS
8094 /* True if the mouse wheel button (i.e. button 4) should map to
8095 mouse-2, instead of mouse-3. */
8096 Lisp_Object Vmac_wheel_button_is_mouse_2
;
8098 /* If Non-nil, the Mac "Command" key is passed on to the Mac Toolbox
8099 for processing before Emacs sees it. */
8100 Lisp_Object Vmac_pass_command_to_system
;
8102 /* If Non-nil, the Mac "Control" key is passed on to the Mac Toolbox
8103 for processing before Emacs sees it. */
8104 Lisp_Object Vmac_pass_control_to_system
;
8107 /* Points to the variable `inev' in the function XTread_socket. It is
8108 used for passing an input event to the function back from
8109 Carbon/Apple event handlers. */
8110 static struct input_event
*read_socket_inev
= NULL
;
8112 /* Set in term/mac-win.el to indicate that event loop can now generate
8113 drag and drop events. */
8114 Lisp_Object Qmac_ready_for_drag_n_drop
;
8116 Point saved_menu_event_location
;
8119 static void init_required_apple_events (void);
8121 do_ae_open_application (const AppleEvent
*, AppleEvent
*, long);
8123 do_ae_print_documents (const AppleEvent
*, AppleEvent
*, long);
8124 static pascal OSErr
do_ae_open_documents (AppleEvent
*, AppleEvent
*, long);
8125 static pascal OSErr
do_ae_quit_application (AppleEvent
*, AppleEvent
*, long);
8127 #if TARGET_API_MAC_CARBON
8129 static pascal OSErr
mac_do_track_drag (DragTrackingMessage
, WindowPtr
, void*, DragReference
);
8130 static pascal OSErr
mac_do_receive_drag (WindowPtr
, void*, DragReference
);
8131 static DragTrackingHandlerUPP mac_do_track_dragUPP
= NULL
;
8132 static DragReceiveHandlerUPP mac_do_receive_dragUPP
= NULL
;
8135 static Lisp_Object Qapplication
, Qabout
;
8136 #if USE_CARBON_EVENTS
8138 extern void init_service_handler ();
8139 static Lisp_Object Qpreferences
, Qservices
, Qpaste
, Qperform
;
8141 /* Window Event Handler */
8142 static pascal OSStatus
mac_handle_window_event (EventHandlerCallRef
,
8145 OSErr
install_window_handler (WindowPtr
);
8147 extern void init_emacs_passwd_dir ();
8148 extern int emacs_main (int, char **, char **);
8150 extern void initialize_applescript();
8151 extern void terminate_applescript();
8154 #if USE_CARBON_EVENTS
8155 mac_to_emacs_modifiers (UInt32 mods
)
8157 mac_to_emacs_modifiers (EventModifiers mods
)
8160 unsigned int result
= 0;
8161 if (mods
& shiftKey
)
8162 result
|= shift_modifier
;
8166 /* Deactivated to simplify configuration:
8167 if Vmac_option_modifier is non-NIL, we fully process the Option
8168 key. Otherwise, we only process it if an additional Ctrl or Command
8169 is pressed. That way the system may convert the character to a
8171 if ((mods & optionKey) &&
8172 (( !NILP(Vmac_option_modifier) ||
8173 ((mods & cmdKey) || (mods & controlKey))))) */
8175 if (!NILP (Vmac_option_modifier
) && (mods
& optionKey
)) {
8176 Lisp_Object val
= Fget(Vmac_option_modifier
, Qmodifier_value
);
8178 result
|= XUINT(val
);
8180 if (!NILP (Vmac_command_modifier
) && (mods
& cmdKey
)) {
8181 Lisp_Object val
= Fget(Vmac_command_modifier
, Qmodifier_value
);
8183 result
|= XUINT(val
);
8185 if (!NILP (Vmac_control_modifier
) && (mods
& controlKey
)) {
8186 Lisp_Object val
= Fget(Vmac_control_modifier
, Qmodifier_value
);
8188 result
|= XUINT(val
);
8192 if (!NILP (Vmac_function_modifier
) && (mods
& kEventKeyModifierFnMask
)) {
8193 Lisp_Object val
= Fget(Vmac_function_modifier
, Qmodifier_value
);
8195 result
|= XUINT(val
);
8203 mac_get_emulated_btn ( UInt32 modifiers
)
8206 if (!NILP (Vmac_emulate_three_button_mouse
)) {
8207 int cmdIs3
= !EQ (Vmac_emulate_three_button_mouse
, Qreverse
);
8208 if (modifiers
& cmdKey
)
8209 result
= cmdIs3
? 2 : 1;
8210 else if (modifiers
& optionKey
)
8211 result
= cmdIs3
? 1 : 2;
8216 #if USE_CARBON_EVENTS
8217 /* Obtains the event modifiers from the event ref and then calls
8218 mac_to_emacs_modifiers. */
8220 mac_event_to_emacs_modifiers (EventRef eventRef
)
8223 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
8224 sizeof (UInt32
), NULL
, &mods
);
8225 if (!NILP (Vmac_emulate_three_button_mouse
) &&
8226 GetEventClass(eventRef
) == kEventClassMouse
)
8228 mods
&= ~(optionKey
| cmdKey
);
8230 return mac_to_emacs_modifiers (mods
);
8233 /* Given an event ref, return the code to use for the mouse button
8234 code in the emacs input_event. */
8236 mac_get_mouse_btn (EventRef ref
)
8238 EventMouseButton result
= kEventMouseButtonPrimary
;
8239 GetEventParameter (ref
, kEventParamMouseButton
, typeMouseButton
, NULL
,
8240 sizeof (EventMouseButton
), NULL
, &result
);
8243 case kEventMouseButtonPrimary
:
8244 if (NILP (Vmac_emulate_three_button_mouse
))
8248 GetEventParameter (ref
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
8249 sizeof (UInt32
), NULL
, &mods
);
8250 return mac_get_emulated_btn(mods
);
8252 case kEventMouseButtonSecondary
:
8253 return NILP (Vmac_wheel_button_is_mouse_2
) ? 1 : 2;
8254 case kEventMouseButtonTertiary
:
8255 case 4: /* 4 is the number for the mouse wheel button */
8256 return NILP (Vmac_wheel_button_is_mouse_2
) ? 2 : 1;
8262 /* Normally, ConvertEventRefToEventRecord will correctly handle all
8263 events. However the click of the mouse wheel is not converted to a
8264 mouseDown or mouseUp event. Likewise for dead key down events.
8265 This calls ConvertEventRef, but then checks to see if it is a mouse
8266 up/down, or a dead key down carbon event that has not been
8267 converted, and if so, converts it by hand (to be picked up in the
8268 XTread_socket loop). */
8269 static Boolean
mac_convert_event_ref (EventRef eventRef
, EventRecord
*eventRec
)
8271 Boolean result
= ConvertEventRefToEventRecord (eventRef
, eventRec
);
8276 switch (GetEventClass (eventRef
))
8278 case kEventClassMouse
:
8279 switch (GetEventKind (eventRef
))
8281 case kEventMouseDown
:
8282 eventRec
->what
= mouseDown
;
8287 eventRec
->what
= mouseUp
;
8296 case kEventClassKeyboard
:
8297 switch (GetEventKind (eventRef
))
8299 case kEventRawKeyDown
:
8301 unsigned char char_codes
;
8304 eventRec
->what
= keyDown
;
8305 GetEventParameter (eventRef
, kEventParamKeyMacCharCodes
, typeChar
,
8306 NULL
, sizeof (char), NULL
, &char_codes
);
8307 GetEventParameter (eventRef
, kEventParamKeyCode
, typeUInt32
,
8308 NULL
, sizeof (UInt32
), NULL
, &key_code
);
8309 eventRec
->message
= char_codes
| ((key_code
& 0xff) << 8);
8325 /* Need where and when. */
8328 GetEventParameter (eventRef
, kEventParamMouseLocation
, typeQDPoint
,
8329 NULL
, sizeof (Point
), NULL
, &eventRec
->where
);
8330 /* Use two step process because new event modifiers are 32-bit
8331 and old are 16-bit. Currently, only loss is NumLock & Fn. */
8332 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
,
8333 NULL
, sizeof (UInt32
), NULL
, &mods
);
8334 eventRec
->modifiers
= mods
;
8336 eventRec
->when
= EventTimeToTicks (GetEventTime (eventRef
));
8347 Handle menubar_handle
;
8348 MenuHandle menu_handle
;
8350 menubar_handle
= GetNewMBar (128);
8351 if(menubar_handle
== NULL
)
8353 SetMenuBar (menubar_handle
);
8356 #if !TARGET_API_MAC_CARBON
8357 menu_handle
= GetMenuHandle (M_APPLE
);
8358 if(menu_handle
!= NULL
)
8359 AppendResMenu (menu_handle
,'DRVR');
8367 do_init_managers (void)
8369 #if !TARGET_API_MAC_CARBON
8370 InitGraf (&qd
.thePort
);
8372 FlushEvents (everyEvent
, 0);
8377 #endif /* !TARGET_API_MAC_CARBON */
8380 #if !TARGET_API_MAC_CARBON
8381 /* set up some extra stack space for use by emacs */
8382 SetApplLimit ((Ptr
) ((long) GetApplLimit () - EXTRA_STACK_ALLOC
));
8384 /* MaxApplZone must be called for AppleScript to execute more
8385 complicated scripts */
8388 #endif /* !TARGET_API_MAC_CARBON */
8392 do_check_ram_size (void)
8394 SInt32 physical_ram_size
, logical_ram_size
;
8396 if (Gestalt (gestaltPhysicalRAMSize
, &physical_ram_size
) != noErr
8397 || Gestalt (gestaltLogicalRAMSize
, &logical_ram_size
) != noErr
8398 || physical_ram_size
> (1 << VALBITS
)
8399 || logical_ram_size
> (1 << VALBITS
))
8401 StopAlert (RAM_TOO_LARGE_ALERT_ID
, NULL
);
8407 do_window_update (WindowPtr win
)
8409 struct frame
*f
= mac_window_to_frame (win
);
8413 /* The tooltip has been drawn already. Avoid the SET_FRAME_GARBAGED
8415 if (win
!= tip_window
)
8417 if (f
->async_visible
== 0)
8419 /* Update events may occur when a frame gets iconified. */
8421 f
->async_visible
= 1;
8422 f
->async_iconified
= 0;
8423 SET_FRAME_GARBAGED (f
);
8429 #if TARGET_API_MAC_CARBON
8430 RgnHandle region
= NewRgn ();
8432 GetPortVisibleRegion (GetWindowPort (win
), region
);
8433 GetRegionBounds (region
, &r
);
8434 expose_frame (f
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
);
8435 UpdateControls (win
, region
);
8436 DisposeRgn (region
);
8438 r
= (*win
->visRgn
)->rgnBBox
;
8439 expose_frame (f
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
);
8440 UpdateControls (win
, win
->visRgn
);
8449 is_emacs_window (WindowPtr win
)
8451 Lisp_Object tail
, frame
;
8456 FOR_EACH_FRAME (tail
, frame
)
8457 if (FRAME_MAC_P (XFRAME (frame
)))
8458 if (FRAME_MAC_WINDOW (XFRAME (frame
)) == win
)
8467 /* Window-activate events will do the job. */
8473 /* Window-deactivate events will do the job. */
8478 do_apple_menu (SInt16 menu_item
)
8480 #if !TARGET_API_MAC_CARBON
8482 SInt16 da_driver_refnum
;
8484 if (menu_item
== I_ABOUT
)
8485 NoteAlert (ABOUT_ALERT_ID
, NULL
);
8488 GetMenuItemText (GetMenuHandle (M_APPLE
), menu_item
, item_name
);
8489 da_driver_refnum
= OpenDeskAcc (item_name
);
8491 #endif /* !TARGET_API_MAC_CARBON */
8495 do_menu_choice (SInt32 menu_choice
)
8497 SInt16 menu_id
, menu_item
;
8499 menu_id
= HiWord (menu_choice
);
8500 menu_item
= LoWord (menu_choice
);
8508 do_apple_menu (menu_item
);
8513 struct frame
*f
= mac_focus_frame (&one_mac_display_info
);
8514 MenuHandle menu
= GetMenuHandle (menu_id
);
8519 GetMenuItemRefCon (menu
, menu_item
, &refcon
);
8520 menubar_selection_callback (f
, refcon
);
8529 /* Handle drags in size box. Based on code contributed by Ben
8530 Mesander and IM - Window Manager A. */
8533 do_grow_window (WindowPtr w
, EventRecord
*e
)
8536 int rows
, columns
, width
, height
;
8537 struct frame
*f
= mac_window_to_frame (w
);
8538 XSizeHints
*size_hints
= FRAME_SIZE_HINTS (f
);
8539 int min_width
= MIN_DOC_SIZE
, min_height
= MIN_DOC_SIZE
;
8540 #if TARGET_API_MAC_CARBON
8546 if (size_hints
->flags
& PMinSize
)
8548 min_width
= size_hints
->min_width
;
8549 min_height
= size_hints
->min_height
;
8551 SetRect (&limit_rect
, min_width
, min_height
, MAX_DOC_SIZE
, MAX_DOC_SIZE
);
8553 #if TARGET_API_MAC_CARBON
8554 if (!ResizeWindow (w
, e
->where
, &limit_rect
, &new_rect
))
8556 height
= new_rect
.bottom
- new_rect
.top
;
8557 width
= new_rect
.right
- new_rect
.left
;
8559 grow_size
= GrowWindow (w
, e
->where
, &limit_rect
);
8560 /* see if it really changed size */
8563 height
= HiWord (grow_size
);
8564 width
= LoWord (grow_size
);
8567 if (width
!= FRAME_PIXEL_WIDTH (f
)
8568 || height
!= FRAME_PIXEL_HEIGHT (f
))
8570 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, height
);
8571 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, width
);
8573 x_set_window_size (f
, 0, columns
, rows
);
8578 /* Handle clicks in zoom box. Calculation of "standard state" based
8579 on code in IM - Window Manager A and code contributed by Ben
8580 Mesander. The standard state of an Emacs window is 80-characters
8581 wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */
8584 do_zoom_window (WindowPtr w
, int zoom_in_or_out
)
8587 Rect zoom_rect
, port_rect
;
8589 int w_title_height
, columns
, rows
, width
, height
;
8590 struct frame
*f
= mac_window_to_frame (w
);
8591 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
8593 #if TARGET_API_MAC_CARBON
8595 Point standard_size
;
8597 standard_size
.h
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
8598 standard_size
.v
= dpyinfo
->height
;
8600 if (IsWindowInStandardState (w
, &standard_size
, &zoom_rect
))
8601 zoom_in_or_out
= inZoomIn
;
8604 /* Adjust the standard size according to character boundaries. */
8606 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, zoom_rect
.right
- zoom_rect
.left
);
8607 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, zoom_rect
.bottom
- zoom_rect
.top
);
8608 standard_size
.h
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, columns
);
8609 standard_size
.v
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
8610 GetWindowBounds (w
, kWindowContentRgn
, &port_rect
);
8611 if (IsWindowInStandardState (w
, &standard_size
, &zoom_rect
)
8612 && port_rect
.left
== zoom_rect
.left
8613 && port_rect
.top
== zoom_rect
.top
)
8614 zoom_in_or_out
= inZoomIn
;
8616 zoom_in_or_out
= inZoomOut
;
8619 ZoomWindowIdeal (w
, zoom_in_or_out
, &standard_size
);
8621 #else /* not TARGET_API_MAC_CARBON */
8622 GetPort (&save_port
);
8624 SetPortWindowPort (w
);
8626 /* Clear window to avoid flicker. */
8627 EraseRect (&(w
->portRect
));
8628 if (zoom_in_or_out
== inZoomOut
)
8630 SetPt (&top_left
, w
->portRect
.left
, w
->portRect
.top
);
8631 LocalToGlobal (&top_left
);
8633 /* calculate height of window's title bar */
8634 w_title_height
= top_left
.v
- 1
8635 - (**((WindowPeek
) w
)->strucRgn
).rgnBBox
.top
+ GetMBarHeight ();
8637 /* get maximum height of window into zoom_rect.bottom - zoom_rect.top */
8638 zoom_rect
= qd
.screenBits
.bounds
;
8639 zoom_rect
.top
+= w_title_height
;
8640 InsetRect (&zoom_rect
, 8, 4); /* not too tight */
8642 zoom_rect
.right
= zoom_rect
.left
8643 + FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
8645 /* Adjust the standard size according to character boundaries. */
8646 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, zoom_rect
.bottom
- zoom_rect
.top
);
8648 zoom_rect
.top
+ FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
8650 (**((WStateDataHandle
) ((WindowPeek
) w
)->dataHandle
)).stdState
8654 ZoomWindow (w
, zoom_in_or_out
, f
== mac_focus_frame (dpyinfo
));
8656 SetPort (save_port
);
8657 #endif /* not TARGET_API_MAC_CARBON */
8659 /* retrieve window size and update application values */
8660 #if TARGET_API_MAC_CARBON
8661 GetWindowPortBounds (w
, &port_rect
);
8663 port_rect
= w
->portRect
;
8665 height
= port_rect
.bottom
- port_rect
.top
;
8666 width
= port_rect
.right
- port_rect
.left
;
8668 if (width
!= FRAME_PIXEL_WIDTH (f
)
8669 || height
!= FRAME_PIXEL_HEIGHT (f
))
8671 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, height
);
8672 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, width
);
8674 change_frame_size (f
, rows
, columns
, 0, 1, 0);
8675 SET_FRAME_GARBAGED (f
);
8676 cancel_mouse_face (f
);
8678 FRAME_PIXEL_WIDTH (f
) = width
;
8679 FRAME_PIXEL_HEIGHT (f
) = height
;
8681 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
8684 /* Intialize AppleEvent dispatcher table for the required events. */
8686 init_required_apple_events ()
8691 /* Make sure we have apple events before starting. */
8692 err
= Gestalt (gestaltAppleEventsAttr
, &result
);
8696 if (!(result
& (1 << gestaltAppleEventsPresent
)))
8699 #if TARGET_API_MAC_CARBON
8700 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenApplication
,
8701 NewAEEventHandlerUPP
8702 ((AEEventHandlerProcPtr
) do_ae_open_application
),
8705 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenApplication
,
8706 NewAEEventHandlerProc
8707 ((AEEventHandlerProcPtr
) do_ae_open_application
),
8713 #if TARGET_API_MAC_CARBON
8714 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenDocuments
,
8715 NewAEEventHandlerUPP
8716 ((AEEventHandlerProcPtr
) do_ae_open_documents
),
8719 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenDocuments
,
8720 NewAEEventHandlerProc
8721 ((AEEventHandlerProcPtr
) do_ae_open_documents
),
8727 #if TARGET_API_MAC_CARBON
8728 err
= AEInstallEventHandler(kCoreEventClass
, kAEPrintDocuments
,
8729 NewAEEventHandlerUPP
8730 ((AEEventHandlerProcPtr
) do_ae_print_documents
),
8733 err
= AEInstallEventHandler(kCoreEventClass
, kAEPrintDocuments
,
8734 NewAEEventHandlerProc
8735 ((AEEventHandlerProcPtr
) do_ae_print_documents
),
8741 #if TARGET_API_MAC_CARBON
8742 err
= AEInstallEventHandler(kCoreEventClass
, kAEQuitApplication
,
8743 NewAEEventHandlerUPP
8744 ((AEEventHandlerProcPtr
) do_ae_quit_application
),
8747 err
= AEInstallEventHandler(kCoreEventClass
, kAEQuitApplication
,
8748 NewAEEventHandlerProc
8749 ((AEEventHandlerProcPtr
) do_ae_quit_application
),
8757 mac_store_application_menu_event (event
)
8758 #if USE_CARBON_EVENTS
8764 struct input_event buf
;
8765 Lisp_Object frame
, entry
;
8769 XSETFRAME (frame
, mac_focus_frame (&one_mac_display_info
));
8770 buf
.kind
= MENU_BAR_EVENT
;
8771 buf
.frame_or_window
= frame
;
8773 kbd_buffer_store_event (&buf
);
8775 buf
.arg
= Qapplication
;
8776 kbd_buffer_store_event (&buf
);
8778 #if USE_CARBON_EVENTS
8779 switch (GetEventClass (event
))
8782 case kEventClassService
:
8783 buf
.arg
= Qservices
;
8784 kbd_buffer_store_event (&buf
);
8785 switch (GetEventKind (event
))
8787 case kEventServicePaste
:
8791 case kEventServicePerform
:
8794 CFStringRef message
;
8796 err
= GetEventParameter (event
, kEventParamServiceMessageName
,
8797 typeCFStringRef
, NULL
,
8798 sizeof (CFStringRef
), NULL
, &message
);
8800 kbd_buffer_store_event (&buf
);
8801 if (err
== noErr
&& message
)
8802 entry
= intern (SDATA (cfstring_to_lisp (message
)));
8812 #endif /* MAC_OSX */
8813 case kEventClassCommand
:
8817 GetEventParameter(event
, kEventParamDirectObject
, typeHICommand
,
8818 NULL
, sizeof (HICommand
), NULL
, &command
);
8819 switch (command
.commandID
)
8821 case kHICommandAbout
:
8825 case kHICommandPreferences
:
8826 entry
= Qpreferences
;
8828 #endif /* MAC_OSX */
8829 case kHICommandQuit
:
8841 #else /* USE_CARBON_EVENTS */
8844 case kHICommandAbout
:
8847 case kHICommandQuit
:
8856 kbd_buffer_store_event (&buf
);
8859 #if USE_CARBON_EVENTS
8860 static pascal OSStatus
8861 mac_handle_command_event (next_handler
, event
, data
)
8862 EventHandlerCallRef next_handler
;
8869 GetEventParameter(event
, kEventParamDirectObject
, typeHICommand
, NULL
,
8870 sizeof (HICommand
), NULL
, &command
);
8872 switch (command
.commandID
)
8874 case kHICommandAbout
:
8876 case kHICommandPreferences
:
8877 #endif /* MAC_OSX */
8878 result
= CallNextEventHandler (next_handler
, event
);
8879 if (result
!= eventNotHandledErr
)
8882 mac_store_application_menu_event (event
);
8889 return eventNotHandledErr
;
8893 init_command_handler ()
8896 EventTypeSpec specs
[] = {{kEventClassCommand
, kEventCommandProcess
}};
8897 static EventHandlerUPP handle_command_eventUPP
= NULL
;
8899 if (handle_command_eventUPP
== NULL
)
8900 handle_command_eventUPP
= NewEventHandlerUPP (mac_handle_command_event
);
8901 return InstallApplicationEventHandler (handle_command_eventUPP
,
8902 GetEventTypeCount (specs
), specs
,
8906 static pascal OSStatus
8907 mac_handle_window_event (next_handler
, event
, data
)
8908 EventHandlerCallRef next_handler
;
8915 XSizeHints
*size_hints
;
8917 GetEventParameter (event
, kEventParamDirectObject
, typeWindowRef
,
8918 NULL
, sizeof (WindowPtr
), NULL
, &wp
);
8920 switch (GetEventKind (event
))
8922 case kEventWindowUpdate
:
8923 result
= CallNextEventHandler (next_handler
, event
);
8924 if (result
!= eventNotHandledErr
)
8927 do_window_update (wp
);
8930 case kEventWindowBoundsChanging
:
8931 result
= CallNextEventHandler (next_handler
, event
);
8932 if (result
!= eventNotHandledErr
)
8935 GetEventParameter (event
, kEventParamAttributes
, typeUInt32
,
8936 NULL
, sizeof (UInt32
), NULL
, &attributes
);
8937 size_hints
= FRAME_SIZE_HINTS (mac_window_to_frame (wp
));
8938 if ((attributes
& kWindowBoundsChangeUserResize
)
8939 && ((size_hints
->flags
& (PResizeInc
| PBaseSize
| PMinSize
))
8940 == (PResizeInc
| PBaseSize
| PMinSize
)))
8945 GetEventParameter (event
, kEventParamCurrentBounds
,
8947 NULL
, sizeof (Rect
), NULL
, &bounds
);
8948 width
= bounds
.right
- bounds
.left
;
8949 height
= bounds
.bottom
- bounds
.top
;
8951 if (width
< size_hints
->min_width
)
8952 width
= size_hints
->min_width
;
8954 width
= size_hints
->base_width
8955 + (int) ((width
- size_hints
->base_width
)
8956 / (float) size_hints
->width_inc
+ .5)
8957 * size_hints
->width_inc
;
8959 if (height
< size_hints
->min_height
)
8960 height
= size_hints
->min_height
;
8962 height
= size_hints
->base_height
8963 + (int) ((height
- size_hints
->base_height
)
8964 / (float) size_hints
->height_inc
+ .5)
8965 * size_hints
->height_inc
;
8967 bounds
.right
= bounds
.left
+ width
;
8968 bounds
.bottom
= bounds
.top
+ height
;
8969 SetEventParameter (event
, kEventParamCurrentBounds
,
8970 typeQDRectangle
, sizeof (Rect
), &bounds
);
8975 case kEventWindowShown
:
8976 case kEventWindowHidden
:
8977 case kEventWindowExpanded
:
8978 case kEventWindowCollapsed
:
8979 result
= CallNextEventHandler (next_handler
, event
);
8981 mac_handle_visibility_change (mac_window_to_frame (wp
));
8987 return eventNotHandledErr
;
8990 static pascal OSStatus
8991 mac_handle_mouse_event (next_handler
, event
, data
)
8992 EventHandlerCallRef next_handler
;
8998 switch (GetEventKind (event
))
9000 case kEventMouseWheelMoved
:
9004 EventMouseWheelAxis axis
;
9008 result
= CallNextEventHandler (next_handler
, event
);
9009 if (result
!= eventNotHandledErr
|| read_socket_inev
== NULL
)
9012 GetEventParameter (event
, kEventParamWindowRef
, typeWindowRef
,
9013 NULL
, sizeof (WindowRef
), NULL
, &wp
);
9014 f
= mac_window_to_frame (wp
);
9015 if (f
!= mac_focus_frame (&one_mac_display_info
))
9018 GetEventParameter (event
, kEventParamMouseWheelAxis
,
9019 typeMouseWheelAxis
, NULL
,
9020 sizeof (EventMouseWheelAxis
), NULL
, &axis
);
9021 if (axis
!= kEventMouseWheelAxisY
)
9024 GetEventParameter (event
, kEventParamMouseWheelDelta
, typeSInt32
,
9025 NULL
, sizeof (SInt32
), NULL
, &delta
);
9026 GetEventParameter (event
, kEventParamMouseLocation
, typeQDPoint
,
9027 NULL
, sizeof (Point
), NULL
, &point
);
9028 read_socket_inev
->kind
= WHEEL_EVENT
;
9029 read_socket_inev
->code
= 0;
9030 read_socket_inev
->modifiers
=
9031 (mac_event_to_emacs_modifiers (event
)
9032 | ((delta
< 0) ? down_modifier
: up_modifier
));
9033 SetPortWindowPort (wp
);
9034 GlobalToLocal (&point
);
9035 XSETINT (read_socket_inev
->x
, point
.h
);
9036 XSETINT (read_socket_inev
->y
, point
.v
);
9037 XSETFRAME (read_socket_inev
->frame_or_window
, f
);
9047 return eventNotHandledErr
;
9049 #endif /* USE_CARBON_EVENTS */
9053 install_window_handler (window
)
9057 #if USE_CARBON_EVENTS
9058 EventTypeSpec specs_window
[] =
9059 {{kEventClassWindow
, kEventWindowUpdate
},
9060 {kEventClassWindow
, kEventWindowBoundsChanging
},
9061 {kEventClassWindow
, kEventWindowShown
},
9062 {kEventClassWindow
, kEventWindowHidden
},
9063 {kEventClassWindow
, kEventWindowExpanded
},
9064 {kEventClassWindow
, kEventWindowCollapsed
}};
9065 EventTypeSpec specs_mouse
[] = {{kEventClassMouse
, kEventMouseWheelMoved
}};
9066 static EventHandlerUPP handle_window_eventUPP
= NULL
;
9067 static EventHandlerUPP handle_mouse_eventUPP
= NULL
;
9069 if (handle_window_eventUPP
== NULL
)
9070 handle_window_eventUPP
= NewEventHandlerUPP (mac_handle_window_event
);
9071 if (handle_mouse_eventUPP
== NULL
)
9072 handle_mouse_eventUPP
= NewEventHandlerUPP (mac_handle_mouse_event
);
9073 err
= InstallWindowEventHandler (window
, handle_window_eventUPP
,
9074 GetEventTypeCount (specs_window
),
9075 specs_window
, NULL
, NULL
);
9077 err
= InstallWindowEventHandler (window
, handle_mouse_eventUPP
,
9078 GetEventTypeCount (specs_mouse
),
9079 specs_mouse
, NULL
, NULL
);
9081 #if TARGET_API_MAC_CARBON
9082 if (mac_do_track_dragUPP
== NULL
)
9083 mac_do_track_dragUPP
= NewDragTrackingHandlerUPP (mac_do_track_drag
);
9084 if (mac_do_receive_dragUPP
== NULL
)
9085 mac_do_receive_dragUPP
= NewDragReceiveHandlerUPP (mac_do_receive_drag
);
9088 err
= InstallTrackingHandler (mac_do_track_dragUPP
, window
, NULL
);
9090 err
= InstallReceiveHandler (mac_do_receive_dragUPP
, window
, NULL
);
9096 remove_window_handler (window
)
9099 #if TARGET_API_MAC_CARBON
9100 if (mac_do_track_dragUPP
)
9101 RemoveTrackingHandler (mac_do_track_dragUPP
, window
);
9102 if (mac_do_receive_dragUPP
)
9103 RemoveReceiveHandler (mac_do_receive_dragUPP
, window
);
9107 /* Open Application Apple Event */
9109 do_ae_open_application(const AppleEvent
*pae
, AppleEvent
*preply
, long prefcon
)
9115 /* Called when we receive an AppleEvent with an ID of
9116 "kAEOpenDocuments". This routine gets the direct parameter,
9117 extracts the FSSpecs in it, and puts their names on a list. */
9118 #pragma options align=mac68k
9119 typedef struct SelectionRange
{
9120 short unused1
; // 0 (not used)
9121 short lineNum
; // line to select (<0 to specify range)
9122 long startRange
; // start of selection range (if line < 0)
9123 long endRange
; // end of selection range (if line < 0)
9124 long unused2
; // 0 (not used)
9125 long theDate
; // modification date/time
9127 #pragma options align=reset
9130 do_ae_open_documents(AppleEvent
*message
, AppleEvent
*reply
, long refcon
)
9135 DescType actual_type
;
9137 SelectionRange position
;
9138 Lisp_Object file_list
= Qnil
;
9140 xassert (read_socket_inev
);
9142 err
= AEGetParamDesc (message
, keyDirectObject
, typeAEList
, &the_desc
);
9144 goto descriptor_error_exit
;
9146 err
= AEGetParamPtr (message
, keyAEPosition
, typeChar
, &actual_type
, &position
, sizeof(SelectionRange
), &actual_size
);
9148 file_list
= Fcons (list3 (make_number (position
.lineNum
+ 1),
9149 make_number (position
.startRange
+ 1),
9150 make_number (position
.endRange
+ 1)),
9153 /* Check to see that we got all of the required parameters from the
9154 event descriptor. For an 'odoc' event this should just be the
9156 err
= AEGetAttributePtr(message
, keyMissedKeywordAttr
, typeWildCard
,
9157 &actual_type
, (Ptr
) &keyword
,
9158 sizeof (keyword
), &actual_size
);
9159 /* No error means that we found some unused parameters.
9160 errAEDescNotFound means that there are no more parameters. If we
9161 get an error code other than that, flag it. */
9162 if ((err
== noErr
) || (err
!= errAEDescNotFound
))
9164 err
= errAEEventNotHandled
;
9169 /* Got all the parameters we need. Now, go through the direct
9170 object list and parse it up. */
9172 long num_files_to_open
;
9174 err
= AECountItems (&the_desc
, &num_files_to_open
);
9179 /* AE file list is one based so just use that for indexing here. */
9180 for (i
= 1; i
<= num_files_to_open
; i
++)
9182 char unix_path_name
[MAXPATHLEN
];
9186 err
= AEGetNthPtr (&the_desc
, i
, typeFSRef
, &keyword
,
9187 &actual_type
, &fref
, sizeof (FSRef
),
9189 if (err
!= noErr
|| actual_type
!= typeFSRef
)
9192 if (FSRefMakePath (&fref
, unix_path_name
, sizeof (unix_path_name
))
9197 err
= AEGetNthPtr(&the_desc
, i
, typeFSS
, &keyword
, &actual_type
,
9198 (Ptr
) &fs
, sizeof (fs
), &actual_size
);
9199 if (err
!= noErr
) continue;
9201 if (fsspec_to_posix_pathname (&fs
, unix_path_name
,
9202 sizeof (unix_path_name
) - 1) == noErr
)
9204 /* x-dnd functions expect undecoded filenames. */
9205 file_list
= Fcons (make_unibyte_string (unix_path_name
,
9206 strlen (unix_path_name
)),
9211 /* Build a DRAG_N_DROP_EVENT type event as is done in
9212 constuct_drag_n_drop in w32term.c. */
9213 if (!NILP (file_list
))
9215 struct frame
*f
= mac_focus_frame (&one_mac_display_info
);
9219 read_socket_inev
->kind
= DRAG_N_DROP_EVENT
;
9220 read_socket_inev
->code
= 0;
9221 read_socket_inev
->modifiers
= 0;
9223 XSETINT (read_socket_inev
->x
, 0);
9224 XSETINT (read_socket_inev
->y
, 0);
9226 XSETFRAME (frame
, f
);
9227 read_socket_inev
->frame_or_window
= Fcons (frame
, file_list
);
9230 /* Regardless of whether Emacs was suspended or in the
9231 foreground, ask it to redraw its entire screen. Otherwise
9232 parts of the screen can be left in an inconsistent
9234 wp
= FRAME_MAC_WINDOW (f
);
9236 #if TARGET_API_MAC_CARBON
9240 GetWindowPortBounds (wp
, &r
);
9241 InvalWindowRect (wp
, &r
);
9243 #else /* not TARGET_API_MAC_CARBON */
9244 InvalRect (&(wp
->portRect
));
9245 #endif /* not TARGET_API_MAC_CARBON */
9251 /* Nuke the coerced file list in any case */
9252 err2
= AEDisposeDesc(&the_desc
);
9254 descriptor_error_exit
:
9255 /* InvalRect(&(gFrontMacWindowP->mWP->portRect)); */
9260 #if TARGET_API_MAC_CARBON
9262 mac_do_track_drag (DragTrackingMessage message
, WindowPtr window
,
9263 void *handlerRefCon
, DragReference theDrag
)
9265 static int can_accept
;
9268 ItemReference theItem
;
9269 FlavorFlags theFlags
;
9272 if (GetFrontWindowOfClass (kMovableModalWindowClass
, false))
9273 return dragNotAcceptedErr
;
9277 case kDragTrackingEnterHandler
:
9278 CountDragItems (theDrag
, &items
);
9280 for (index
= 1; index
<= items
; index
++)
9282 GetDragItemReferenceNumber (theDrag
, index
, &theItem
);
9283 result
= GetFlavorFlags (theDrag
, theItem
, flavorTypeHFS
, &theFlags
);
9284 if (result
== noErr
)
9292 case kDragTrackingEnterWindow
:
9295 RgnHandle hilite_rgn
= NewRgn ();
9297 struct frame
*f
= mac_window_to_frame (window
);
9299 GetWindowPortBounds (window
, &r
);
9300 OffsetRect (&r
, -r
.left
, -r
.top
);
9301 RectRgn (hilite_rgn
, &r
);
9302 ShowDragHilite (theDrag
, hilite_rgn
, true);
9303 DisposeRgn (hilite_rgn
);
9304 SetThemeCursor (kThemeCopyArrowCursor
);
9308 case kDragTrackingInWindow
:
9311 case kDragTrackingLeaveWindow
:
9314 struct frame
*f
= mac_window_to_frame (window
);
9316 HideDragHilite (theDrag
);
9317 SetThemeCursor (kThemeArrowCursor
);
9321 case kDragTrackingLeaveHandler
:
9329 mac_do_receive_drag (WindowPtr window
, void *handlerRefCon
,
9330 DragReference theDrag
)
9334 FlavorFlags theFlags
;
9337 ItemReference theItem
;
9339 Size size
= sizeof (HFSFlavor
);
9340 Lisp_Object file_list
;
9342 if (GetFrontWindowOfClass (kMovableModalWindowClass
, false))
9343 return dragNotAcceptedErr
;
9346 GetDragMouse (theDrag
, &mouse
, 0L);
9347 CountDragItems (theDrag
, &items
);
9348 for (index
= 1; index
<= items
; index
++)
9350 /* Only handle file references. */
9351 GetDragItemReferenceNumber (theDrag
, index
, &theItem
);
9352 result
= GetFlavorFlags (theDrag
, theItem
, flavorTypeHFS
, &theFlags
);
9353 if (result
== noErr
)
9358 char unix_path_name
[MAXPATHLEN
];
9360 GetFlavorData (theDrag
, theItem
, flavorTypeHFS
, &data
, &size
, 0L);
9362 /* Use Carbon routines, otherwise it converts the file name
9363 to /Macintosh HD/..., which is not correct. */
9364 FSpMakeFSRef (&data
.fileSpec
, &fref
);
9365 if (! FSRefMakePath (&fref
, unix_path_name
, sizeof (unix_path_name
)));
9367 if (fsspec_to_posix_pathname (&data
.fileSpec
, unix_path_name
,
9368 sizeof (unix_path_name
) - 1) == noErr
)
9370 /* x-dnd functions expect undecoded filenames. */
9371 file_list
= Fcons (make_unibyte_string (unix_path_name
,
9372 strlen (unix_path_name
)),
9376 /* If there are items in the list, construct an event and post it to
9377 the queue like an interrupt using kbd_buffer_store_event. */
9378 if (!NILP (file_list
))
9380 struct input_event event
;
9382 struct frame
*f
= mac_window_to_frame (window
);
9385 GlobalToLocal (&mouse
);
9386 GetDragModifiers (theDrag
, NULL
, NULL
, &modifiers
);
9388 event
.kind
= DRAG_N_DROP_EVENT
;
9390 event
.modifiers
= mac_to_emacs_modifiers (modifiers
);
9391 event
.timestamp
= TickCount () * (1000 / 60);
9392 XSETINT (event
.x
, mouse
.h
);
9393 XSETINT (event
.y
, mouse
.v
);
9394 XSETFRAME (frame
, f
);
9395 event
.frame_or_window
= Fcons (frame
, file_list
);
9397 /* Post to the interrupt queue */
9398 kbd_buffer_store_event (&event
);
9399 /* MAC_TODO: Mimic behavior of windows by switching contexts to Emacs */
9401 ProcessSerialNumber psn
;
9402 GetCurrentProcess (&psn
);
9403 SetFrontProcess (&psn
);
9409 return dragNotAcceptedErr
;
9414 /* Print Document Apple Event */
9416 do_ae_print_documents (const AppleEvent
*pAE
, AppleEvent
*reply
, long refcon
)
9418 return errAEEventNotHandled
;
9423 do_ae_quit_application (AppleEvent
* message
, AppleEvent
*reply
, long refcon
)
9425 #if USE_CARBON_EVENTS
9427 EventRef event
= NULL
;
9428 static const HICommand quit_command
= {kEventAttributeNone
, kHICommandQuit
};
9430 err
= CreateEvent (NULL
, kEventClassCommand
, kEventCommandProcess
, 0,
9431 kEventAttributeUserEvent
, &event
);
9433 err
= SetEventParameter (event
, kEventParamDirectObject
, typeHICommand
,
9434 sizeof (HICommand
), &quit_command
);
9436 mac_store_application_menu_event (event
);
9438 ReleaseEvent (event
);
9443 return errAEEventNotHandled
;
9445 mac_store_application_menu_event (kHICommandQuit
);
9454 profiler_exit_proc ()
9456 ProfilerDump ("\pEmacs.prof");
9461 /* These few functions implement Emacs as a normal Mac application
9462 (almost): set up the heap and the Toolbox, handle necessary system
9463 events plus a few simple menu events. They also set up Emacs's
9464 access to functions defined in the rest of this file. Emacs uses
9465 function hooks to perform all its terminal I/O. A complete list of
9466 these functions appear in termhooks.h. For what they do, read the
9467 comments there and see also w32term.c and xterm.c. What's
9468 noticeably missing here is the event loop, which is normally
9469 present in most Mac application. After performing the necessary
9470 Mac initializations, main passes off control to emacs_main
9471 (corresponding to main in emacs.c). Emacs_main calls XTread_socket
9472 (defined further below) to read input. This is where
9473 WaitNextEvent/ReceiveNextEvent is called to process Mac events. */
9480 #if __profile__ /* is the profiler on? */
9481 if (ProfilerInit(collectDetailed
, bestTimeBase
, 5000, 200))
9486 /* set creator and type for files created by MSL */
9491 do_init_managers ();
9496 do_check_ram_size ();
9499 init_emacs_passwd_dir ();
9503 initialize_applescript ();
9505 init_required_apple_events ();
9511 /* set up argv array from STR# resource */
9512 get_string_list (&argv
, ARGV_STRING_LIST_ID
);
9516 /* free up AppleScript resources on exit */
9517 atexit (terminate_applescript
);
9519 #if __profile__ /* is the profiler on? */
9520 atexit (profiler_exit_proc
);
9523 /* 3rd param "envp" never used in emacs_main */
9524 (void) emacs_main (argc
, argv
, 0);
9527 /* Never reached - real exit in Fkill_emacs */
9532 /* Table for translating Mac keycode to X keysym values. Contributed
9534 Mapping for special keys is now identical to that in Apple X11
9535 except `clear' (-> <clear>) on the KeyPad, `enter' (-> <kp-enter>)
9536 on the right of the Cmd key on laptops, and fn + `enter' (->
9538 static unsigned char keycode_to_xkeysym_table
[] = {
9539 /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9540 /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9541 /*0x20*/ 0, 0, 0, 0, 0x0d /*return*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9543 /*0x30*/ 0x09 /*tab*/, 0 /*0x0020 space*/, 0, 0x08 /*backspace*/,
9544 /*0x34*/ 0x8d /*enter on laptops*/, 0x1b /*escape*/, 0, 0,
9545 /*0x38*/ 0, 0, 0, 0,
9546 /*0x3C*/ 0, 0, 0, 0,
9548 /*0x40*/ 0, 0xae /*kp-.*/, 0, 0xaa /*kp-**/,
9549 /*0x44*/ 0, 0xab /*kp-+*/, 0, 0x0b /*clear*/,
9550 /*0x48*/ 0, 0, 0, 0xaf /*kp-/*/,
9551 /*0x4C*/ 0x8d /*kp-enter*/, 0, 0xad /*kp--*/, 0,
9553 /*0x50*/ 0, 0xbd /*kp-=*/, 0xb0 /*kp-0*/, 0xb1 /*kp-1*/,
9554 /*0x54*/ 0xb2 /*kp-2*/, 0xb3 /*kp-3*/, 0xb4 /*kp-4*/, 0xb5 /*kp-5*/,
9555 /*0x58*/ 0xb6 /*kp-6*/, 0xb7 /*kp-7*/, 0, 0xb8 /*kp-8*/,
9556 /*0x5C*/ 0xb9 /*kp-9*/, 0, 0, 0,
9558 /*0x60*/ 0xc2 /*f5*/, 0xc3 /*f6*/, 0xc4 /*f7*/, 0xc0 /*f3*/,
9559 /*0x64*/ 0xc5 /*f8*/, 0xc6 /*f9*/, 0, 0xc8 /*f11*/,
9560 /*0x68*/ 0, 0xca /*f13*/, 0, 0xcb /*f14*/,
9561 /*0x6C*/ 0, 0xc7 /*f10*/, 0x0a /*fn+enter on laptops*/, 0xc9 /*f12*/,
9563 /*0x70*/ 0, 0xcc /*f15*/, 0x6a /*help*/, 0x50 /*home*/,
9564 /*0x74*/ 0x55 /*pgup*/, 0xff /*delete*/, 0xc1 /*f4*/, 0x57 /*end*/,
9565 /*0x78*/ 0xbf /*f2*/, 0x56 /*pgdown*/, 0xbe /*f1*/, 0x51 /*left*/,
9566 /*0x7C*/ 0x53 /*right*/, 0x54 /*down*/, 0x52 /*up*/, 0
9571 keycode_to_xkeysym (int keyCode
, int *xKeySym
)
9573 *xKeySym
= keycode_to_xkeysym_table
[keyCode
& 0x7f];
9574 return *xKeySym
!= 0;
9577 static unsigned char fn_keycode_to_xkeysym_table
[] = {
9578 /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9579 /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9580 /*0x20*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9582 /*0x30*/ 0, 0, 0, 0,
9583 /*0x34*/ 0, 0, 0, 0,
9584 /*0x38*/ 0, 0, 0, 0,
9585 /*0x3C*/ 0, 0, 0, 0,
9587 /*0x40*/ 0, 0x2e /*kp-. = .*/, 0, 0x50 /*kp-* = 'p'*/,
9588 /*0x44*/ 0, '/' /*kp-+*/, 0, 0,
9589 /*0x48*/ 0, 0, 0, 0x30 /*kp-/ = '0'*/,
9590 /*0x4C*/ 0, 0, 0x3b /*kp-- = ';'*/, 0,
9592 /*0x50*/ 0, 0x2d /*kp-= = '-'*/, 0x6d /*kp-0 = 'm'*/, 0x6a /*kp-1 = 'j'*/,
9593 /*0x54*/ 0x6b /*kp-2 = 'k'*/, 0x6c /*kp-3 = 'l'*/, 'u' /*kp-4*/, 'i' /*kp-5*/,
9594 /*0x58*/ 'o' /*kp-6*/, '7' /*kp-7*/, 0, '8' /*kp-8*/,
9595 /*0x5C*/ '9' /*kp-9*/, 0, 0, 0,
9597 /*0x60*/ 0, 0, 0, 0,
9598 /*0x64*/ 0, 0, 0, 0,
9599 /*0x68*/ 0, 0, 0, 0,
9600 /*0x6C*/ 0, 0, 0, 0,
9602 /*0x70*/ 0, 0, 0, 0,
9603 /*0x74*/ 0, 0, 0, 0,
9604 /*0x78*/ 0, 0, 0, 0,
9608 convert_fn_keycode (EventRef eventRef
, int keyCode
, int *newCode
)
9611 /* Use the special map to translate keys when function modifier is
9612 to be caught. KeyTranslate can't be used in that case.
9613 We can't detect the function key using the input_event.modifiers,
9614 because this uses the high word of an UInt32. Therefore,
9615 we'll just read it out of the original eventRef.
9619 /* TODO / known issues
9621 - Fn-Shift-j is regonized as Fn-j and not Fn-J.
9622 The above table always translates to lower characters. We need to use
9623 the KCHR keyboard resource (KeyTranslate() ) to map k->K and 8->*.
9625 - The table is meant for English language keyboards, and it will work
9626 for many others with the exception of key combinations like Fn-ö on
9627 a German keyboard, which is currently mapped to Fn-;.
9628 How to solve this without keeping separate tables for all keyboards
9629 around? KeyTranslate isn't of much help here, as it only takes a 16-bit
9630 value for keycode with the modifiers in he high byte, i.e. no room for the
9631 Fn modifier. That's why we need the table.
9636 if (!NILP(Vmac_function_modifier
))
9638 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
9639 sizeof (UInt32
), NULL
, &mods
);
9640 if (mods
& kEventKeyModifierFnMask
)
9641 { *newCode
= fn_keycode_to_xkeysym_table
[keyCode
& 0x7f];
9643 return (*newCode
!= 0);
9651 backtranslate_modified_keycode(int mods
, int keycode
, int def
)
9655 (NILP (Vmac_option_modifier
) ? 0 : optionKey
) |
9658 /* This code comes from Keyboard Resource,
9659 Appendix C of IM - Text. This is necessary
9660 since shift is ignored in KCHR table
9661 translation when option or command is pressed.
9662 It also does not translate correctly
9663 control-shift chars like C-% so mask off shift
9666 Not done for combinations with the option key (alt)
9667 unless it is to be caught by Emacs: this is
9668 to preserve key combinations translated by the OS
9671 /* mask off option and command */
9672 int new_modifiers
= mods
& 0xe600;
9673 /* set high byte of keycode to modifier high byte*/
9674 int new_keycode
= keycode
| new_modifiers
;
9675 Ptr kchr_ptr
= (Ptr
) GetScriptManagerVariable (smKCHRCache
);
9676 unsigned long some_state
= 0;
9677 return (int) KeyTranslate (kchr_ptr
, new_keycode
,
9678 &some_state
) & 0xff;
9679 /* TO DO: Recognize two separate resulting characters, "for
9680 example, when the user presses Option-E followed by N, you
9681 can map this through the KeyTranslate function using the
9682 U.S. 'KCHR' resource to produce ´n, which KeyTranslate
9683 returns as two characters in the bytes labeled Character code
9684 1 and Character code 2." (from Carbon API doc) */
9692 #if !USE_CARBON_EVENTS
9693 static RgnHandle mouse_region
= NULL
;
9696 mac_wait_next_event (er
, sleep_time
, dequeue
)
9701 static EventRecord er_buf
= {nullEvent
};
9702 UInt32 target_tick
, current_tick
;
9703 EventMask event_mask
;
9705 if (mouse_region
== NULL
)
9706 mouse_region
= NewRgn ();
9708 event_mask
= everyEvent
;
9709 if (NILP (Fboundp (Qmac_ready_for_drag_n_drop
)))
9710 event_mask
-= highLevelEventMask
;
9712 current_tick
= TickCount ();
9713 target_tick
= current_tick
+ sleep_time
;
9715 if (er_buf
.what
== nullEvent
)
9716 while (!WaitNextEvent (event_mask
, &er_buf
,
9717 target_tick
- current_tick
, mouse_region
))
9719 current_tick
= TickCount ();
9720 if (target_tick
<= current_tick
)
9726 er_buf
.what
= nullEvent
;
9729 #endif /* not USE_CARBON_EVENTS */
9731 /* Emacs calls this whenever it wants to read an input event from the
9734 XTread_socket (sd
, expected
, hold_quit
)
9736 struct input_event
*hold_quit
;
9738 struct input_event inev
;
9740 #if USE_CARBON_EVENTS
9742 EventTargetRef toolbox_dispatcher
;
9745 struct mac_display_info
*dpyinfo
= &one_mac_display_info
;
9747 if (interrupt_input_blocked
)
9749 interrupt_input_pending
= 1;
9753 interrupt_input_pending
= 0;
9756 /* So people can tell when we have read the available input. */
9757 input_signal_count
++;
9759 #if USE_CARBON_EVENTS
9760 toolbox_dispatcher
= GetEventDispatcherTarget ();
9762 while (!ReceiveNextEvent (0, NULL
, kEventDurationNoWait
,
9763 kEventRemoveFromQueue
, &eventRef
))
9764 #else /* !USE_CARBON_EVENTS */
9765 while (mac_wait_next_event (&er
, 0, true))
9766 #endif /* !USE_CARBON_EVENTS */
9770 unsigned long timestamp
;
9772 /* It is necessary to set this (additional) argument slot of an
9773 event to nil because keyboard.c protects incompletely
9774 processed event from being garbage collected by placing them
9775 in the kbd_buffer_gcpro vector. */
9777 inev
.kind
= NO_EVENT
;
9780 #if USE_CARBON_EVENTS
9781 timestamp
= GetEventTime (eventRef
) / kEventDurationMillisecond
;
9783 timestamp
= er
.when
* (1000 / 60); /* ticks to milliseconds */
9786 #if USE_CARBON_EVENTS
9787 /* Handle new events */
9788 if (!mac_convert_event_ref (eventRef
, &er
))
9790 /* There used to be a handler for the kEventMouseWheelMoved
9791 event here. But as of Mac OS X 10.4, this kind of event
9792 is not directly posted to the main event queue by
9793 two-finger scrolling on the trackpad. Instead, some
9794 private event is posted and it is converted to a wheel
9795 event by the default handler for the application target.
9796 The converted one can be received by a Carbon event
9797 handler installed on a window target. */
9798 read_socket_inev
= &inev
;
9799 SendEventToEventTarget (eventRef
, toolbox_dispatcher
);
9800 read_socket_inev
= NULL
;
9803 #endif /* USE_CARBON_EVENTS */
9809 WindowPtr window_ptr
;
9810 ControlPartCode part_code
;
9813 #if USE_CARBON_EVENTS
9814 /* This is needed to send mouse events like aqua window
9815 buttons to the correct handler. */
9816 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
9817 != eventNotHandledErr
)
9820 last_mouse_glyph_frame
= 0;
9822 if (dpyinfo
->grabbed
&& last_mouse_frame
9823 && FRAME_LIVE_P (last_mouse_frame
))
9825 window_ptr
= FRAME_MAC_WINDOW (last_mouse_frame
);
9826 part_code
= inContent
;
9830 part_code
= FindWindow (er
.where
, &window_ptr
);
9831 if (tip_window
&& window_ptr
== tip_window
)
9833 HideWindow (tip_window
);
9834 part_code
= FindWindow (er
.where
, &window_ptr
);
9838 if (er
.what
!= mouseDown
&&
9839 (part_code
!= inContent
|| dpyinfo
->grabbed
== 0))
9845 f
= mac_focus_frame (dpyinfo
);
9846 saved_menu_event_location
= er
.where
;
9847 inev
.kind
= MENU_BAR_ACTIVATE_EVENT
;
9848 XSETFRAME (inev
.frame_or_window
, f
);
9852 if (window_ptr
!= FRAME_MAC_WINDOW (mac_focus_frame (dpyinfo
)))
9853 SelectWindow (window_ptr
);
9856 ControlPartCode control_part_code
;
9858 Point mouse_loc
= er
.where
;
9860 ControlKind control_kind
;
9863 f
= mac_window_to_frame (window_ptr
);
9864 /* convert to local coordinates of new window */
9865 SetPortWindowPort (window_ptr
);
9867 GlobalToLocal (&mouse_loc
);
9868 #if TARGET_API_MAC_CARBON
9869 ch
= FindControlUnderMouse (mouse_loc
, window_ptr
,
9870 &control_part_code
);
9873 GetControlKind (ch
, &control_kind
);
9876 control_part_code
= FindControl (mouse_loc
, window_ptr
,
9880 #if USE_CARBON_EVENTS
9881 inev
.code
= mac_get_mouse_btn (eventRef
);
9882 inev
.modifiers
= mac_event_to_emacs_modifiers (eventRef
);
9884 inev
.code
= mac_get_emulated_btn (er
.modifiers
);
9885 inev
.modifiers
= mac_to_emacs_modifiers (er
.modifiers
);
9887 XSETINT (inev
.x
, mouse_loc
.h
);
9888 XSETINT (inev
.y
, mouse_loc
.v
);
9890 if (dpyinfo
->grabbed
&& tracked_scroll_bar
9892 #ifndef USE_TOOLKIT_SCROLL_BARS
9893 /* control_part_code becomes kControlNoPart if
9894 a progress indicator is clicked. */
9895 && control_part_code
!= kControlNoPart
9896 #else /* USE_TOOLKIT_SCROLL_BARS */
9898 && control_kind
.kind
== kControlKindScrollBar
9899 #endif /* MAC_OSX */
9900 #endif /* USE_TOOLKIT_SCROLL_BARS */
9903 struct scroll_bar
*bar
;
9905 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
9907 bar
= tracked_scroll_bar
;
9908 #ifndef USE_TOOLKIT_SCROLL_BARS
9909 control_part_code
= kControlIndicatorPart
;
9913 bar
= (struct scroll_bar
*) GetControlReference (ch
);
9914 #ifdef USE_TOOLKIT_SCROLL_BARS
9915 /* Make the "Ctrl-Mouse-2 splits window" work
9916 for toolkit scroll bars. */
9917 if (er
.modifiers
& controlKey
)
9918 x_scroll_bar_handle_click (bar
, control_part_code
,
9920 else if (er
.what
== mouseDown
)
9921 x_scroll_bar_handle_press (bar
, control_part_code
,
9924 x_scroll_bar_handle_release (bar
, &inev
);
9925 #else /* not USE_TOOLKIT_SCROLL_BARS */
9926 x_scroll_bar_handle_click (bar
, control_part_code
,
9928 if (er
.what
== mouseDown
9929 && control_part_code
== kControlIndicatorPart
)
9930 tracked_scroll_bar
= bar
;
9932 tracked_scroll_bar
= NULL
;
9933 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9938 int x
= mouse_loc
.h
;
9939 int y
= mouse_loc
.v
;
9941 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
9942 if (EQ (window
, f
->tool_bar_window
))
9944 if (er
.what
== mouseDown
)
9945 handle_tool_bar_click (f
, x
, y
, 1, 0);
9947 handle_tool_bar_click (f
, x
, y
, 0,
9953 XSETFRAME (inev
.frame_or_window
, f
);
9954 inev
.kind
= MOUSE_CLICK_EVENT
;
9958 if (er
.what
== mouseDown
)
9960 dpyinfo
->grabbed
|= (1 << inev
.code
);
9961 last_mouse_frame
= f
;
9964 last_tool_bar_item
= -1;
9968 if ((dpyinfo
->grabbed
& (1 << inev
.code
)) == 0)
9969 /* If a button is released though it was not
9970 previously pressed, that would be because
9971 of multi-button emulation. */
9972 dpyinfo
->grabbed
= 0;
9974 dpyinfo
->grabbed
&= ~(1 << inev
.code
);
9977 /* Ignore any mouse motion that happened before
9978 this event; any subsequent mouse-movement Emacs
9979 events should reflect only motion after the
9984 #ifdef USE_TOOLKIT_SCROLL_BARS
9985 if (inev
.kind
== MOUSE_CLICK_EVENT
)
9990 inev
.modifiers
|= down_modifier
;
9993 inev
.modifiers
|= up_modifier
;
10000 #if TARGET_API_MAC_CARBON
10001 DragWindow (window_ptr
, er
.where
, NULL
);
10002 #else /* not TARGET_API_MAC_CARBON */
10003 DragWindow (window_ptr
, er
.where
, &qd
.screenBits
.bounds
);
10004 #endif /* not TARGET_API_MAC_CARBON */
10005 /* Update the frame parameters. */
10007 struct frame
*f
= mac_window_to_frame (window_ptr
);
10009 if (f
&& !f
->async_iconified
)
10010 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
10015 if (TrackGoAway (window_ptr
, er
.where
))
10017 inev
.kind
= DELETE_WINDOW_EVENT
;
10018 XSETFRAME (inev
.frame_or_window
,
10019 mac_window_to_frame (window_ptr
));
10023 /* window resize handling added --ben */
10025 do_grow_window (window_ptr
, &er
);
10028 /* window zoom handling added --ben */
10031 if (TrackBox (window_ptr
, er
.where
, part_code
))
10032 do_zoom_window (window_ptr
, part_code
);
10042 #if USE_CARBON_EVENTS
10043 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
10044 != eventNotHandledErr
)
10047 do_window_update ((WindowPtr
) er
.message
);
10052 #if USE_CARBON_EVENTS
10053 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
10054 != eventNotHandledErr
)
10057 switch ((er
.message
>> 24) & 0x000000FF)
10059 case suspendResumeMessage
:
10060 if ((er
.message
& resumeFlag
) == 1)
10066 case mouseMovedMessage
:
10067 #if !USE_CARBON_EVENTS
10068 SetRectRgn (mouse_region
, er
.where
.h
, er
.where
.v
,
10069 er
.where
.h
+ 1, er
.where
.v
+ 1);
10071 previous_help_echo_string
= help_echo_string
;
10072 help_echo_string
= Qnil
;
10074 if (dpyinfo
->grabbed
&& last_mouse_frame
10075 && FRAME_LIVE_P (last_mouse_frame
))
10076 f
= last_mouse_frame
;
10078 f
= dpyinfo
->x_focus_frame
;
10080 if (dpyinfo
->mouse_face_hidden
)
10082 dpyinfo
->mouse_face_hidden
= 0;
10083 clear_mouse_face (dpyinfo
);
10088 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
10089 Point mouse_pos
= er
.where
;
10091 SetPortWindowPort (wp
);
10093 GlobalToLocal (&mouse_pos
);
10095 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
10096 #ifdef USE_TOOLKIT_SCROLL_BARS
10097 x_scroll_bar_handle_drag (wp
, tracked_scroll_bar
,
10099 #else /* not USE_TOOLKIT_SCROLL_BARS */
10100 x_scroll_bar_note_movement (tracked_scroll_bar
,
10102 - XINT (tracked_scroll_bar
->top
),
10103 er
.when
* (1000 / 60));
10104 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10107 /* Generate SELECT_WINDOW_EVENTs when needed. */
10108 if (mouse_autoselect_window
)
10110 Lisp_Object window
;
10112 window
= window_from_coordinates (f
,
10117 /* Window will be selected only when it is
10118 not selected now and last mouse movement
10119 event was not in it. Minibuffer window
10120 will be selected iff it is active. */
10121 if (WINDOWP (window
)
10122 && !EQ (window
, last_window
)
10123 && !EQ (window
, selected_window
))
10125 inev
.kind
= SELECT_WINDOW_EVENT
;
10126 inev
.frame_or_window
= window
;
10129 last_window
=window
;
10131 if (!note_mouse_movement (f
, &mouse_pos
))
10132 help_echo_string
= previous_help_echo_string
;
10136 /* If the contents of the global variable
10137 help_echo_string has changed, generate a
10139 if (!NILP (help_echo_string
) || !NILP (previous_help_echo_string
))
10147 WindowPtr window_ptr
= (WindowPtr
) er
.message
;
10149 #if USE_CARBON_EVENTS
10150 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
10151 != eventNotHandledErr
)
10154 if (window_ptr
== tip_window
)
10156 HideWindow (tip_window
);
10160 if (!is_emacs_window (window_ptr
))
10163 if ((er
.modifiers
& activeFlag
) != 0)
10165 /* A window has been activated */
10166 Point mouse_loc
= er
.where
;
10168 x_detect_focus_change (dpyinfo
, &er
, &inev
);
10170 SetPortWindowPort (window_ptr
);
10171 GlobalToLocal (&mouse_loc
);
10172 /* Window-activated event counts as mouse movement,
10173 so update things that depend on mouse position. */
10174 note_mouse_movement (mac_window_to_frame (window_ptr
),
10179 /* A window has been deactivated */
10180 #if USE_TOOLKIT_SCROLL_BARS
10181 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
10183 struct input_event event
;
10185 EVENT_INIT (event
);
10186 event
.kind
= NO_EVENT
;
10187 x_scroll_bar_handle_release (tracked_scroll_bar
, &event
);
10188 if (event
.kind
!= NO_EVENT
)
10190 event
.timestamp
= timestamp
;
10191 kbd_buffer_store_event_hold (&event
, hold_quit
);
10196 dpyinfo
->grabbed
= 0;
10198 x_detect_focus_change (dpyinfo
, &er
, &inev
);
10200 f
= mac_window_to_frame (window_ptr
);
10201 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10203 /* If we move outside the frame, then we're
10204 certainly no longer on any text in the
10206 clear_mouse_face (dpyinfo
);
10207 dpyinfo
->mouse_face_mouse_frame
= 0;
10210 /* Generate a nil HELP_EVENT to cancel a help-echo.
10211 Do it only if there's something to cancel.
10212 Otherwise, the startup message is cleared when the
10213 mouse leaves the frame. */
10214 if (any_help_event_p
)
10223 int keycode
= (er
.message
& keyCodeMask
) >> 8;
10226 #if USE_CARBON_EVENTS && defined (MAC_OSX)
10227 /* When using Carbon Events, we need to pass raw keyboard
10228 events to the TSM ourselves. If TSM handles it, it
10229 will pass back noErr, otherwise it will pass back
10230 "eventNotHandledErr" and we can process it
10232 if ((!NILP (Vmac_pass_command_to_system
)
10233 || !(er
.modifiers
& cmdKey
))
10234 && (!NILP (Vmac_pass_control_to_system
)
10235 || !(er
.modifiers
& controlKey
))
10236 && (NILP (Vmac_option_modifier
)
10237 || !(er
.modifiers
& optionKey
)))
10238 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
10239 != eventNotHandledErr
)
10244 if (dpyinfo
->x_focus_frame
== NULL
)
10246 /* Beep if keyboard input occurs when all the frames
10254 static SInt16 last_key_script
= -1;
10255 SInt16 current_key_script
= GetScriptManagerVariable (smKeyScript
);
10257 if (last_key_script
!= current_key_script
)
10259 struct input_event event
;
10261 EVENT_INIT (event
);
10262 event
.kind
= LANGUAGE_CHANGE_EVENT
;
10264 event
.code
= current_key_script
;
10265 event
.timestamp
= timestamp
;
10266 kbd_buffer_store_event (&event
);
10269 last_key_script
= current_key_script
;
10274 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
10276 clear_mouse_face (dpyinfo
);
10277 dpyinfo
->mouse_face_hidden
= 1;
10280 /* translate the keycode back to determine the original key */
10281 /* Convert key code if function key is pressed.
10282 Otherwise, if non-ASCII-event, take care of that
10283 without re-translating the key code. */
10284 #if USE_CARBON_EVENTS
10285 if (convert_fn_keycode (eventRef
, keycode
, &xkeysym
))
10287 inev
.code
= xkeysym
;
10288 /* this doesn't work - tried to add shift modifiers */
10290 backtranslate_modified_keycode(er
.modifiers
& (~0x2200),
10291 xkeysym
| 0x80, xkeysym
);
10292 inev
.kind
= ASCII_KEYSTROKE_EVENT
;
10296 if (keycode_to_xkeysym (keycode
, &xkeysym
))
10298 inev
.code
= 0xff00 | xkeysym
;
10299 inev
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
10305 backtranslate_modified_keycode(er
.modifiers
, keycode
,
10306 er
.message
& charCodeMask
);
10307 inev
.kind
= ASCII_KEYSTROKE_EVENT
;
10312 #if USE_CARBON_EVENTS
10313 inev
.modifiers
= mac_event_to_emacs_modifiers (eventRef
);
10315 inev
.modifiers
= mac_to_emacs_modifiers (er
.modifiers
);
10317 inev
.modifiers
|= (extra_keyboard_modifiers
10318 & (meta_modifier
| alt_modifier
10319 | hyper_modifier
| super_modifier
));
10320 XSETFRAME (inev
.frame_or_window
, mac_focus_frame (dpyinfo
));
10323 case kHighLevelEvent
:
10324 read_socket_inev
= &inev
;
10325 AEProcessAppleEvent (&er
);
10326 read_socket_inev
= NULL
;
10332 #if USE_CARBON_EVENTS
10333 ReleaseEvent (eventRef
);
10336 if (inev
.kind
!= NO_EVENT
)
10338 inev
.timestamp
= timestamp
;
10339 kbd_buffer_store_event_hold (&inev
, hold_quit
);
10344 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
10349 XSETFRAME (frame
, f
);
10355 any_help_event_p
= 1;
10356 gen_help_event (help_echo_string
, frame
, help_echo_window
,
10357 help_echo_object
, help_echo_pos
);
10361 help_echo_string
= Qnil
;
10362 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
10369 /* If the focus was just given to an autoraising frame,
10371 /* ??? This ought to be able to handle more than one such frame. */
10372 if (pending_autoraise_frame
)
10374 x_raise_frame (pending_autoraise_frame
);
10375 pending_autoraise_frame
= 0;
10378 #if !USE_CARBON_EVENTS
10379 /* Check which frames are still visible. We do this here because
10380 there doesn't seem to be any direct notification from the Window
10381 Manager that the visibility of a window has changed (at least,
10382 not in all cases). */
10384 Lisp_Object tail
, frame
;
10386 FOR_EACH_FRAME (tail
, frame
)
10388 struct frame
*f
= XFRAME (frame
);
10390 /* The tooltip has been drawn already. Avoid the
10391 SET_FRAME_GARBAGED in mac_handle_visibility_change. */
10392 if (EQ (frame
, tip_frame
))
10395 if (FRAME_MAC_P (f
))
10396 mac_handle_visibility_change (f
);
10406 /* Need to override CodeWarrior's input function so no conversion is
10407 done on newlines Otherwise compiled functions in .elc files will be
10408 read incorrectly. Defined in ...:MSL C:MSL
10409 Common:Source:buffer_io.c. */
10412 __convert_to_newlines (unsigned char * p
, size_t * n
)
10414 #pragma unused(p,n)
10418 __convert_from_newlines (unsigned char * p
, size_t * n
)
10420 #pragma unused(p,n)
10426 make_mac_terminal_frame (struct frame
*f
)
10431 XSETFRAME (frame
, f
);
10433 f
->output_method
= output_mac
;
10434 f
->output_data
.mac
= (struct mac_output
*)
10435 xmalloc (sizeof (struct mac_output
));
10436 bzero (f
->output_data
.mac
, sizeof (struct mac_output
));
10438 XSETFRAME (FRAME_KBOARD (f
)->Vdefault_minibuffer_frame
, f
);
10440 FRAME_COLS (f
) = 96;
10441 FRAME_LINES (f
) = 4;
10443 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
10444 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_right
;
10446 FRAME_DESIRED_CURSOR (f
) = FILLED_BOX_CURSOR
;
10448 f
->output_data
.mac
->cursor_pixel
= 0;
10449 f
->output_data
.mac
->border_pixel
= 0x00ff00;
10450 f
->output_data
.mac
->mouse_pixel
= 0xff00ff;
10451 f
->output_data
.mac
->cursor_foreground_pixel
= 0x0000ff;
10453 f
->output_data
.mac
->text_cursor
= kThemeIBeamCursor
;
10454 f
->output_data
.mac
->nontext_cursor
= kThemeArrowCursor
;
10455 f
->output_data
.mac
->modeline_cursor
= kThemeArrowCursor
;
10456 f
->output_data
.mac
->hand_cursor
= kThemePointingHandCursor
;
10457 f
->output_data
.mac
->hourglass_cursor
= kThemeWatchCursor
;
10458 f
->output_data
.mac
->horizontal_drag_cursor
= kThemeResizeLeftRightCursor
;
10460 FRAME_FONTSET (f
) = -1;
10461 f
->output_data
.mac
->explicit_parent
= 0;
10464 f
->border_width
= 0;
10466 f
->internal_border_width
= 0;
10471 f
->new_text_cols
= 0;
10472 f
->new_text_lines
= 0;
10474 SetRect (&r
, f
->left_pos
, f
->top_pos
,
10475 f
->left_pos
+ FRAME_PIXEL_WIDTH (f
),
10476 f
->top_pos
+ FRAME_PIXEL_HEIGHT (f
));
10480 if (!(FRAME_MAC_WINDOW (f
) =
10481 NewCWindow (NULL
, &r
, "\p", true, dBoxProc
,
10482 (WindowPtr
) -1, 1, (long) f
->output_data
.mac
)))
10484 /* so that update events can find this mac_output struct */
10485 f
->output_data
.mac
->mFP
= f
; /* point back to emacs frame */
10491 /* Need to be initialized for unshow_buffer in window.c. */
10492 selected_window
= f
->selected_window
;
10494 Fmodify_frame_parameters (frame
,
10495 Fcons (Fcons (Qfont
,
10496 build_string ("-*-monaco-medium-r-*--*-90-*-*-*-*-mac-roman")), Qnil
));
10497 Fmodify_frame_parameters (frame
,
10498 Fcons (Fcons (Qforeground_color
,
10499 build_string ("black")), Qnil
));
10500 Fmodify_frame_parameters (frame
,
10501 Fcons (Fcons (Qbackground_color
,
10502 build_string ("white")), Qnil
));
10507 /***********************************************************************
10509 ***********************************************************************/
10511 int mac_initialized
= 0;
10514 mac_initialize_display_info ()
10516 struct mac_display_info
*dpyinfo
= &one_mac_display_info
;
10517 GDHandle main_device_handle
;
10519 bzero (dpyinfo
, sizeof (*dpyinfo
));
10522 dpyinfo
->mac_id_name
10523 = (char *) xmalloc (SCHARS (Vinvocation_name
)
10524 + SCHARS (Vsystem_name
)
10526 sprintf (dpyinfo
->mac_id_name
, "%s@%s",
10527 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
10529 dpyinfo
->mac_id_name
= (char *) xmalloc (strlen ("Mac Display") + 1);
10530 strcpy (dpyinfo
->mac_id_name
, "Mac Display");
10533 main_device_handle
= LMGetMainDevice();
10535 dpyinfo
->reference_count
= 0;
10536 dpyinfo
->resx
= 72.0;
10537 dpyinfo
->resy
= 72.0;
10538 dpyinfo
->color_p
= TestDeviceAttribute (main_device_handle
, gdDevType
);
10540 /* HasDepth returns true if it is possible to have a 32 bit display,
10541 but this may not be what is actually used. Mac OSX can do better.
10542 CGMainDisplayID is only available on OSX 10.2 and higher, but the
10543 header for CGGetActiveDisplayList says that the first display returned
10544 is the active one, so we use that. */
10546 CGDirectDisplayID disp_id
[1];
10547 CGDisplayCount disp_count
;
10548 CGDisplayErr error_code
;
10550 error_code
= CGGetActiveDisplayList (1, disp_id
, &disp_count
);
10551 if (error_code
!= 0)
10552 error ("No display found, CGGetActiveDisplayList error %d", error_code
);
10554 dpyinfo
->n_planes
= CGDisplayBitsPerPixel (disp_id
[0]);
10557 for (dpyinfo
->n_planes
= 32; dpyinfo
->n_planes
> 0; dpyinfo
->n_planes
>>= 1)
10558 if (HasDepth (main_device_handle
, dpyinfo
->n_planes
,
10559 gdDevType
, dpyinfo
->color_p
))
10562 dpyinfo
->height
= (**main_device_handle
).gdRect
.bottom
;
10563 dpyinfo
->width
= (**main_device_handle
).gdRect
.right
;
10564 dpyinfo
->grabbed
= 0;
10565 dpyinfo
->root_window
= NULL
;
10566 dpyinfo
->image_cache
= make_image_cache ();
10568 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
10569 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10570 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10571 dpyinfo
->mouse_face_window
= Qnil
;
10572 dpyinfo
->mouse_face_overlay
= Qnil
;
10573 dpyinfo
->mouse_face_hidden
= 0;
10578 mac_make_rdb (xrm_option
)
10581 XrmDatabase database
;
10583 database
= xrm_get_preference_database (NULL
);
10585 xrm_merge_string_database (database
, xrm_option
);
10590 struct mac_display_info
*
10591 mac_term_init (display_name
, xrm_option
, resource_name
)
10592 Lisp_Object display_name
;
10594 char *resource_name
;
10596 struct mac_display_info
*dpyinfo
;
10600 if (!mac_initialized
)
10603 mac_initialized
= 1;
10606 if (x_display_list
)
10607 error ("Sorry, this version can only handle one display");
10609 mac_initialize_display_info ();
10611 dpyinfo
= &one_mac_display_info
;
10613 dpyinfo
->xrdb
= mac_make_rdb (xrm_option
);
10615 /* Put this display on the chain. */
10616 dpyinfo
->next
= x_display_list
;
10617 x_display_list
= dpyinfo
;
10619 /* Put it on x_display_name_list. */
10620 x_display_name_list
= Fcons (Fcons (display_name
,
10621 Fcons (Qnil
, dpyinfo
->xrdb
)),
10622 x_display_name_list
);
10623 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
10629 /* Get rid of display DPYINFO, assuming all frames are already gone. */
10632 x_delete_display (dpyinfo
)
10633 struct mac_display_info
*dpyinfo
;
10637 /* Discard this display from x_display_name_list and x_display_list.
10638 We can't use Fdelq because that can quit. */
10639 if (! NILP (x_display_name_list
)
10640 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10641 x_display_name_list
= XCDR (x_display_name_list
);
10646 tail
= x_display_name_list
;
10647 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10649 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10651 XSETCDR (tail
, XCDR (XCDR (tail
)));
10654 tail
= XCDR (tail
);
10658 if (x_display_list
== dpyinfo
)
10659 x_display_list
= dpyinfo
->next
;
10662 struct x_display_info
*tail
;
10664 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10665 if (tail
->next
== dpyinfo
)
10666 tail
->next
= tail
->next
->next
;
10669 /* Free the font names in the font table. */
10670 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10671 if (dpyinfo
->font_table
[i
].name
)
10673 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
10674 xfree (dpyinfo
->font_table
[i
].full_name
);
10675 xfree (dpyinfo
->font_table
[i
].name
);
10678 if (dpyinfo
->font_table
->font_encoder
)
10679 xfree (dpyinfo
->font_table
->font_encoder
);
10681 xfree (dpyinfo
->font_table
);
10682 xfree (dpyinfo
->mac_id_name
);
10684 if (x_display_list
== 0)
10686 mac_clear_font_name_table ();
10687 bzero (dpyinfo
, sizeof (*dpyinfo
));
10696 extern int inhibit_window_system
;
10697 extern int noninteractive
;
10698 CFBundleRef appsBundle
;
10701 /* No need to test if already -nw*/
10702 if (inhibit_window_system
|| noninteractive
)
10705 appsBundle
= CFBundleGetMainBundle();
10706 if (appsBundle
!= NULL
)
10708 CFStringRef cfBI
= CFSTR("CFBundleIdentifier");
10709 CFTypeRef res
= CFBundleGetValueForInfoDictionaryKey(appsBundle
, cfBI
);
10710 /* We found the bundle identifier, now we know we are valid. */
10717 /* MAC_TODO: Have this start the bundled executable */
10719 /* For now, prevent the fatal error by bringing it up in the terminal */
10720 inhibit_window_system
= 1;
10724 MakeMeTheFrontProcess ()
10726 ProcessSerialNumber psn
;
10729 err
= GetCurrentProcess (&psn
);
10731 (void) SetFrontProcess (&psn
);
10734 /***** Code to handle C-g testing *****/
10736 /* Contains the Mac modifier formed from quit_char */
10737 int mac_quit_char_modifiers
= 0;
10738 int mac_quit_char_keycode
;
10739 extern int quit_char
;
10742 mac_determine_quit_char_modifiers()
10744 /* Todo: Determine modifiers from quit_char. */
10745 UInt32 qc_modifiers
= ctrl_modifier
;
10747 /* Map modifiers */
10748 mac_quit_char_modifiers
= 0;
10749 if (qc_modifiers
& ctrl_modifier
) mac_quit_char_modifiers
|= controlKey
;
10750 if (qc_modifiers
& shift_modifier
) mac_quit_char_modifiers
|= shiftKey
;
10751 if (qc_modifiers
& alt_modifier
) mac_quit_char_modifiers
|= optionKey
;
10755 init_quit_char_handler ()
10757 /* TODO: Let this support keys other the 'g' */
10758 mac_quit_char_keycode
= 5;
10759 /* Look at <architecture/adb_kb_map.h> for details */
10760 /* http://gemma.apple.com/techpubs/mac/Toolbox/Toolbox-40.html#MARKER-9-184*/
10762 mac_determine_quit_char_modifiers();
10764 #endif /* MAC_OSX */
10772 MenuItemIndex menu_index
;
10774 err
= GetIndMenuItemWithCommandID (NULL
, kHICommandQuit
, 1,
10775 &menu
, &menu_index
);
10777 SetMenuItemCommandKey (menu
, menu_index
, false, 0);
10778 #if USE_CARBON_EVENTS
10779 EnableMenuCommand (NULL
, kHICommandPreferences
);
10780 err
= GetIndMenuItemWithCommandID (NULL
, kHICommandPreferences
, 1,
10781 &menu
, &menu_index
);
10784 SetMenuItemCommandKey (menu
, menu_index
, false, 0);
10785 InsertMenuItemTextWithCFString (menu
, NULL
,
10786 0, kMenuItemAttrSeparator
, 0);
10787 InsertMenuItemTextWithCFString (menu
, CFSTR ("About Emacs"),
10788 0, 0, kHICommandAbout
);
10790 #endif /* USE_CARBON_EVENTS */
10791 #else /* !MAC_OSX */
10792 #if USE_CARBON_EVENTS
10793 SetMenuItemCommandID (GetMenuHandle (M_APPLE
), I_ABOUT
, kHICommandAbout
);
10799 /* Set up use of X before we make the first connection. */
10801 extern frame_parm_handler mac_frame_parm_handlers
[];
10803 static struct redisplay_interface x_redisplay_interface
=
10805 mac_frame_parm_handlers
,
10809 x_clear_end_of_line
,
10811 x_after_update_window_line
,
10812 x_update_window_begin
,
10813 x_update_window_end
,
10816 0, /* flush_display_optional */
10817 x_clear_window_mouse_face
,
10818 x_get_glyph_overhangs
,
10819 x_fix_overlapping_area
,
10820 x_draw_fringe_bitmap
,
10821 0, /* define_fringe_bitmap */
10822 0, /* destroy_fringe_bitmap */
10823 mac_per_char_metric
,
10825 mac_compute_glyph_string_overhangs
,
10826 x_draw_glyph_string
,
10827 mac_define_frame_cursor
,
10828 mac_clear_frame_area
,
10829 mac_draw_window_cursor
,
10830 mac_draw_vertical_window_border
,
10831 mac_shift_glyphs_for_insert
10837 rif
= &x_redisplay_interface
;
10839 clear_frame_hook
= x_clear_frame
;
10840 ins_del_lines_hook
= x_ins_del_lines
;
10841 delete_glyphs_hook
= x_delete_glyphs
;
10842 ring_bell_hook
= XTring_bell
;
10843 reset_terminal_modes_hook
= XTreset_terminal_modes
;
10844 set_terminal_modes_hook
= XTset_terminal_modes
;
10845 update_begin_hook
= x_update_begin
;
10846 update_end_hook
= x_update_end
;
10847 set_terminal_window_hook
= XTset_terminal_window
;
10848 read_socket_hook
= XTread_socket
;
10849 frame_up_to_date_hook
= XTframe_up_to_date
;
10850 mouse_position_hook
= XTmouse_position
;
10851 frame_rehighlight_hook
= XTframe_rehighlight
;
10852 frame_raise_lower_hook
= XTframe_raise_lower
;
10854 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10855 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10856 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10857 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10859 scroll_region_ok
= 1; /* we'll scroll partial frames */
10860 char_ins_del_ok
= 1;
10861 line_ins_del_ok
= 1; /* we'll just blt 'em */
10862 fast_clear_end_of_line
= 1; /* X does this well */
10863 memory_below_frame
= 0; /* we don't remember what scrolls
10867 last_tool_bar_item
= -1;
10868 any_help_event_p
= 0;
10870 /* Try to use interrupt input; if we can't, then start polling. */
10871 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
10875 #if TARGET_API_MAC_CARBON
10876 init_required_apple_events ();
10878 #if USE_CARBON_EVENTS
10880 init_service_handler ();
10882 init_quit_char_handler ();
10883 #endif /* MAC_OSX */
10885 init_command_handler ();
10888 #endif /* USE_CARBON_EVENTS */
10891 if (!inhibit_window_system
)
10892 MakeMeTheFrontProcess ();
10903 staticpro (&x_error_message_string
);
10904 x_error_message_string
= Qnil
;
10907 Qmodifier_value
= intern ("modifier-value");
10908 Qctrl
= intern ("ctrl");
10909 Fput (Qctrl
, Qmodifier_value
, make_number (ctrl_modifier
));
10910 Qmeta
= intern ("meta");
10911 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10912 Qalt
= intern ("alt");
10913 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10914 Qhyper
= intern ("hyper");
10915 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10916 Qsuper
= intern ("super");
10917 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10919 Qapplication
= intern ("application"); staticpro (&Qapplication
);
10920 Qabout
= intern ("about"); staticpro (&Qabout
);
10922 #if USE_CARBON_EVENTS && defined (MAC_OSX)
10923 Qpreferences
= intern ("preferences"); staticpro (&Qpreferences
);
10924 Qservices
= intern ("services"); staticpro (&Qservices
);
10925 Qpaste
= intern ("paste"); staticpro (&Qpaste
);
10926 Qperform
= intern ("perform"); staticpro (&Qperform
);
10930 Fprovide (intern ("mac-carbon"), Qnil
);
10933 staticpro (&Qreverse
);
10934 Qreverse
= intern ("reverse");
10936 staticpro (&Qmac_ready_for_drag_n_drop
);
10937 Qmac_ready_for_drag_n_drop
= intern ("mac-ready-for-drag-n-drop");
10939 staticpro (&x_display_name_list
);
10940 x_display_name_list
= Qnil
;
10942 staticpro (&last_mouse_scroll_bar
);
10943 last_mouse_scroll_bar
= Qnil
;
10945 staticpro (&fm_font_family_alist
);
10946 fm_font_family_alist
= Qnil
;
10949 staticpro (&atsu_font_id_hash
);
10950 atsu_font_id_hash
= Qnil
;
10953 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
10954 doc
: /* If not nil, Emacs uses toolkit scroll bars. */);
10955 #ifdef USE_TOOLKIT_SCROLL_BARS
10956 Vx_toolkit_scroll_bars
= Qt
;
10958 Vx_toolkit_scroll_bars
= Qnil
;
10961 staticpro (&last_mouse_motion_frame
);
10962 last_mouse_motion_frame
= Qnil
;
10966 /* Variables to configure modifier key assignment. */
10968 DEFVAR_LISP ("mac-control-modifier", &Vmac_control_modifier
,
10969 doc
: /* Modifier key assumed when the Mac control key is pressed.
10970 The value can be `alt', `ctrl', `hyper', or `super' for the respective
10971 modifier. The default is `ctrl'. */);
10972 Vmac_control_modifier
= Qctrl
;
10974 DEFVAR_LISP ("mac-option-modifier", &Vmac_option_modifier
,
10975 doc
: /* Modifier key assumed when the Mac alt/option key is pressed.
10976 The value can be `alt', `ctrl', `hyper', or `super' for the respective
10977 modifier. If the value is nil then the key will act as the normal
10978 Mac control modifier, and the option key can be used to compose
10979 characters depending on the chosen Mac keyboard setting. */);
10980 Vmac_option_modifier
= Qnil
;
10982 DEFVAR_LISP ("mac-command-modifier", &Vmac_command_modifier
,
10983 doc
: /* Modifier key assumed when the Mac command key is pressed.
10984 The value can be `alt', `ctrl', `hyper', or `super' for the respective
10985 modifier. The default is `meta'. */);
10986 Vmac_command_modifier
= Qmeta
;
10988 DEFVAR_LISP ("mac-function-modifier", &Vmac_function_modifier
,
10989 doc
: /* Modifier key assumed when the Mac function key is pressed.
10990 The value can be `alt', `ctrl', `hyper', or `super' for the respective
10991 modifier. Note that remapping the function key may lead to unexpected
10992 results for some keys on non-US/GB keyboards. */);
10993 Vmac_function_modifier
= Qnil
;
10995 DEFVAR_LISP ("mac-emulate-three-button-mouse",
10996 &Vmac_emulate_three_button_mouse
,
10997 doc
: /* t means that when the option-key is held down while pressing the
10998 mouse button, the click will register as mouse-2 and while the
10999 command-key is held down, the click will register as mouse-3.
11000 'reverse means that the option-key will register for mouse-3
11001 and the command-key will register for mouse-2. nil means that
11002 no emulation should be done and the modifiers should be placed
11003 on the mouse-1 event. */);
11004 Vmac_emulate_three_button_mouse
= Qnil
;
11006 #if USE_CARBON_EVENTS
11007 DEFVAR_LISP ("mac-wheel-button-is-mouse-2", &Vmac_wheel_button_is_mouse_2
,
11008 doc
: /* Non-nil means that the wheel button will be treated as mouse-2 and
11009 the right click will be mouse-3.
11010 Otherwise, the right click will be mouse-2 and the wheel button mouse-3.*/);
11011 Vmac_wheel_button_is_mouse_2
= Qt
;
11013 DEFVAR_LISP ("mac-pass-command-to-system", &Vmac_pass_command_to_system
,
11014 doc
: /* If non-nil, the Mac \"Command\" key is passed on to the Mac
11015 Toolbox for processing before Emacs sees it. */);
11016 Vmac_pass_command_to_system
= Qt
;
11018 DEFVAR_LISP ("mac-pass-control-to-system", &Vmac_pass_control_to_system
,
11019 doc
: /* If non-nil, the Mac \"Control\" key is passed on to the Mac
11020 Toolbox for processing before Emacs sees it. */);
11021 Vmac_pass_control_to_system
= Qt
;
11025 DEFVAR_LISP ("mac-allow-anti-aliasing", &Vmac_use_core_graphics
,
11026 doc
: /* If non-nil, allow anti-aliasing.
11027 The text will be rendered using Core Graphics text rendering which
11028 may anti-alias the text. */);
11029 Vmac_use_core_graphics
= Qnil
;
11031 /* Register an entry for `mac-roman' so that it can be used when
11032 creating the terminal frame on Mac OS 9 before loading
11033 term/mac-win.elc. */
11034 DEFVAR_LISP ("mac-charset-info-alist", &Vmac_charset_info_alist
,
11035 doc
: /* Alist linking Emacs character sets to Mac text encoding and Emacs coding system.
11036 Each entry should be of the form:
11038 (CHARSET-NAME TEXT-ENCODING CODING-SYSTEM)
11040 where CHARSET-NAME is a string used in font names to identify the
11041 charset, TEXT-ENCODING is a TextEncodingBase value, and CODING_SYSTEM
11042 is a coding system corresponding to TEXT-ENCODING. */);
11043 Vmac_charset_info_alist
=
11044 Fcons (list3 (build_string ("mac-roman"),
11045 make_number (smRoman
), Qnil
), Qnil
);
11048 /* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b
11049 (do not change this comment) */