1 /* Implementation of GUI terminal on the Mac OS.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004,
3 2005, 2006 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 */
75 #include "dispextern.h"
77 #include "termhooks.h"
84 #include "intervals.h"
90 /* Non-nil means Emacs uses toolkit scroll bars. */
92 Lisp_Object Vx_toolkit_scroll_bars
;
94 /* If non-zero, the text will be rendered using Core Graphics text
95 rendering which may anti-alias the text. */
96 int mac_use_core_graphics
;
99 /* Non-zero means that a HELP_EVENT has been generated since Emacs
102 static int any_help_event_p
;
104 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
105 static Lisp_Object last_window
;
107 /* Non-zero means make use of UNDERLINE_POSITION font properties.
108 (Not yet supported.) */
109 int x_use_underline_position_properties
;
111 /* This is a chain of structures for all the X displays currently in
114 struct x_display_info
*x_display_list
;
116 /* This is a list of cons cells, each of the form (NAME
117 FONT-LIST-CACHE . RESOURCE-DATABASE), one for each element of
118 x_display_list and in the same order. NAME is the name of the
119 frame. FONT-LIST-CACHE records previous values returned by
120 x-list-fonts. RESOURCE-DATABASE preserves the X Resource Database
121 equivalent, which is implemented with a Lisp object, for the
124 Lisp_Object x_display_name_list
;
126 /* This is display since Mac does not support multiple ones. */
127 struct mac_display_info one_mac_display_info
;
129 /* Frame being updated by update_frame. This is declared in term.c.
130 This is set by update_begin and looked at by all the XT functions.
131 It is zero while not inside an update. In that case, the XT
132 functions assume that `selected_frame' is the frame to apply to. */
134 extern struct frame
*updating_frame
;
136 /* This is a frame waiting to be auto-raised, within XTread_socket. */
138 struct frame
*pending_autoraise_frame
;
142 Formerly, we used PointerMotionHintMask (in standard_event_mask)
143 so that we would have to call XQueryPointer after each MotionNotify
144 event to ask for another such event. However, this made mouse tracking
145 slow, and there was a bug that made it eventually stop.
147 Simply asking for MotionNotify all the time seems to work better.
149 In order to avoid asking for motion events and then throwing most
150 of them away or busy-polling the server for mouse positions, we ask
151 the server for pointer motion hints. This means that we get only
152 one event per group of mouse movements. "Groups" are delimited by
153 other kinds of events (focus changes and button clicks, for
154 example), or by XQueryPointer calls; when one of these happens, we
155 get another MotionNotify event the next time the mouse moves. This
156 is at least as efficient as getting motion events when mouse
157 tracking is on, and I suspect only negligibly worse when tracking
160 /* Where the mouse was last time we reported a mouse event. */
162 static Rect last_mouse_glyph
;
163 static FRAME_PTR last_mouse_glyph_frame
;
165 /* The scroll bar in which the last X motion event occurred.
167 If the last X motion event occurred in a scroll bar, we set this so
168 XTmouse_position can know whether to report a scroll bar motion or
171 If the last X motion event didn't occur in a scroll bar, we set
172 this to Qnil, to tell XTmouse_position to return an ordinary motion
175 static Lisp_Object last_mouse_scroll_bar
;
177 /* This is a hack. We would really prefer that XTmouse_position would
178 return the time associated with the position it returns, but there
179 doesn't seem to be any way to wrest the time-stamp from the server
180 along with the position query. So, we just keep track of the time
181 of the last movement we received, and return that in hopes that
182 it's somewhat accurate. */
184 static Time last_mouse_movement_time
;
186 struct scroll_bar
*tracked_scroll_bar
= NULL
;
188 /* Incremented by XTread_socket whenever it really tries to read
192 static int volatile input_signal_count
;
194 static int input_signal_count
;
197 extern Lisp_Object Vsystem_name
;
199 extern Lisp_Object Qeql
;
201 /* A mask of extra modifier bits to put into every keyboard char. */
203 extern EMACS_INT extra_keyboard_modifiers
;
205 /* The keysyms to use for the various modifiers. */
207 static Lisp_Object Qalt
, Qhyper
, Qsuper
, Qcontrol
, Qmeta
, Qmodifier_value
;
209 extern int inhibit_window_system
;
211 #if __MRC__ && !TARGET_API_MAC_CARBON
212 QDGlobals qd
; /* QuickDraw global information structure. */
215 #define mac_window_to_frame(wp) (((mac_output *) GetWRefCon (wp))->mFP)
217 struct mac_display_info
*mac_display_info_for_display (Display
*);
218 static void x_update_window_end
P_ ((struct window
*, int, int));
219 int x_catch_errors
P_ ((Display
*));
220 void x_uncatch_errors
P_ ((Display
*, int));
221 void x_lower_frame
P_ ((struct frame
*));
222 void x_scroll_bar_clear
P_ ((struct frame
*));
223 int x_had_errors_p
P_ ((Display
*));
224 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
225 void x_raise_frame
P_ ((struct frame
*));
226 void x_set_window_size
P_ ((struct frame
*, int, int, int));
227 void x_wm_set_window_state
P_ ((struct frame
*, int));
228 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
229 void mac_initialize
P_ ((void));
230 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
231 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
232 static void x_update_end
P_ ((struct frame
*));
233 static void XTframe_up_to_date
P_ ((struct frame
*));
234 static void XTset_terminal_modes
P_ ((void));
235 static void XTreset_terminal_modes
P_ ((void));
236 static void x_clear_frame
P_ ((void));
237 static void frame_highlight
P_ ((struct frame
*));
238 static void frame_unhighlight
P_ ((struct frame
*));
239 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
240 static void mac_focus_changed
P_ ((int, struct mac_display_info
*,
241 struct frame
*, struct input_event
*));
242 static void x_detect_focus_change
P_ ((struct mac_display_info
*,
243 EventRecord
*, struct input_event
*));
244 static void XTframe_rehighlight
P_ ((struct frame
*));
245 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
246 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
247 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
248 enum text_cursor_kinds
));
250 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*, int, GC
));
251 static void x_flush
P_ ((struct frame
*f
));
252 static void x_update_begin
P_ ((struct frame
*));
253 static void x_update_window_begin
P_ ((struct window
*));
254 static void x_after_update_window_line
P_ ((struct glyph_row
*));
255 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
256 enum scroll_bar_part
*,
257 Lisp_Object
*, Lisp_Object
*,
260 static int is_emacs_window
P_ ((WindowPtr
));
261 static XCharStruct
*mac_per_char_metric
P_ ((XFontStruct
*, XChar2b
*, int));
262 static void XSetFont
P_ ((Display
*, GC
, XFontStruct
*));
264 /* Defined in macmenu.h. */
265 extern void menubar_selection_callback (FRAME_PTR
, int);
267 #define GC_FORE_COLOR(gc) (&(gc)->fore_color)
268 #define GC_BACK_COLOR(gc) (&(gc)->back_color)
269 #define GC_FONT(gc) ((gc)->xgcv.font)
270 #define FRAME_NORMAL_GC(f) ((f)->output_data.mac->normal_gc)
271 #define CG_SET_FILL_COLOR(context, color) \
272 CGContextSetRGBFillColor (context, \
273 RED_FROM_ULONG (color) / 255.0f, \
274 GREEN_FROM_ULONG (color) / 255.0f, \
275 BLUE_FROM_ULONG (color) / 255.0f, 1.0f)
276 #define CG_SET_STROKE_COLOR(context, color) \
277 CGContextSetRGBStrokeColor (context, \
278 RED_FROM_ULONG (color) / 255.0f, \
279 GREEN_FROM_ULONG (color) / 255.0f, \
280 BLUE_FROM_ULONG (color) / 255.0f, 1.0f)
282 #define FRAME_CG_CONTEXT(f) ((f)->output_data.mac->cg_context)
284 /* Fringe bitmaps. */
286 static int max_fringe_bmp
= 0;
287 static CGImageRef
*fringe_bmp
= 0;
290 mac_begin_cg_clip (f
, gc
)
294 CGContextRef context
= FRAME_CG_CONTEXT (f
);
298 QDBeginCGContext (GetWindowPort (FRAME_MAC_WINDOW (f
)), &context
);
299 FRAME_CG_CONTEXT (f
) = context
;
302 CGContextSaveGState (context
);
303 CGContextTranslateCTM (context
, 0, FRAME_PIXEL_HEIGHT (f
));
304 CGContextScaleCTM (context
, 1, -1);
305 if (gc
&& gc
->n_clip_rects
)
306 CGContextClipToRects (context
, gc
->clip_rects
, gc
->n_clip_rects
);
315 CGContextRestoreGState (FRAME_CG_CONTEXT (f
));
319 mac_prepare_for_quickdraw (f
)
324 Lisp_Object rest
, frame
;
325 FOR_EACH_FRAME (rest
, frame
)
326 if (FRAME_MAC_P (XFRAME (frame
)))
327 mac_prepare_for_quickdraw (XFRAME (frame
));
331 CGContextRef context
= FRAME_CG_CONTEXT (f
);
335 CGContextSynchronize (context
);
336 QDEndCGContext (GetWindowPort (FRAME_MAC_WINDOW (f
)),
337 &FRAME_CG_CONTEXT (f
));
343 static RgnHandle saved_port_clip_region
= NULL
;
349 static RgnHandle new_region
= NULL
;
351 if (saved_port_clip_region
== NULL
)
352 saved_port_clip_region
= NewRgn ();
353 if (new_region
== NULL
)
354 new_region
= NewRgn ();
356 if (gc
->n_clip_rects
)
358 GetClip (saved_port_clip_region
);
359 SectRgn (saved_port_clip_region
, gc
->clip_region
, new_region
);
360 SetClip (new_region
);
368 if (gc
->n_clip_rects
)
369 SetClip (saved_port_clip_region
);
373 /* X display function emulation */
376 XFreePixmap (display
, pixmap
)
377 Display
*display
; /* not used */
380 DisposeGWorld (pixmap
);
384 /* Mac version of XDrawLine. */
387 mac_draw_line (f
, gc
, x1
, y1
, x2
, y2
)
393 CGContextRef context
;
394 float gx1
= x1
, gy1
= y1
, gx2
= x2
, gy2
= y2
;
397 gx1
+= 0.5f
, gx2
+= 0.5f
;
399 gy1
+= 0.5f
, gy2
+= 0.5f
;
401 context
= mac_begin_cg_clip (f
, gc
);
402 CG_SET_STROKE_COLOR (context
, gc
->xgcv
.foreground
);
403 CGContextBeginPath (context
);
404 CGContextMoveToPoint (context
, gx1
, gy1
);
405 CGContextAddLineToPoint (context
, gx2
, gy2
);
406 CGContextClosePath (context
);
407 CGContextStrokePath (context
);
425 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
427 RGBForeColor (GC_FORE_COLOR (gc
));
437 mac_draw_line_to_pixmap (display
, p
, gc
, x1
, y1
, x2
, y2
)
461 GetGWorld (&old_port
, &old_gdh
);
464 RGBForeColor (GC_FORE_COLOR (gc
));
466 LockPixels (GetGWorldPixMap (p
));
469 UnlockPixels (GetGWorldPixMap (p
));
471 SetGWorld (old_port
, old_gdh
);
476 mac_erase_rectangle (f
, gc
, x
, y
, width
, height
)
480 unsigned int width
, height
;
483 CGContextRef context
;
485 context
= mac_begin_cg_clip (f
, gc
);
486 CG_SET_FILL_COLOR (context
, gc
->xgcv
.background
);
487 CGContextFillRect (context
, CGRectMake (x
, y
, width
, height
));
492 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
494 RGBBackColor (GC_BACK_COLOR (gc
));
495 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
501 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
506 /* Mac version of XClearArea. */
509 mac_clear_area (f
, x
, y
, width
, height
)
512 unsigned int width
, height
;
514 mac_erase_rectangle (f
, FRAME_NORMAL_GC (f
), x
, y
, width
, height
);
517 /* Mac version of XClearWindow. */
524 CGContextRef context
;
525 GC gc
= FRAME_NORMAL_GC (f
);
527 context
= mac_begin_cg_clip (f
, NULL
);
528 CG_SET_FILL_COLOR (context
, gc
->xgcv
.background
);
529 CGContextFillRect (context
, CGRectMake (0, 0, FRAME_PIXEL_WIDTH (f
),
530 FRAME_PIXEL_HEIGHT (f
)));
533 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
535 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
537 #if TARGET_API_MAC_CARBON
541 GetWindowPortBounds (FRAME_MAC_WINDOW (f
), &r
);
544 #else /* not TARGET_API_MAC_CARBON */
545 EraseRect (&(FRAME_MAC_WINDOW (f
)->portRect
));
546 #endif /* not TARGET_API_MAC_CARBON */
551 /* Mac replacement for XCopyArea. */
555 mac_draw_cg_image (image
, f
, gc
, src_x
, src_y
, width
, height
,
556 dest_x
, dest_y
, overlay_p
)
561 unsigned int width
, height
;
562 int dest_x
, dest_y
, overlay_p
;
564 CGContextRef context
;
565 float port_height
= FRAME_PIXEL_HEIGHT (f
);
566 CGRect dest_rect
= CGRectMake (dest_x
, dest_y
, width
, height
);
568 context
= mac_begin_cg_clip (f
, gc
);
571 CG_SET_FILL_COLOR (context
, gc
->xgcv
.background
);
572 CGContextFillRect (context
, dest_rect
);
574 CGContextClipToRect (context
, dest_rect
);
575 CGContextScaleCTM (context
, 1, -1);
576 CGContextTranslateCTM (context
, 0, -port_height
);
577 if (CGImageIsMask (image
))
578 CG_SET_FILL_COLOR (context
, gc
->xgcv
.foreground
);
579 CGContextDrawImage (context
,
580 CGRectMake (dest_x
- src_x
,
581 port_height
- (dest_y
- src_y
582 + CGImageGetHeight (image
)),
583 CGImageGetWidth (image
),
584 CGImageGetHeight (image
)),
589 #else /* !USE_CG_DRAWING */
592 mac_draw_bitmap (f
, gc
, x
, y
, width
, height
, bits
, overlay_p
)
595 int x
, y
, width
, height
;
596 unsigned short *bits
;
602 bitmap
.rowBytes
= sizeof(unsigned short);
603 bitmap
.baseAddr
= (char *)bits
;
604 SetRect (&(bitmap
.bounds
), 0, 0, width
, height
);
606 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
608 RGBForeColor (GC_FORE_COLOR (gc
));
609 RGBBackColor (GC_BACK_COLOR (gc
));
610 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
613 #if TARGET_API_MAC_CARBON
619 CopyBits (&bitmap
, GetPortBitMapForCopyBits (port
),
620 &(bitmap
.bounds
), &r
, overlay_p
? srcOr
: srcCopy
, 0);
621 UnlockPortBits (port
);
623 #else /* not TARGET_API_MAC_CARBON */
624 CopyBits (&bitmap
, &(FRAME_MAC_WINDOW (f
)->portBits
), &(bitmap
.bounds
), &r
,
625 overlay_p
? srcOr
: srcCopy
, 0);
626 #endif /* not TARGET_API_MAC_CARBON */
629 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
631 #endif /* !USE_CG_DRAWING */
634 /* Mac replacement for XCreateBitmapFromBitmapData. */
637 mac_create_bitmap_from_bitmap_data (bitmap
, bits
, w
, h
)
642 static unsigned char swap_nibble
[16]
643 = { 0x0, 0x8, 0x4, 0xc, /* 0000 1000 0100 1100 */
644 0x2, 0xa, 0x6, 0xe, /* 0010 1010 0110 1110 */
645 0x1, 0x9, 0x5, 0xd, /* 0001 1001 0101 1101 */
646 0x3, 0xb, 0x7, 0xf }; /* 0011 1011 0111 1111 */
650 w1
= (w
+ 7) / 8; /* nb of 8bits elt in X bitmap */
651 bitmap
->rowBytes
= ((w
+ 15) / 16) * 2; /* nb of 16bits elt in Mac bitmap */
652 bitmap
->baseAddr
= xmalloc (bitmap
->rowBytes
* h
);
653 bzero (bitmap
->baseAddr
, bitmap
->rowBytes
* h
);
654 for (i
= 0; i
< h
; i
++)
656 p
= bitmap
->baseAddr
+ i
* bitmap
->rowBytes
;
657 for (j
= 0; j
< w1
; j
++)
659 /* Bitswap XBM bytes to match how Mac does things. */
660 unsigned char c
= *bits
++;
661 *p
++ = (unsigned char)((swap_nibble
[c
& 0xf] << 4)
662 | (swap_nibble
[(c
>>4) & 0xf]));;
666 SetRect (&(bitmap
->bounds
), 0, 0, w
, h
);
671 mac_free_bitmap (bitmap
)
674 xfree (bitmap
->baseAddr
);
679 XCreatePixmap (display
, w
, width
, height
, depth
)
680 Display
*display
; /* not used */
682 unsigned int width
, height
;
689 SetPortWindowPort (w
);
691 SetRect (&r
, 0, 0, width
, height
);
692 #if !defined (WORDS_BIG_ENDIAN) && USE_CG_DRAWING
695 err
= NewGWorld (&pixmap
, depth
, &r
, NULL
, NULL
, 0);
696 #if !defined (WORDS_BIG_ENDIAN) && USE_CG_DRAWING
698 /* CreateCGImageFromPixMaps requires ARGB format. */
699 err
= QTNewGWorld (&pixmap
, k32ARGBPixelFormat
, &r
, NULL
, NULL
, 0);
708 XCreatePixmapFromBitmapData (display
, w
, data
, width
, height
, fg
, bg
, depth
)
709 Display
*display
; /* not used */
712 unsigned int width
, height
;
713 unsigned long fg
, bg
;
720 static GC gc
= NULL
; /* not reentrant */
723 gc
= XCreateGC (display
, w
, 0, NULL
);
725 pixmap
= XCreatePixmap (display
, w
, width
, height
, depth
);
729 GetGWorld (&old_port
, &old_gdh
);
730 SetGWorld (pixmap
, NULL
);
731 mac_create_bitmap_from_bitmap_data (&bitmap
, data
, width
, height
);
732 XSetForeground (display
, gc
, fg
);
733 XSetBackground (display
, gc
, bg
);
734 RGBForeColor (GC_FORE_COLOR (gc
));
735 RGBBackColor (GC_BACK_COLOR (gc
));
736 LockPixels (GetGWorldPixMap (pixmap
));
737 #if TARGET_API_MAC_CARBON
738 CopyBits (&bitmap
, GetPortBitMapForCopyBits (pixmap
),
739 &bitmap
.bounds
, &bitmap
.bounds
, srcCopy
, 0);
740 #else /* not TARGET_API_MAC_CARBON */
741 CopyBits (&bitmap
, &(((GrafPtr
)pixmap
)->portBits
),
742 &bitmap
.bounds
, &bitmap
.bounds
, srcCopy
, 0);
743 #endif /* not TARGET_API_MAC_CARBON */
744 UnlockPixels (GetGWorldPixMap (pixmap
));
745 SetGWorld (old_port
, old_gdh
);
746 mac_free_bitmap (&bitmap
);
752 /* Mac replacement for XFillRectangle. */
755 mac_fill_rectangle (f
, gc
, x
, y
, width
, height
)
759 unsigned int width
, height
;
762 CGContextRef context
;
764 context
= mac_begin_cg_clip (f
, gc
);
765 CG_SET_FILL_COLOR (context
, gc
->xgcv
.foreground
);
766 CGContextFillRect (context
, CGRectMake (x
, y
, width
, height
));
771 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
773 RGBForeColor (GC_FORE_COLOR (gc
));
774 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
777 PaintRect (&r
); /* using foreground color of gc */
783 /* Mac replacement for XDrawRectangle: dest is a window. */
786 mac_draw_rectangle (f
, gc
, x
, y
, width
, height
)
790 unsigned int width
, height
;
793 CGContextRef context
;
795 context
= mac_begin_cg_clip (f
, gc
);
796 CG_SET_STROKE_COLOR (context
, gc
->xgcv
.foreground
);
797 CGContextStrokeRect (context
,
798 CGRectMake (x
+ 0.5f
, y
+ 0.5f
, width
, height
));
803 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
805 RGBForeColor (GC_FORE_COLOR (gc
));
806 SetRect (&r
, x
, y
, x
+ width
+ 1, y
+ height
+ 1);
809 FrameRect (&r
); /* using foreground color of gc */
817 atsu_get_text_layout_with_text_ptr (text
, text_length
, style
, text_layout
)
818 ConstUniCharArrayPtr text
;
819 UniCharCount text_length
;
821 ATSUTextLayout
*text_layout
;
824 static ATSUTextLayout saved_text_layout
= NULL
; /* not reentrant */
826 if (saved_text_layout
== NULL
)
828 UniCharCount lengths
[] = {kATSUToTextEnd
};
829 ATSUAttributeTag tags
[] = {kATSULineLayoutOptionsTag
};
830 ByteCount sizes
[] = {sizeof (ATSLineLayoutOptions
)};
831 static ATSLineLayoutOptions line_layout
=
832 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
833 kATSLineDisableAllLayoutOperations
| kATSLineUseDeviceMetrics
834 | kATSLineUseQDRendering
836 kATSLineIsDisplayOnly
| kATSLineFractDisable
839 ATSUAttributeValuePtr values
[] = {&line_layout
};
841 err
= ATSUCreateTextLayoutWithTextPtr (text
,
842 kATSUFromTextBeginning
,
848 err
= ATSUSetLayoutControls (saved_text_layout
,
849 sizeof (tags
) / sizeof (tags
[0]),
850 tags
, sizes
, values
);
851 /* XXX: Should we do this? */
853 err
= ATSUSetTransientFontMatching (saved_text_layout
, true);
857 err
= ATSUSetRunStyle (saved_text_layout
, style
,
858 kATSUFromTextBeginning
, kATSUToTextEnd
);
860 err
= ATSUSetTextPointerLocation (saved_text_layout
, text
,
861 kATSUFromTextBeginning
,
867 *text_layout
= saved_text_layout
;
874 mac_invert_rectangle (f
, x
, y
, width
, height
)
877 unsigned int width
, height
;
882 mac_prepare_for_quickdraw (f
);
884 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
886 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
893 mac_draw_string_common (f
, gc
, x
, y
, buf
, nchars
, bg_width
, bytes_per_char
)
898 int nchars
, bg_width
, bytes_per_char
;
900 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
903 if (GC_FONT (gc
)->mac_style
)
906 ATSUTextLayout text_layout
;
908 xassert (bytes_per_char
== 2);
910 #ifndef WORDS_BIG_ENDIAN
913 UniChar
*text
= (UniChar
*)buf
;
915 for (i
= 0; i
< nchars
; i
++)
916 text
[i
] = EndianU16_BtoN (text
[i
]);
919 err
= atsu_get_text_layout_with_text_ptr ((ConstUniCharArrayPtr
)buf
,
921 GC_FONT (gc
)->mac_style
,
926 if (!mac_use_core_graphics
)
930 mac_prepare_for_quickdraw (f
);
933 RGBForeColor (GC_FORE_COLOR (gc
));
938 SetRect (&r
, x
, y
- FONT_BASE (GC_FONT (gc
)),
939 x
+ bg_width
, y
+ FONT_DESCENT (GC_FONT (gc
)));
940 RGBBackColor (GC_BACK_COLOR (gc
));
942 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
945 ATSUDrawText (text_layout
,
946 kATSUFromTextBeginning
, kATSUToTextEnd
,
947 kATSUUseGrafPortPenLoc
, kATSUUseGrafPortPenLoc
);
954 CGContextRef context
;
955 float port_height
= FRAME_PIXEL_HEIGHT (f
);
956 ATSUAttributeTag tags
[] = {kATSUCGContextTag
};
957 ByteCount sizes
[] = {sizeof (CGContextRef
)};
958 ATSUAttributeValuePtr values
[] = {&context
};
961 context
= mac_begin_cg_clip (f
, gc
);
964 QDBeginCGContext (port
, &context
);
965 if (gc
->n_clip_rects
|| bg_width
)
967 CGContextTranslateCTM (context
, 0, port_height
);
968 CGContextScaleCTM (context
, 1, -1);
969 if (gc
->n_clip_rects
)
970 CGContextClipToRects (context
, gc
->clip_rects
,
975 CG_SET_FILL_COLOR (context
, gc
->xgcv
.background
);
978 CGRectMake (x
, y
- FONT_BASE (GC_FONT (gc
)),
979 bg_width
, FONT_HEIGHT (GC_FONT (gc
))));
981 CGContextScaleCTM (context
, 1, -1);
982 CGContextTranslateCTM (context
, 0, -port_height
);
986 CG_SET_FILL_COLOR (context
, gc
->xgcv
.foreground
);
987 err
= ATSUSetLayoutControls (text_layout
,
988 sizeof (tags
) / sizeof (tags
[0]),
989 tags
, sizes
, values
);
991 ATSUDrawText (text_layout
,
992 kATSUFromTextBeginning
, kATSUToTextEnd
,
993 Long2Fix (x
), Long2Fix (port_height
- y
));
998 CGContextSynchronize (context
);
999 QDEndCGContext (port
, &context
);
1002 /* This doesn't work on Mac OS X 10.1. */
1003 ATSUClearLayoutControls (text_layout
,
1004 sizeof (tags
) / sizeof (tags
[0]), tags
);
1006 ATSUSetLayoutControls (text_layout
,
1007 sizeof (tags
) / sizeof (tags
[0]),
1008 tags
, sizes
, values
);
1011 #endif /* MAC_OSX */
1014 #endif /* USE_ATSUI */
1016 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1019 if (mac_use_core_graphics
)
1020 savedFlags
= SwapQDTextFlags (kQDUseCGTextRendering
);
1023 mac_prepare_for_quickdraw (f
);
1025 mac_begin_clip (gc
);
1026 RGBForeColor (GC_FORE_COLOR (gc
));
1030 RGBBackColor (GC_BACK_COLOR (gc
));
1036 /* We prefer not to use srcCopy text transfer mode on Mac OS X
1038 - Screen is double-buffered. (In srcCopy mode, a text is
1039 drawn into an offscreen graphics world first. So
1040 performance gain cannot be expected.)
1041 - It lowers rendering quality.
1042 - Some fonts leave garbage on cursor movement. */
1047 RGBBackColor (GC_BACK_COLOR (gc
));
1048 SetRect (&r
, x
, y
- FONT_BASE (GC_FONT (gc
)),
1049 x
+ bg_width
, y
+ FONT_DESCENT (GC_FONT (gc
)));
1054 TextFont (GC_FONT (gc
)->mac_fontnum
);
1055 TextSize (GC_FONT (gc
)->mac_fontsize
);
1056 TextFace (GC_FONT (gc
)->mac_fontface
);
1058 DrawText (buf
, 0, nchars
* bytes_per_char
);
1060 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1063 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1064 if (mac_use_core_graphics
)
1065 SwapQDTextFlags(savedFlags
);
1071 /* Mac replacement for XDrawString. */
1074 mac_draw_string (f
, gc
, x
, y
, buf
, nchars
)
1081 mac_draw_string_common (f
, gc
, x
, y
, buf
, nchars
, 0, 1);
1085 /* Mac replacement for XDrawString16. */
1088 mac_draw_string_16 (f
, gc
, x
, y
, buf
, nchars
)
1095 mac_draw_string_common (f
, gc
, x
, y
, (char *) buf
, nchars
, 0, 2);
1099 /* Mac replacement for XDrawImageString. */
1102 mac_draw_image_string (f
, gc
, x
, y
, buf
, nchars
, bg_width
)
1107 int nchars
, bg_width
;
1109 mac_draw_string_common (f
, gc
, x
, y
, buf
, nchars
, bg_width
, 1);
1113 /* Mac replacement for XDrawString16. */
1116 mac_draw_image_string_16 (f
, gc
, x
, y
, buf
, nchars
, bg_width
)
1121 int nchars
, bg_width
;
1123 mac_draw_string_common (f
, gc
, x
, y
, (char *) buf
, nchars
, bg_width
, 2);
1127 /* Mac replacement for XQueryTextExtents, but takes a character. If
1128 STYLE is NULL, measurement is done by QuickDraw Text routines for
1129 the font of the current graphics port. If CG_GLYPH is not NULL,
1130 *CG_GLYPH is set to the glyph ID or 0 if it cannot be obtained. */
1133 mac_query_char_extents (style
, c
,
1134 font_ascent_return
, font_descent_return
,
1135 overall_return
, cg_glyph
)
1142 int *font_ascent_return
, *font_descent_return
;
1143 XCharStruct
*overall_return
;
1144 #if USE_CG_TEXT_DRAWING
1150 OSStatus err
= noErr
;
1157 ATSUTextLayout text_layout
;
1160 err
= atsu_get_text_layout_with_text_ptr (&ch
, 1, style
, &text_layout
);
1163 ATSTrapezoid glyph_bounds
;
1165 err
= ATSUGetGlyphBounds (text_layout
, 0, 0,
1166 kATSUFromTextBeginning
, kATSUToTextEnd
,
1167 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1168 kATSUseFractionalOrigins
,
1170 kATSUseDeviceOrigins
,
1172 1, &glyph_bounds
, NULL
);
1175 xassert (glyph_bounds
.lowerRight
.x
- glyph_bounds
.lowerLeft
.x
1176 == glyph_bounds
.upperRight
.x
- glyph_bounds
.upperLeft
.x
);
1178 width
= Fix2Long (glyph_bounds
.upperRight
.x
1179 - glyph_bounds
.upperLeft
.x
);
1180 if (font_ascent_return
)
1181 *font_ascent_return
= -Fix2Long (glyph_bounds
.upperLeft
.y
);
1182 if (font_descent_return
)
1183 *font_descent_return
= Fix2Long (glyph_bounds
.lowerLeft
.y
);
1186 if (err
== noErr
&& overall_return
)
1188 err
= ATSUMeasureTextImage (text_layout
,
1189 kATSUFromTextBeginning
, kATSUToTextEnd
,
1190 0, 0, &char_bounds
);
1192 STORE_XCHARSTRUCT (*overall_return
, width
, char_bounds
);
1193 #if USE_CG_TEXT_DRAWING
1194 if (err
== noErr
&& cg_glyph
)
1197 ATSUGlyphInfoArray glyph_info_array
;
1198 ByteCount count
= sizeof (ATSUGlyphInfoArray
);
1200 err1
= ATSUMatchFontsToText (text_layout
, kATSUFromTextBeginning
,
1201 kATSUToTextEnd
, NULL
, NULL
, NULL
);
1203 err1
= ATSUGetGlyphInfo (text_layout
, kATSUFromTextBeginning
,
1204 kATSUToTextEnd
, &count
,
1208 xassert (glyph_info_array
.glyphs
[0].glyphID
);
1209 *cg_glyph
= glyph_info_array
.glyphs
[0].glyphID
;
1220 if (font_ascent_return
|| font_descent_return
)
1224 GetFontInfo (&font_info
);
1225 if (font_ascent_return
)
1226 *font_ascent_return
= font_info
.ascent
;
1227 if (font_descent_return
)
1228 *font_descent_return
= font_info
.descent
;
1234 width
= CharWidth (ch
);
1235 QDTextBounds (1, &ch
, &char_bounds
);
1236 STORE_XCHARSTRUCT (*overall_return
, width
, char_bounds
);
1244 /* Mac replacement for XTextExtents16. Only sets horizontal metrics. */
1247 mac_text_extents_16 (font_struct
, string
, nchars
, overall_return
)
1248 XFontStruct
*font_struct
;
1251 XCharStruct
*overall_return
;
1254 short width
= 0, lbearing
= 0, rbearing
= 0;
1257 for (i
= 0; i
< nchars
; i
++)
1259 pcm
= mac_per_char_metric (font_struct
, string
, 0);
1261 width
+= FONT_WIDTH (font_struct
);
1264 lbearing
= min (lbearing
, width
+ pcm
->lbearing
);
1265 rbearing
= max (rbearing
, width
+ pcm
->rbearing
);
1266 width
+= pcm
->width
;
1271 overall_return
->lbearing
= lbearing
;
1272 overall_return
->rbearing
= rbearing
;
1273 overall_return
->width
= width
;
1275 /* What's the meaning of the return value of XTextExtents16? */
1279 #if USE_CG_TEXT_DRAWING
1280 static int cg_text_anti_aliasing_threshold
= 8;
1283 init_cg_text_anti_aliasing_threshold ()
1289 CFPreferencesGetAppIntegerValue (CFSTR ("AppleAntiAliasingThreshold"),
1290 kCFPreferencesCurrentApplication
,
1293 cg_text_anti_aliasing_threshold
= threshold
;
1297 mac_draw_image_string_cg (f
, gc
, x
, y
, buf
, nchars
, bg_width
)
1302 int nchars
, bg_width
;
1305 float port_height
, gx
, gy
;
1307 CGContextRef context
;
1311 if (!mac_use_core_graphics
|| GC_FONT (gc
)->cg_font
== NULL
)
1314 port
= GetWindowPort (FRAME_MAC_WINDOW (f
));
1315 port_height
= FRAME_PIXEL_HEIGHT (f
);
1317 gy
= port_height
- y
;
1318 glyphs
= (CGGlyph
*)buf
;
1319 advances
= alloca (sizeof (CGSize
) * nchars
);
1320 if (advances
== NULL
)
1322 for (i
= 0; i
< nchars
; i
++)
1324 XCharStruct
*pcm
= mac_per_char_metric (GC_FONT (gc
), buf
, 0);
1326 advances
[i
].width
= pcm
->width
;
1327 advances
[i
].height
= 0;
1328 glyphs
[i
] = GC_FONT (gc
)->cg_glyphs
[buf
->byte2
];
1333 context
= mac_begin_cg_clip (f
, gc
);
1335 QDBeginCGContext (port
, &context
);
1336 if (gc
->n_clip_rects
|| bg_width
)
1338 CGContextTranslateCTM (context
, 0, port_height
);
1339 CGContextScaleCTM (context
, 1, -1);
1340 if (gc
->n_clip_rects
)
1341 CGContextClipToRects (context
, gc
->clip_rects
, gc
->n_clip_rects
);
1345 CG_SET_FILL_COLOR (context
, gc
->xgcv
.background
);
1348 CGRectMake (gx
, y
- FONT_BASE (GC_FONT (gc
)),
1349 bg_width
, FONT_HEIGHT (GC_FONT (gc
))));
1351 CGContextScaleCTM (context
, 1, -1);
1352 CGContextTranslateCTM (context
, 0, -port_height
);
1356 CG_SET_FILL_COLOR (context
, gc
->xgcv
.foreground
);
1357 CGContextSetFont (context
, GC_FONT (gc
)->cg_font
);
1358 CGContextSetFontSize (context
, GC_FONT (gc
)->mac_fontsize
);
1359 if (GC_FONT (gc
)->mac_fontsize
<= cg_text_anti_aliasing_threshold
)
1360 CGContextSetShouldAntialias (context
, false);
1361 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
1362 CGContextSetTextPosition (context
, gx
, gy
);
1363 CGContextShowGlyphsWithAdvances (context
, glyphs
, advances
, nchars
);
1365 for (i
= 0; i
< nchars
; i
++)
1367 CGContextShowGlyphsAtPoint (context
, gx
, gy
, glyphs
+ i
, 1);
1368 gx
+= advances
[i
].width
;
1372 mac_end_cg_clip (f
);
1374 CGContextSynchronize (context
);
1375 QDEndCGContext (port
, &context
);
1384 /* Mac replacement for XCopyArea: dest must be window. */
1387 mac_copy_area (src
, f
, gc
, src_x
, src_y
, width
, height
, dest_x
, dest_y
)
1392 unsigned int width
, height
;
1397 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
1399 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1400 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1402 ForeColor (blackColor
);
1403 BackColor (whiteColor
);
1405 mac_begin_clip (gc
);
1406 LockPixels (GetGWorldPixMap (src
));
1407 #if TARGET_API_MAC_CARBON
1412 LockPortBits (port
);
1413 CopyBits (GetPortBitMapForCopyBits (src
),
1414 GetPortBitMapForCopyBits (port
),
1415 &src_r
, &dest_r
, srcCopy
, 0);
1416 UnlockPortBits (port
);
1418 #else /* not TARGET_API_MAC_CARBON */
1419 CopyBits (&(((GrafPtr
)src
)->portBits
), &(FRAME_MAC_WINDOW (f
)->portBits
),
1420 &src_r
, &dest_r
, srcCopy
, 0);
1421 #endif /* not TARGET_API_MAC_CARBON */
1422 UnlockPixels (GetGWorldPixMap (src
));
1425 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1430 mac_copy_area_with_mask (src
, mask
, f
, gc
, src_x
, src_y
,
1431 width
, height
, dest_x
, dest_y
)
1436 unsigned int width
, height
;
1441 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
1443 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1444 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1446 ForeColor (blackColor
);
1447 BackColor (whiteColor
);
1449 mac_begin_clip (gc
);
1450 LockPixels (GetGWorldPixMap (src
));
1451 LockPixels (GetGWorldPixMap (mask
));
1452 #if TARGET_API_MAC_CARBON
1457 LockPortBits (port
);
1458 CopyMask (GetPortBitMapForCopyBits (src
), GetPortBitMapForCopyBits (mask
),
1459 GetPortBitMapForCopyBits (port
),
1460 &src_r
, &src_r
, &dest_r
);
1461 UnlockPortBits (port
);
1463 #else /* not TARGET_API_MAC_CARBON */
1464 CopyMask (&(((GrafPtr
)src
)->portBits
), &(((GrafPtr
)mask
)->portBits
),
1465 &(FRAME_MAC_WINDOW (f
)->portBits
), &src_r
, &src_r
, &dest_r
);
1466 #endif /* not TARGET_API_MAC_CARBON */
1467 UnlockPixels (GetGWorldPixMap (mask
));
1468 UnlockPixels (GetGWorldPixMap (src
));
1471 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1473 #endif /* !USE_CG_DRAWING */
1476 /* Mac replacement for XCopyArea: used only for scrolling. */
1479 mac_scroll_area (f
, gc
, src_x
, src_y
, width
, height
, dest_x
, dest_y
)
1483 unsigned int width
, height
;
1486 #if TARGET_API_MAC_CARBON
1488 RgnHandle dummy
= NewRgn (); /* For avoiding update events. */
1490 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1492 mac_prepare_for_quickdraw (f
);
1494 ScrollWindowRect (FRAME_MAC_WINDOW (f
),
1495 &src_r
, dest_x
- src_x
, dest_y
- src_y
,
1496 kScrollWindowNoOptions
, dummy
);
1498 #else /* not TARGET_API_MAC_CARBON */
1500 WindowPtr w
= FRAME_MAC_WINDOW (f
);
1504 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1505 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1507 /* In Color QuickDraw, set ForeColor and BackColor as follows to avoid
1508 color mapping in CopyBits. Otherwise, it will be slow. */
1509 ForeColor (blackColor
);
1510 BackColor (whiteColor
);
1511 mac_begin_clip (gc
);
1512 CopyBits (&(w
->portBits
), &(w
->portBits
), &src_r
, &dest_r
, srcCopy
, 0);
1515 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1516 #endif /* not TARGET_API_MAC_CARBON */
1520 /* Mac replacement for XChangeGC. */
1523 XChangeGC (display
, gc
, mask
, xgcv
)
1529 if (mask
& GCForeground
)
1530 XSetForeground (display
, gc
, xgcv
->foreground
);
1531 if (mask
& GCBackground
)
1532 XSetBackground (display
, gc
, xgcv
->background
);
1534 XSetFont (display
, gc
, xgcv
->font
);
1538 /* Mac replacement for XCreateGC. */
1541 XCreateGC (display
, window
, mask
, xgcv
)
1547 GC gc
= xmalloc (sizeof (*gc
));
1549 bzero (gc
, sizeof (*gc
));
1550 XChangeGC (display
, gc
, mask
, xgcv
);
1556 /* Used in xfaces.c. */
1559 XFreeGC (display
, gc
)
1563 if (gc
->clip_region
)
1564 DisposeRgn (gc
->clip_region
);
1569 /* Mac replacement for XGetGCValues. */
1572 XGetGCValues (display
, gc
, mask
, xgcv
)
1578 if (mask
& GCForeground
)
1579 xgcv
->foreground
= gc
->xgcv
.foreground
;
1580 if (mask
& GCBackground
)
1581 xgcv
->background
= gc
->xgcv
.background
;
1583 xgcv
->font
= gc
->xgcv
.font
;
1587 /* Mac replacement for XSetForeground. */
1590 XSetForeground (display
, gc
, color
)
1593 unsigned long color
;
1595 if (gc
->xgcv
.foreground
!= color
)
1597 gc
->xgcv
.foreground
= color
;
1598 gc
->fore_color
.red
= RED16_FROM_ULONG (color
);
1599 gc
->fore_color
.green
= GREEN16_FROM_ULONG (color
);
1600 gc
->fore_color
.blue
= BLUE16_FROM_ULONG (color
);
1605 /* Mac replacement for XSetBackground. */
1608 XSetBackground (display
, gc
, color
)
1611 unsigned long color
;
1613 if (gc
->xgcv
.background
!= color
)
1615 gc
->xgcv
.background
= color
;
1616 gc
->back_color
.red
= RED16_FROM_ULONG (color
);
1617 gc
->back_color
.green
= GREEN16_FROM_ULONG (color
);
1618 gc
->back_color
.blue
= BLUE16_FROM_ULONG (color
);
1623 /* Mac replacement for XSetFont. */
1626 XSetFont (display
, gc
, font
)
1631 gc
->xgcv
.font
= font
;
1635 /* Mac replacement for XSetClipRectangles. */
1638 mac_set_clip_rectangles (display
, gc
, rectangles
, n
)
1646 xassert (n
>= 0 && n
<= MAX_CLIP_RECTS
);
1648 gc
->n_clip_rects
= n
;
1651 if (gc
->clip_region
== NULL
)
1652 gc
->clip_region
= NewRgn ();
1653 RectRgn (gc
->clip_region
, rectangles
);
1656 RgnHandle region
= NewRgn ();
1658 for (i
= 1; i
< n
; i
++)
1660 RectRgn (region
, rectangles
+ i
);
1661 UnionRgn (gc
->clip_region
, region
, gc
->clip_region
);
1663 DisposeRgn (region
);
1666 #if defined (MAC_OSX) && (USE_ATSUI || USE_CG_DRAWING)
1667 for (i
= 0; i
< n
; i
++)
1669 Rect
*rect
= rectangles
+ i
;
1671 gc
->clip_rects
[i
] = CGRectMake (rect
->left
, rect
->top
,
1672 rect
->right
- rect
->left
,
1673 rect
->bottom
- rect
->top
);
1679 /* Mac replacement for XSetClipMask. */
1682 mac_reset_clip_rectangles (display
, gc
)
1686 gc
->n_clip_rects
= 0;
1690 /* Mac replacement for XSetWindowBackground. */
1693 XSetWindowBackground (display
, w
, color
)
1696 unsigned long color
;
1698 #if !TARGET_API_MAC_CARBON
1699 AuxWinHandle aw_handle
;
1700 CTabHandle ctab_handle
;
1701 ColorSpecPtr ct_table
;
1706 bg_color
.red
= RED16_FROM_ULONG (color
);
1707 bg_color
.green
= GREEN16_FROM_ULONG (color
);
1708 bg_color
.blue
= BLUE16_FROM_ULONG (color
);
1710 #if TARGET_API_MAC_CARBON
1711 SetWindowContentColor (w
, &bg_color
);
1713 if (GetAuxWin (w
, &aw_handle
))
1715 ctab_handle
= (*aw_handle
)->awCTable
;
1716 HandToHand ((Handle
*) &ctab_handle
);
1717 ct_table
= (*ctab_handle
)->ctTable
;
1718 ct_size
= (*ctab_handle
)->ctSize
;
1719 while (ct_size
> -1)
1721 if (ct_table
->value
== 0)
1723 ct_table
->rgb
= bg_color
;
1724 CTabChanged (ctab_handle
);
1725 SetWinColor (w
, (WCTabHandle
) ctab_handle
);
1733 /* Flush display of frame F, or of all frames if F is null. */
1739 #if TARGET_API_MAC_CARBON
1742 mac_prepare_for_quickdraw (f
);
1745 QDFlushPortBuffer (GetWindowPort (FRAME_MAC_WINDOW (f
)), NULL
);
1747 QDFlushPortBuffer (GetQDGlobalsThePort (), NULL
);
1753 /* Remove calls to XFlush by defining XFlush to an empty replacement.
1754 Calls to XFlush should be unnecessary because the X output buffer
1755 is flushed automatically as needed by calls to XPending,
1756 XNextEvent, or XWindowEvent according to the XFlush man page.
1757 XTread_socket calls XPending. Removing XFlush improves
1760 #define XFlush(DISPLAY) (void) 0
1763 /* Return the struct mac_display_info corresponding to DPY. There's
1766 struct mac_display_info
*
1767 mac_display_info_for_display (dpy
)
1770 return &one_mac_display_info
;
1775 /***********************************************************************
1776 Starting and ending an update
1777 ***********************************************************************/
1779 /* Start an update of frame F. This function is installed as a hook
1780 for update_begin, i.e. it is called when update_begin is called.
1781 This function is called prior to calls to x_update_window_begin for
1782 each window being updated. */
1788 #if TARGET_API_MAC_CARBON
1789 /* During update of a frame, availability of input events is
1790 periodically checked with ReceiveNextEvent if
1791 redisplay-dont-pause is nil. That normally flushes window buffer
1792 changes for every check, and thus screen update looks waving even
1793 if no input is available. So we disable screen updates during
1794 update of a frame. */
1796 DisableScreenUpdates ();
1802 /* Start update of window W. Set the global variable updated_window
1803 to the window being updated and set output_cursor to the cursor
1807 x_update_window_begin (w
)
1810 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1811 struct mac_display_info
*display_info
= FRAME_MAC_DISPLAY_INFO (f
);
1814 set_output_cursor (&w
->cursor
);
1818 if (f
== display_info
->mouse_face_mouse_frame
)
1820 /* Don't do highlighting for mouse motion during the update. */
1821 display_info
->mouse_face_defer
= 1;
1823 /* If F needs to be redrawn, simply forget about any prior mouse
1825 if (FRAME_GARBAGED_P (f
))
1826 display_info
->mouse_face_window
= Qnil
;
1828 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
1829 their mouse_face_p flag set, which means that they are always
1830 unequal to rows in a desired matrix which never have that
1831 flag set. So, rows containing mouse-face glyphs are never
1832 scrolled, and we don't have to switch the mouse highlight off
1833 here to prevent it from being scrolled. */
1835 /* Can we tell that this update does not affect the window
1836 where the mouse highlight is? If so, no need to turn off.
1837 Likewise, don't do anything if the frame is garbaged;
1838 in that case, the frame's current matrix that we would use
1839 is all wrong, and we will redisplay that line anyway. */
1840 if (!NILP (display_info
->mouse_face_window
)
1841 && w
== XWINDOW (display_info
->mouse_face_window
))
1845 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
1846 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
1849 if (i
< w
->desired_matrix
->nrows
)
1850 clear_mouse_face (display_info
);
1859 /* Draw a vertical window border from (x,y0) to (x,y1) */
1862 mac_draw_vertical_window_border (w
, x
, y0
, y1
)
1866 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1869 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
1871 XSetForeground (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->normal_gc
,
1874 mac_draw_line (f
, f
->output_data
.mac
->normal_gc
, x
, y0
, x
, y1
);
1877 /* End update of window W (which is equal to updated_window).
1879 Draw vertical borders between horizontally adjacent windows, and
1880 display W's cursor if CURSOR_ON_P is non-zero.
1882 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
1883 glyphs in mouse-face were overwritten. In that case we have to
1884 make sure that the mouse-highlight is properly redrawn.
1886 W may be a menu bar pseudo-window in case we don't have X toolkit
1887 support. Such windows don't have a cursor, so don't display it
1891 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
1893 int cursor_on_p
, mouse_face_overwritten_p
;
1895 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (XFRAME (w
->frame
));
1897 if (!w
->pseudo_window_p
)
1902 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
1904 output_cursor
.x
, output_cursor
.y
);
1906 if (draw_window_fringes (w
, 1))
1907 x_draw_vertical_border (w
);
1912 /* If a row with mouse-face was overwritten, arrange for
1913 XTframe_up_to_date to redisplay the mouse highlight. */
1914 if (mouse_face_overwritten_p
)
1916 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
1917 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
1918 dpyinfo
->mouse_face_window
= Qnil
;
1921 updated_window
= NULL
;
1925 /* End update of frame F. This function is installed as a hook in
1932 /* Mouse highlight may be displayed again. */
1933 FRAME_MAC_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
1936 #if TARGET_API_MAC_CARBON
1937 EnableScreenUpdates ();
1939 XFlush (FRAME_MAC_DISPLAY (f
));
1944 /* This function is called from various places in xdisp.c whenever a
1945 complete update has been performed. The global variable
1946 updated_window is not available here. */
1949 XTframe_up_to_date (f
)
1952 if (FRAME_MAC_P (f
))
1954 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
1956 if (dpyinfo
->mouse_face_deferred_gc
1957 || f
== dpyinfo
->mouse_face_mouse_frame
)
1960 if (dpyinfo
->mouse_face_mouse_frame
)
1961 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
1962 dpyinfo
->mouse_face_mouse_x
,
1963 dpyinfo
->mouse_face_mouse_y
);
1964 dpyinfo
->mouse_face_deferred_gc
= 0;
1971 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
1972 arrow bitmaps, or clear the fringes if no bitmaps are required
1973 before DESIRED_ROW is made current. The window being updated is
1974 found in updated_window. This function is called from
1975 update_window_line only if it is known that there are differences
1976 between bitmaps to be drawn between current row and DESIRED_ROW. */
1979 x_after_update_window_line (desired_row
)
1980 struct glyph_row
*desired_row
;
1982 struct window
*w
= updated_window
;
1988 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
1989 desired_row
->redraw_fringe_bitmaps_p
= 1;
1991 /* When a window has disappeared, make sure that no rest of
1992 full-width rows stays visible in the internal border. Could
1993 check here if updated_window is the leftmost/rightmost window,
1994 but I guess it's not worth doing since vertically split windows
1995 are almost never used, internal border is rarely set, and the
1996 overhead is very small. */
1997 if (windows_or_buffers_changed
1998 && desired_row
->full_width_p
1999 && (f
= XFRAME (w
->frame
),
2000 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
2002 && (height
= desired_row
->visible_height
,
2005 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
2007 /* Internal border is drawn below the tool bar. */
2008 if (WINDOWP (f
->tool_bar_window
)
2009 && w
== XWINDOW (f
->tool_bar_window
))
2013 mac_clear_area (f
, 0, y
, width
, height
);
2014 mac_clear_area (f
, FRAME_PIXEL_WIDTH (f
) - width
, y
, width
, height
);
2020 /* Draw the bitmap WHICH in one of the left or right fringes of
2021 window W. ROW is the glyph row for which to display the bitmap; it
2022 determines the vertical position at which the bitmap has to be
2026 x_draw_fringe_bitmap (w
, row
, p
)
2028 struct glyph_row
*row
;
2029 struct draw_fringe_bitmap_params
*p
;
2031 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2032 Display
*display
= FRAME_MAC_DISPLAY (f
);
2033 struct face
*face
= p
->face
;
2036 /* Must clip because of partially visible lines. */
2037 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
2040 /* Adjust position of "bottom aligned" bitmap on partially
2041 visible last row. */
2043 int oldVH
= row
->visible_height
;
2044 row
->visible_height
= p
->h
;
2045 row
->y
-= rowY
- p
->y
;
2046 x_clip_to_row (w
, row
, -1, face
->gc
);
2048 row
->visible_height
= oldVH
;
2051 x_clip_to_row (w
, row
, -1, face
->gc
);
2053 if (p
->bx
>= 0 && !p
->overlay_p
)
2055 #if 0 /* MAC_TODO: stipple */
2056 /* In case the same realized face is used for fringes and
2057 for something displayed in the text (e.g. face `region' on
2058 mono-displays, the fill style may have been changed to
2059 FillSolid in x_draw_glyph_string_background. */
2061 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
2063 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
2066 mac_erase_rectangle (f
, face
->gc
, p
->bx
, p
->by
, p
->nx
, p
->ny
);
2068 #if 0 /* MAC_TODO: stipple */
2070 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
2076 && p
->which
< max_fringe_bmp
2082 XGetGCValues (display
, face
->gc
, GCForeground
, &gcv
);
2083 XSetForeground (display
, face
->gc
,
2085 ? (p
->overlay_p
? face
->background
2086 : f
->output_data
.mac
->cursor_pixel
)
2087 : face
->foreground
));
2089 mac_draw_cg_image (fringe_bmp
[p
->which
], f
, face
->gc
, 0, p
->dh
,
2090 p
->wd
, p
->h
, p
->x
, p
->y
, p
->overlay_p
);
2092 mac_draw_bitmap (f
, face
->gc
, p
->x
, p
->y
,
2093 p
->wd
, p
->h
, p
->bits
+ p
->dh
, p
->overlay_p
);
2095 XSetForeground (display
, face
->gc
, gcv
.foreground
);
2098 mac_reset_clip_rectangles (display
, face
->gc
);
2103 mac_define_fringe_bitmap (which
, bits
, h
, wd
)
2105 unsigned short *bits
;
2109 CGDataProviderRef provider
;
2111 if (which
>= max_fringe_bmp
)
2114 max_fringe_bmp
= which
+ 20;
2115 fringe_bmp
= (CGImageRef
*) xrealloc (fringe_bmp
, max_fringe_bmp
* sizeof (CGImageRef
));
2116 while (i
< max_fringe_bmp
)
2117 fringe_bmp
[i
++] = 0;
2120 for (i
= 0; i
< h
; i
++)
2122 provider
= CGDataProviderCreateWithData (NULL
, bits
,
2123 sizeof (unsigned short) * h
, NULL
);
2126 fringe_bmp
[which
] = CGImageMaskCreate (wd
, h
, 1, 1,
2127 sizeof (unsigned short),
2129 CGDataProviderRelease (provider
);
2134 mac_destroy_fringe_bitmap (which
)
2137 if (which
>= max_fringe_bmp
)
2140 if (fringe_bmp
[which
])
2141 CGImageRelease (fringe_bmp
[which
]);
2142 fringe_bmp
[which
] = 0;
2147 /* This is called when starting Emacs and when restarting after
2148 suspend. When starting Emacs, no window is mapped. And nothing
2149 must be done to Emacs's own window if it is suspended (though that
2153 XTset_terminal_modes ()
2157 /* This is called when exiting or suspending Emacs. Exiting will make
2158 the windows go away, and suspending requires no action. */
2161 XTreset_terminal_modes ()
2167 /***********************************************************************
2169 ***********************************************************************/
2171 /* Function prototypes of this page. */
2173 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
2174 static int mac_encode_char
P_ ((int, XChar2b
*, struct font_info
*, int *));
2178 pcm_init (pcm
, count
)
2182 bzero (pcm
, sizeof (XCharStruct
) * count
);
2183 while (--count
>= 0)
2185 pcm
->descent
= PCM_INVALID
;
2190 static enum pcm_status
2191 pcm_get_status (pcm
)
2194 int height
= pcm
->ascent
+ pcm
->descent
;
2196 /* Negative height means some special status. */
2197 return height
>= 0 ? PCM_VALID
: height
;
2200 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
2201 is not contained in the font. */
2203 static INLINE XCharStruct
*
2204 x_per_char_metric (font
, char2b
)
2208 /* The result metric information. */
2209 XCharStruct
*pcm
= NULL
;
2211 xassert (font
&& char2b
);
2214 if (font
->mac_style
)
2216 XCharStruct
**row
= font
->bounds
.rows
+ char2b
->byte1
;
2220 *row
= xmalloc (sizeof (XCharStruct
) * 0x100);
2221 pcm_init (*row
, 0x100);
2223 pcm
= *row
+ char2b
->byte2
;
2224 if (pcm_get_status (pcm
) != PCM_VALID
)
2227 mac_query_char_extents (font
->mac_style
,
2228 (char2b
->byte1
<< 8) + char2b
->byte2
,
2229 NULL
, NULL
, pcm
, NULL
);
2236 if (font
->bounds
.per_char
!= NULL
)
2238 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
2240 /* min_char_or_byte2 specifies the linear character index
2241 corresponding to the first element of the per_char array,
2242 max_char_or_byte2 is the index of the last character. A
2243 character with non-zero CHAR2B->byte1 is not in the font.
2244 A character with byte2 less than min_char_or_byte2 or
2245 greater max_char_or_byte2 is not in the font. */
2246 if (char2b
->byte1
== 0
2247 && char2b
->byte2
>= font
->min_char_or_byte2
2248 && char2b
->byte2
<= font
->max_char_or_byte2
)
2249 pcm
= font
->bounds
.per_char
2250 + (char2b
->byte2
- font
->min_char_or_byte2
);
2254 /* If either min_byte1 or max_byte1 are nonzero, both
2255 min_char_or_byte2 and max_char_or_byte2 are less than
2256 256, and the 2-byte character index values corresponding
2257 to the per_char array element N (counting from 0) are:
2259 byte1 = N/D + min_byte1
2260 byte2 = N\D + min_char_or_byte2
2264 D = max_char_or_byte2 - min_char_or_byte2 + 1
2265 / = integer division
2266 \ = integer modulus */
2267 if (char2b
->byte1
>= font
->min_byte1
2268 && char2b
->byte1
<= font
->max_byte1
2269 && char2b
->byte2
>= font
->min_char_or_byte2
2270 && char2b
->byte2
<= font
->max_char_or_byte2
)
2272 pcm
= (font
->bounds
.per_char
2273 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
2274 * (char2b
->byte1
- font
->min_byte1
))
2275 + (char2b
->byte2
- font
->min_char_or_byte2
));
2281 /* If the per_char pointer is null, all glyphs between the first
2282 and last character indexes inclusive have the same
2283 information, as given by both min_bounds and max_bounds. */
2284 if (char2b
->byte2
>= font
->min_char_or_byte2
2285 && char2b
->byte2
<= font
->max_char_or_byte2
)
2286 pcm
= &font
->max_bounds
;
2292 return ((pcm
== NULL
2294 #if 0 /* Show hollow boxes for zero-width glyphs such as combining diacritics. */
2295 && (pcm
->rbearing
- pcm
->lbearing
) == 0
2304 static XCharStruct
*
2305 mac_per_char_metric (font
, char2b
, font_type
)
2310 return x_per_char_metric (font
, char2b
);
2314 Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
2315 the two-byte form of C. Encoding is returned in *CHAR2B. */
2318 mac_encode_char (c
, char2b
, font_info
, two_byte_p
)
2321 struct font_info
*font_info
;
2324 int charset
= CHAR_CHARSET (c
);
2325 XFontStruct
*font
= font_info
->font
;
2327 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
2328 This may be either a program in a special encoder language or a
2330 if (font_info
->font_encoder
)
2332 /* It's a program. */
2333 struct ccl_program
*ccl
= font_info
->font_encoder
;
2335 check_ccl_update (ccl
);
2336 if (CHARSET_DIMENSION (charset
) == 1)
2338 ccl
->reg
[0] = charset
;
2339 ccl
->reg
[1] = char2b
->byte2
;
2344 ccl
->reg
[0] = charset
;
2345 ccl
->reg
[1] = char2b
->byte1
;
2346 ccl
->reg
[2] = char2b
->byte2
;
2349 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
2351 /* We assume that MSBs are appropriately set/reset by CCL
2353 if (font
->max_byte1
== 0) /* 1-byte font */
2354 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
2356 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
2358 else if (font_info
->encoding
[charset
])
2360 /* Fixed encoding scheme. See fontset.h for the meaning of the
2361 encoding numbers. */
2362 int enc
= font_info
->encoding
[charset
];
2364 if ((enc
== 1 || enc
== 2)
2365 && CHARSET_DIMENSION (charset
) == 2)
2366 char2b
->byte1
|= 0x80;
2368 if (enc
== 1 || enc
== 3)
2369 char2b
->byte2
|= 0x80;
2375 ENCODE_SJIS (char2b
->byte1
, char2b
->byte2
, sjis1
, sjis2
);
2376 char2b
->byte1
= sjis1
;
2377 char2b
->byte2
= sjis2
;
2382 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
2384 return FONT_TYPE_UNKNOWN
;
2389 /***********************************************************************
2391 ***********************************************************************/
2395 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2396 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2397 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2399 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2400 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2401 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2402 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2403 static void mac_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2404 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2405 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2406 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2407 /*static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap,
2408 unsigned long *, double, int));*/
2409 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2410 double, int, unsigned long));
2411 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2412 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2413 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2414 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2415 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2417 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2418 int, int, int, int, int, int,
2420 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2421 int, int, int, Rect
*));
2424 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2428 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2433 struct glyph_string
*s
;
2435 if (s
->font
== FRAME_FONT (s
->f
)
2436 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2437 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2439 s
->gc
= s
->f
->output_data
.mac
->cursor_gc
;
2442 /* Cursor on non-default face: must merge. */
2446 xgcv
.background
= s
->f
->output_data
.mac
->cursor_pixel
;
2447 xgcv
.foreground
= s
->face
->background
;
2449 /* If the glyph would be invisible, try a different foreground. */
2450 if (xgcv
.foreground
== xgcv
.background
)
2451 xgcv
.foreground
= s
->face
->foreground
;
2452 if (xgcv
.foreground
== xgcv
.background
)
2453 xgcv
.foreground
= s
->f
->output_data
.mac
->cursor_foreground_pixel
;
2454 if (xgcv
.foreground
== xgcv
.background
)
2455 xgcv
.foreground
= s
->face
->foreground
;
2457 /* Make sure the cursor is distinct from text in this face. */
2458 if (xgcv
.background
== s
->face
->background
2459 && xgcv
.foreground
== s
->face
->foreground
)
2461 xgcv
.background
= s
->face
->foreground
;
2462 xgcv
.foreground
= s
->face
->background
;
2465 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2466 xgcv
.font
= s
->font
;
2467 mask
= GCForeground
| GCBackground
| GCFont
;
2469 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2470 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2473 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2474 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2476 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2481 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2484 x_set_mouse_face_gc (s
)
2485 struct glyph_string
*s
;
2490 /* What face has to be used last for the mouse face? */
2491 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2492 face
= FACE_FROM_ID (s
->f
, face_id
);
2494 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2496 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2497 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2499 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2500 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2501 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2503 /* If font in this face is same as S->font, use it. */
2504 if (s
->font
== s
->face
->font
)
2505 s
->gc
= s
->face
->gc
;
2508 /* Otherwise construct scratch_cursor_gc with values from FACE
2513 xgcv
.background
= s
->face
->background
;
2514 xgcv
.foreground
= s
->face
->foreground
;
2515 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2516 xgcv
.font
= s
->font
;
2517 mask
= GCForeground
| GCBackground
| GCFont
;
2519 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2520 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2523 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2524 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2526 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2529 xassert (s
->gc
!= 0);
2533 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2534 Faces to use in the mode line have already been computed when the
2535 matrix was built, so there isn't much to do, here. */
2538 x_set_mode_line_face_gc (s
)
2539 struct glyph_string
*s
;
2541 s
->gc
= s
->face
->gc
;
2545 /* Set S->gc of glyph string S for drawing that glyph string. Set
2546 S->stippled_p to a non-zero value if the face of S has a stipple
2550 x_set_glyph_string_gc (s
)
2551 struct glyph_string
*s
;
2553 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2555 if (s
->hl
== DRAW_NORMAL_TEXT
)
2557 s
->gc
= s
->face
->gc
;
2558 s
->stippled_p
= s
->face
->stipple
!= 0;
2560 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2562 x_set_mode_line_face_gc (s
);
2563 s
->stippled_p
= s
->face
->stipple
!= 0;
2565 else if (s
->hl
== DRAW_CURSOR
)
2567 x_set_cursor_gc (s
);
2570 else if (s
->hl
== DRAW_MOUSE_FACE
)
2572 x_set_mouse_face_gc (s
);
2573 s
->stippled_p
= s
->face
->stipple
!= 0;
2575 else if (s
->hl
== DRAW_IMAGE_RAISED
2576 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2578 s
->gc
= s
->face
->gc
;
2579 s
->stippled_p
= s
->face
->stipple
!= 0;
2583 s
->gc
= s
->face
->gc
;
2584 s
->stippled_p
= s
->face
->stipple
!= 0;
2587 /* GC must have been set. */
2588 xassert (s
->gc
!= 0);
2592 /* Set clipping for output of glyph string S. S may be part of a mode
2593 line or menu if we don't have X toolkit support. */
2596 x_set_glyph_string_clipping (s
)
2597 struct glyph_string
*s
;
2599 Rect rects
[MAX_CLIP_RECTS
];
2602 n
= get_glyph_string_clip_rects (s
, rects
, MAX_CLIP_RECTS
);
2603 mac_set_clip_rectangles (s
->display
, s
->gc
, rects
, n
);
2608 Compute left and right overhang of glyph string S. If S is a glyph
2609 string for a composition, assume overhangs don't exist. */
2612 mac_compute_glyph_string_overhangs (s
)
2613 struct glyph_string
*s
;
2615 if (!(s
->cmp
== NULL
2616 && s
->first_glyph
->type
== CHAR_GLYPH
))
2621 || s
->font
->mac_style
2627 mac_text_extents_16 (s
->font
, s
->char2b
, s
->nchars
, &cs
);
2628 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2629 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2634 MacFontStruct
*font
= s
->font
;
2636 TextFont (font
->mac_fontnum
);
2637 TextSize (font
->mac_fontsize
);
2638 TextFace (font
->mac_fontface
);
2640 QDTextBounds (s
->nchars
* 2, (char *)s
->char2b
, &r
);
2642 s
->right_overhang
= r
.right
> s
->width
? r
.right
- s
->width
: 0;
2643 s
->left_overhang
= r
.left
< 0 ? -r
.left
: 0;
2648 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
2651 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
2652 struct glyph_string
*s
;
2655 mac_erase_rectangle (s
->f
, s
->gc
, x
, y
, w
, h
);
2659 /* Draw the background of glyph_string S. If S->background_filled_p
2660 is non-zero don't draw it. FORCE_P non-zero means draw the
2661 background even if it wouldn't be drawn normally. This is used
2662 when a string preceding S draws into the background of S, or S
2663 contains the first component of a composition. */
2666 x_draw_glyph_string_background (s
, force_p
)
2667 struct glyph_string
*s
;
2670 /* Nothing to do if background has already been drawn or if it
2671 shouldn't be drawn in the first place. */
2672 if (!s
->background_filled_p
)
2674 int box_line_width
= max (s
->face
->box_line_width
, 0);
2676 #if 0 /* MAC_TODO: stipple */
2679 /* Fill background with a stipple pattern. */
2680 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2681 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
2682 s
->y
+ box_line_width
,
2683 s
->background_width
,
2684 s
->height
- 2 * box_line_width
);
2685 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2686 s
->background_filled_p
= 1;
2690 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
2691 || s
->font_not_found_p
2692 || s
->extends_to_end_of_line_p
2695 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
2696 s
->background_width
,
2697 s
->height
- 2 * box_line_width
);
2698 s
->background_filled_p
= 1;
2704 /* Draw the foreground of glyph string S. */
2707 x_draw_glyph_string_foreground (s
)
2708 struct glyph_string
*s
;
2712 /* If first glyph of S has a left box line, start drawing the text
2713 of S to the right of that box line. */
2714 if (s
->face
->box
!= FACE_NO_BOX
2715 && s
->first_glyph
->left_box_line_p
)
2716 x
= s
->x
+ abs (s
->face
->box_line_width
);
2720 /* Draw characters of S as rectangles if S's font could not be
2722 if (s
->font_not_found_p
)
2724 for (i
= 0; i
< s
->nchars
; ++i
)
2726 struct glyph
*g
= s
->first_glyph
+ i
;
2727 mac_draw_rectangle (s
->f
, s
->gc
, x
, s
->y
,
2728 g
->pixel_width
- 1, s
->height
- 1);
2729 x
+= g
->pixel_width
;
2734 char *char1b
= (char *) s
->char2b
;
2735 int boff
= s
->font_info
->baseline_offset
;
2737 if (s
->font_info
->vertical_centering
)
2738 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
2740 /* If we can use 8-bit functions, condense S->char2b. */
2743 && GC_FONT (s
->gc
)->mac_style
== NULL
2746 for (i
= 0; i
< s
->nchars
; ++i
)
2747 char1b
[i
] = s
->char2b
[i
].byte2
;
2749 /* Draw text with XDrawString if background has already been
2750 filled. Otherwise, use XDrawImageString. (Note that
2751 XDrawImageString is usually faster than XDrawString.) Always
2752 use XDrawImageString when drawing the cursor so that there is
2753 no chance that characters under a box cursor are invisible. */
2755 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
2756 bg_width
= 0; /* Corresponds to XDrawString. */
2758 bg_width
= s
->background_width
; /* Corresponds to XDrawImageString. */
2762 || GC_FONT (s
->gc
)->mac_style
2765 #if USE_CG_TEXT_DRAWING
2767 && mac_draw_image_string_cg (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2768 s
->char2b
, s
->nchars
, bg_width
))
2772 mac_draw_image_string_16 (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2773 s
->char2b
, s
->nchars
, bg_width
);
2775 mac_draw_image_string (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2776 char1b
, s
->nchars
, bg_width
);
2780 /* Draw the foreground of composite glyph string S. */
2783 x_draw_composite_glyph_string_foreground (s
)
2784 struct glyph_string
*s
;
2788 /* If first glyph of S has a left box line, start drawing the text
2789 of S to the right of that box line. */
2790 if (s
->face
->box
!= FACE_NO_BOX
2791 && s
->first_glyph
->left_box_line_p
)
2792 x
= s
->x
+ abs (s
->face
->box_line_width
);
2796 /* S is a glyph string for a composition. S->gidx is the index of
2797 the first character drawn for glyphs of this composition.
2798 S->gidx == 0 means we are drawing the very first character of
2799 this composition. */
2801 /* Draw a rectangle for the composition if the font for the very
2802 first character of the composition could not be loaded. */
2803 if (s
->font_not_found_p
)
2806 mac_draw_rectangle (s
->f
, s
->gc
, x
, s
->y
,
2807 s
->width
- 1, s
->height
- 1);
2811 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
2812 mac_draw_string_16 (s
->f
, s
->gc
,
2813 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
2814 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
2820 #ifdef USE_X_TOOLKIT
2822 static struct frame
*x_frame_of_widget
P_ ((Widget
));
2825 /* Return the frame on which widget WIDGET is used.. Abort if frame
2826 cannot be determined. */
2828 static struct frame
*
2829 x_frame_of_widget (widget
)
2832 struct x_display_info
*dpyinfo
;
2836 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
2838 /* Find the top-level shell of the widget. Note that this function
2839 can be called when the widget is not yet realized, so XtWindow
2840 (widget) == 0. That's the reason we can't simply use
2841 x_any_window_to_frame. */
2842 while (!XtIsTopLevelShell (widget
))
2843 widget
= XtParent (widget
);
2845 /* Look for a frame with that top-level widget. Allocate the color
2846 on that frame to get the right gamma correction value. */
2847 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
2848 if (GC_FRAMEP (XCAR (tail
))
2849 && (f
= XFRAME (XCAR (tail
)),
2850 (f
->output_data
.nothing
!= 1
2851 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
2852 && f
->output_data
.x
->widget
== widget
)
2859 /* Allocate the color COLOR->pixel on the screen and display of
2860 widget WIDGET in colormap CMAP. If an exact match cannot be
2861 allocated, try the nearest color available. Value is non-zero
2862 if successful. This is called from lwlib. */
2865 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
2870 struct frame
*f
= x_frame_of_widget (widget
);
2871 return x_alloc_nearest_color (f
, cmap
, color
);
2875 #endif /* USE_X_TOOLKIT */
2877 #if 0 /* MAC_TODO */
2879 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
2880 CMAP. If an exact match can't be allocated, try the nearest color
2881 available. Value is non-zero if successful. Set *COLOR to the
2885 x_alloc_nearest_color (f
, cmap
, color
)
2890 Display
*display
= FRAME_X_DISPLAY (f
);
2891 Screen
*screen
= FRAME_X_SCREEN (f
);
2894 gamma_correct (f
, color
);
2895 rc
= XAllocColor (display
, cmap
, color
);
2898 /* If we got to this point, the colormap is full, so we're going
2899 to try to get the next closest color. The algorithm used is
2900 a least-squares matching, which is what X uses for closest
2901 color matching with StaticColor visuals. */
2903 unsigned long nearest_delta
= ~0;
2904 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
2905 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
2907 for (i
= 0; i
< ncells
; ++i
)
2909 XQueryColors (display
, cmap
, cells
, ncells
);
2911 for (nearest
= i
= 0; i
< ncells
; ++i
)
2913 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
2914 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
2915 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
2916 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
2918 if (delta
< nearest_delta
)
2921 nearest_delta
= delta
;
2925 color
->red
= cells
[nearest
].red
;
2926 color
->green
= cells
[nearest
].green
;
2927 color
->blue
= cells
[nearest
].blue
;
2928 rc
= XAllocColor (display
, cmap
, color
);
2931 #ifdef DEBUG_X_COLORS
2933 register_color (color
->pixel
);
2934 #endif /* DEBUG_X_COLORS */
2940 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
2941 It's necessary to do this instead of just using PIXEL directly to
2942 get color reference counts right. */
2945 x_copy_color (f
, pixel
)
2947 unsigned long pixel
;
2951 color
.pixel
= pixel
;
2953 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2954 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2956 #ifdef DEBUG_X_COLORS
2957 register_color (pixel
);
2963 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
2964 It's necessary to do this instead of just using PIXEL directly to
2965 get color reference counts right. */
2968 x_copy_dpy_color (dpy
, cmap
, pixel
)
2971 unsigned long pixel
;
2975 color
.pixel
= pixel
;
2977 XQueryColor (dpy
, cmap
, &color
);
2978 XAllocColor (dpy
, cmap
, &color
);
2980 #ifdef DEBUG_X_COLORS
2981 register_color (pixel
);
2986 #endif /* MAC_TODO */
2989 /* Brightness beyond which a color won't have its highlight brightness
2992 Nominally, highlight colors for `3d' faces are calculated by
2993 brightening an object's color by a constant scale factor, but this
2994 doesn't yield good results for dark colors, so for colors who's
2995 brightness is less than this value (on a scale of 0-255) have to
2996 use an additional additive factor.
2998 The value here is set so that the default menu-bar/mode-line color
2999 (grey75) will not have its highlights changed at all. */
3000 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
3003 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
3004 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3005 If this produces the same color as COLOR, try a color where all RGB
3006 values have DELTA added. Return the allocated color in *COLOR.
3007 DISPLAY is the X display, CMAP is the colormap to operate on.
3008 Value is non-zero if successful. */
3011 mac_alloc_lighter_color (f
, color
, factor
, delta
)
3013 unsigned long *color
;
3020 /* On Mac, RGB values are 0-255, not 0-65535, so scale delta. */
3023 /* Change RGB values by specified FACTOR. Avoid overflow! */
3024 xassert (factor
>= 0);
3025 new = RGB_TO_ULONG (min (0xff, (int) (factor
* RED_FROM_ULONG (*color
))),
3026 min (0xff, (int) (factor
* GREEN_FROM_ULONG (*color
))),
3027 min (0xff, (int) (factor
* BLUE_FROM_ULONG (*color
))));
3029 /* Calculate brightness of COLOR. */
3030 bright
= (2 * RED_FROM_ULONG (*color
) + 3 * GREEN_FROM_ULONG (*color
)
3031 + BLUE_FROM_ULONG (*color
)) / 6;
3033 /* We only boost colors that are darker than
3034 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3035 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3036 /* Make an additive adjustment to NEW, because it's dark enough so
3037 that scaling by FACTOR alone isn't enough. */
3039 /* How far below the limit this color is (0 - 1, 1 being darker). */
3040 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3041 /* The additive adjustment. */
3042 int min_delta
= delta
* dimness
* factor
/ 2;
3045 new = RGB_TO_ULONG (max (0, min (0xff, (int) (RED_FROM_ULONG (*color
)) - min_delta
)),
3046 max (0, min (0xff, (int) (GREEN_FROM_ULONG (*color
)) - min_delta
)),
3047 max (0, min (0xff, (int) (BLUE_FROM_ULONG (*color
)) - min_delta
)));
3049 new = RGB_TO_ULONG (max (0, min (0xff, (int) (min_delta
+ RED_FROM_ULONG (*color
)))),
3050 max (0, min (0xff, (int) (min_delta
+ GREEN_FROM_ULONG (*color
)))),
3051 max (0, min (0xff, (int) (min_delta
+ BLUE_FROM_ULONG (*color
)))));
3055 new = RGB_TO_ULONG (max (0, min (0xff, (int) (delta
+ RED_FROM_ULONG (*color
)))),
3056 max (0, min (0xff, (int) (delta
+ GREEN_FROM_ULONG (*color
)))),
3057 max (0, min (0xff, (int) (delta
+ BLUE_FROM_ULONG (*color
)))));
3059 /* MAC_TODO: Map to palette and retry with delta if same? */
3060 /* MAC_TODO: Free colors (if using palette)? */
3071 /* Set up the foreground color for drawing relief lines of glyph
3072 string S. RELIEF is a pointer to a struct relief containing the GC
3073 with which lines will be drawn. Use a color that is FACTOR or
3074 DELTA lighter or darker than the relief's background which is found
3075 in S->f->output_data.x->relief_background. If such a color cannot
3076 be allocated, use DEFAULT_PIXEL, instead. */
3079 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3081 struct relief
*relief
;
3084 unsigned long default_pixel
;
3087 struct mac_output
*di
= f
->output_data
.mac
;
3088 unsigned long mask
= GCForeground
;
3089 unsigned long pixel
;
3090 unsigned long background
= di
->relief_background
;
3091 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
3093 /* MAC_TODO: Free colors (if using palette)? */
3095 /* Allocate new color. */
3096 xgcv
.foreground
= default_pixel
;
3098 if (dpyinfo
->n_planes
!= 1
3099 && mac_alloc_lighter_color (f
, &pixel
, factor
, delta
))
3101 relief
->allocated_p
= 1;
3102 xgcv
.foreground
= relief
->pixel
= pixel
;
3105 if (relief
->gc
== 0)
3107 #if 0 /* MAC_TODO: stipple */
3108 xgcv
.stipple
= dpyinfo
->gray
;
3111 relief
->gc
= XCreateGC (NULL
, FRAME_MAC_WINDOW (f
), mask
, &xgcv
);
3114 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
3118 /* Set up colors for the relief lines around glyph string S. */
3121 x_setup_relief_colors (s
)
3122 struct glyph_string
*s
;
3124 struct mac_output
*di
= s
->f
->output_data
.mac
;
3125 unsigned long color
;
3127 if (s
->face
->use_box_color_for_shadows_p
)
3128 color
= s
->face
->box_color
;
3129 else if (s
->first_glyph
->type
== IMAGE_GLYPH
3131 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
3132 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
3137 /* Get the background color of the face. */
3138 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3139 color
= xgcv
.background
;
3142 if (di
->white_relief
.gc
== 0
3143 || color
!= di
->relief_background
)
3145 di
->relief_background
= color
;
3146 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3147 WHITE_PIX_DEFAULT (s
->f
));
3148 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3149 BLACK_PIX_DEFAULT (s
->f
));
3154 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3155 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3156 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3157 relief. LEFT_P non-zero means draw a relief on the left side of
3158 the rectangle. RIGHT_P non-zero means draw a relief on the right
3159 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3163 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3164 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
3166 int left_x
, top_y
, right_x
, bottom_y
, width
;
3167 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
3170 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
3175 gc
= f
->output_data
.mac
->white_relief
.gc
;
3177 gc
= f
->output_data
.mac
->black_relief
.gc
;
3178 mac_set_clip_rectangles (dpy
, gc
, clip_rect
, 1);
3182 for (i
= 0; i
< width
; ++i
)
3183 mac_draw_line (f
, gc
,
3184 left_x
+ i
* left_p
, top_y
+ i
,
3185 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3189 for (i
= 0; i
< width
; ++i
)
3190 mac_draw_line (f
, gc
,
3191 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
3193 mac_reset_clip_rectangles (dpy
, gc
);
3195 gc
= f
->output_data
.mac
->black_relief
.gc
;
3197 gc
= f
->output_data
.mac
->white_relief
.gc
;
3198 mac_set_clip_rectangles (dpy
, gc
, clip_rect
, 1);
3202 for (i
= 0; i
< width
; ++i
)
3203 mac_draw_line (f
, gc
,
3204 left_x
+ i
* left_p
, bottom_y
- i
,
3205 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3209 for (i
= 0; i
< width
; ++i
)
3210 mac_draw_line (f
, gc
,
3211 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3213 mac_reset_clip_rectangles (dpy
, gc
);
3217 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3218 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3219 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3220 left side of the rectangle. RIGHT_P non-zero means draw a line
3221 on the right side of the rectangle. CLIP_RECT is the clipping
3222 rectangle to use when drawing. */
3225 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3226 left_p
, right_p
, clip_rect
)
3227 struct glyph_string
*s
;
3228 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
3233 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3234 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3235 mac_set_clip_rectangles (s
->display
, s
->gc
, clip_rect
, 1);
3238 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, top_y
,
3239 right_x
- left_x
+ 1, width
);
3243 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, top_y
,
3244 width
, bottom_y
- top_y
+ 1);
3247 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, bottom_y
- width
+ 1,
3248 right_x
- left_x
+ 1, width
);
3252 mac_fill_rectangle (s
->f
, s
->gc
, right_x
- width
+ 1,
3253 top_y
, width
, bottom_y
- top_y
+ 1);
3255 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3256 mac_reset_clip_rectangles (s
->display
, s
->gc
);
3260 /* Draw a box around glyph string S. */
3263 x_draw_glyph_string_box (s
)
3264 struct glyph_string
*s
;
3266 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3267 int left_p
, right_p
;
3268 struct glyph
*last_glyph
;
3271 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
3272 ? WINDOW_RIGHT_EDGE_X (s
->w
)
3273 : window_box_right (s
->w
, s
->area
));
3275 /* The glyph that may have a right box line. */
3276 last_glyph
= (s
->cmp
|| s
->img
3278 : s
->first_glyph
+ s
->nchars
- 1);
3280 width
= abs (s
->face
->box_line_width
);
3281 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3283 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
3285 : min (last_x
, s
->x
+ s
->background_width
) - 1);
3287 bottom_y
= top_y
+ s
->height
- 1;
3289 left_p
= (s
->first_glyph
->left_box_line_p
3290 || (s
->hl
== DRAW_MOUSE_FACE
3292 || s
->prev
->hl
!= s
->hl
)));
3293 right_p
= (last_glyph
->right_box_line_p
3294 || (s
->hl
== DRAW_MOUSE_FACE
3296 || s
->next
->hl
!= s
->hl
)));
3298 get_glyph_string_clip_rect (s
, &clip_rect
);
3300 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3301 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3302 left_p
, right_p
, &clip_rect
);
3305 x_setup_relief_colors (s
);
3306 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3307 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
3312 /* Draw foreground of image glyph string S. */
3315 x_draw_image_foreground (s
)
3316 struct glyph_string
*s
;
3319 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
3321 /* If first glyph of S has a left box line, start drawing it to the
3322 right of that line. */
3323 if (s
->face
->box
!= FACE_NO_BOX
3324 && s
->first_glyph
->left_box_line_p
3326 x
+= abs (s
->face
->box_line_width
);
3328 /* If there is a margin around the image, adjust x- and y-position
3330 if (s
->slice
.x
== 0)
3331 x
+= s
->img
->hmargin
;
3332 if (s
->slice
.y
== 0)
3333 y
+= s
->img
->vmargin
;
3337 x_set_glyph_string_clipping (s
);
3340 mac_draw_cg_image (s
->img
->data
.ptr_val
,
3341 s
->f
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
3342 s
->slice
.width
, s
->slice
.height
, x
, y
, 1);
3346 mac_copy_area_with_mask (s
->img
->pixmap
, s
->img
->mask
,
3347 s
->f
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
3348 s
->slice
.width
, s
->slice
.height
, x
, y
);
3355 mac_copy_area (s
->img
->pixmap
,
3356 s
->f
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
3357 s
->slice
.width
, s
->slice
.height
, x
, y
);
3360 /* When the image has a mask, we can expect that at
3361 least part of a mouse highlight or a block cursor will
3362 be visible. If the image doesn't have a mask, make
3363 a block cursor visible by drawing a rectangle around
3364 the image. I believe it's looking better if we do
3365 nothing here for mouse-face. */
3366 if (s
->hl
== DRAW_CURSOR
)
3368 int r
= s
->img
->relief
;
3370 mac_draw_rectangle (s
->f
, s
->gc
, x
- r
, y
- r
,
3371 s
->slice
.width
+ r
*2 - 1,
3372 s
->slice
.height
+ r
*2 - 1);
3377 /* Draw a rectangle if image could not be loaded. */
3378 mac_draw_rectangle (s
->f
, s
->gc
, x
, y
,
3379 s
->slice
.width
- 1, s
->slice
.height
- 1);
3383 /* Draw a relief around the image glyph string S. */
3386 x_draw_image_relief (s
)
3387 struct glyph_string
*s
;
3389 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3392 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
3394 /* If first glyph of S has a left box line, start drawing it to the
3395 right of that line. */
3396 if (s
->face
->box
!= FACE_NO_BOX
3397 && s
->first_glyph
->left_box_line_p
3399 x
+= abs (s
->face
->box_line_width
);
3401 /* If there is a margin around the image, adjust x- and y-position
3403 if (s
->slice
.x
== 0)
3404 x
+= s
->img
->hmargin
;
3405 if (s
->slice
.y
== 0)
3406 y
+= s
->img
->vmargin
;
3408 if (s
->hl
== DRAW_IMAGE_SUNKEN
3409 || s
->hl
== DRAW_IMAGE_RAISED
)
3411 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3412 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3416 thick
= abs (s
->img
->relief
);
3417 raised_p
= s
->img
->relief
> 0;
3422 x1
= x
+ s
->slice
.width
+ thick
- 1;
3423 y1
= y
+ s
->slice
.height
+ thick
- 1;
3425 x_setup_relief_colors (s
);
3426 get_glyph_string_clip_rect (s
, &r
);
3427 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
3429 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
3431 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
3436 /* Draw part of the background of glyph string S. X, Y, W, and H
3437 give the rectangle to draw. */
3440 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3441 struct glyph_string
*s
;
3444 #if 0 /* MAC_TODO: stipple */
3447 /* Fill background with a stipple pattern. */
3448 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3449 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3450 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3453 #endif /* MAC_TODO */
3454 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3458 /* Draw image glyph string S.
3461 s->x +-------------------------
3464 | +-------------------------
3467 | | +-------------------
3473 x_draw_image_glyph_string (s
)
3474 struct glyph_string
*s
;
3477 int box_line_hwidth
= abs (s
->face
->box_line_width
);
3478 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
3481 height
= s
->height
- 2 * box_line_vwidth
;
3484 /* Fill background with face under the image. Do it only if row is
3485 taller than image or if image has a clip mask to reduce
3487 s
->stippled_p
= s
->face
->stipple
!= 0;
3488 if (height
> s
->slice
.height
3492 || s
->img
->pixmap
== 0
3493 || s
->width
!= s
->background_width
)
3496 if (s
->first_glyph
->left_box_line_p
3498 x
+= box_line_hwidth
;
3501 if (s
->slice
.y
== 0)
3502 y
+= box_line_vwidth
;
3504 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
3506 s
->background_filled_p
= 1;
3509 /* Draw the foreground. */
3510 x_draw_image_foreground (s
);
3512 /* If we must draw a relief around the image, do it. */
3514 || s
->hl
== DRAW_IMAGE_RAISED
3515 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3516 x_draw_image_relief (s
);
3520 /* Draw stretch glyph string S. */
3523 x_draw_stretch_glyph_string (s
)
3524 struct glyph_string
*s
;
3526 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
3527 s
->stippled_p
= s
->face
->stipple
!= 0;
3529 if (s
->hl
== DRAW_CURSOR
3530 && !x_stretch_cursor_p
)
3532 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
3533 as wide as the stretch glyph. */
3534 int width
, background_width
= s
->background_width
;
3535 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
3539 background_width
-= left_x
- x
;
3542 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
3545 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
3547 /* Clear rest using the GC of the original non-cursor face. */
3548 if (width
< background_width
)
3551 int w
= background_width
- width
, h
= s
->height
;
3556 if (s
->row
->mouse_face_p
3557 && cursor_in_mouse_face_p (s
->w
))
3559 x_set_mouse_face_gc (s
);
3565 get_glyph_string_clip_rect (s
, &r
);
3566 mac_set_clip_rectangles (s
->display
, gc
, &r
, 1);
3568 #if 0 /* MAC_TODO: stipple */
3569 if (s
->face
->stipple
)
3571 /* Fill background with a stipple pattern. */
3572 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
3573 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3574 XSetFillStyle (s
->display
, gc
, FillSolid
);
3577 #endif /* MAC_TODO */
3578 mac_erase_rectangle (s
->f
, gc
, x
, y
, w
, h
);
3581 else if (!s
->background_filled_p
)
3583 int background_width
= s
->background_width
;
3584 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
3586 /* Don't draw into left margin, fringe or scrollbar area
3587 except for header line and mode line. */
3588 if (x
< left_x
&& !s
->row
->mode_line_p
)
3590 background_width
-= left_x
- x
;
3593 if (background_width
> 0)
3594 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
3597 s
->background_filled_p
= 1;
3601 /* Draw glyph string S. */
3604 x_draw_glyph_string (s
)
3605 struct glyph_string
*s
;
3607 int relief_drawn_p
= 0;
3609 /* If S draws into the background of its successor that does not
3610 draw a cursor, draw the background of the successor first so that
3611 S can draw into it. This makes S->next use XDrawString instead
3612 of XDrawImageString. */
3613 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
3614 && s
->next
->hl
!= DRAW_CURSOR
)
3616 xassert (s
->next
->img
== NULL
);
3617 x_set_glyph_string_gc (s
->next
);
3618 x_set_glyph_string_clipping (s
->next
);
3619 x_draw_glyph_string_background (s
->next
, 1);
3622 /* Set up S->gc, set clipping and draw S. */
3623 x_set_glyph_string_gc (s
);
3625 /* Draw relief (if any) in advance for char/composition so that the
3626 glyph string can be drawn over it. */
3627 if (!s
->for_overlaps
3628 && s
->face
->box
!= FACE_NO_BOX
3629 && (s
->first_glyph
->type
== CHAR_GLYPH
3630 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
3633 x_set_glyph_string_clipping (s
);
3634 x_draw_glyph_string_background (s
, 1);
3635 x_draw_glyph_string_box (s
);
3636 x_set_glyph_string_clipping (s
);
3640 x_set_glyph_string_clipping (s
);
3642 switch (s
->first_glyph
->type
)
3645 x_draw_image_glyph_string (s
);
3649 x_draw_stretch_glyph_string (s
);
3653 if (s
->for_overlaps
)
3654 s
->background_filled_p
= 1;
3656 x_draw_glyph_string_background (s
, 0);
3657 x_draw_glyph_string_foreground (s
);
3660 case COMPOSITE_GLYPH
:
3661 if (s
->for_overlaps
|| s
->gidx
> 0)
3662 s
->background_filled_p
= 1;
3664 x_draw_glyph_string_background (s
, 1);
3665 x_draw_composite_glyph_string_foreground (s
);
3672 if (!s
->for_overlaps
)
3674 /* Draw underline. */
3675 if (s
->face
->underline_p
)
3677 unsigned long h
= 1;
3678 unsigned long dy
= s
->height
- h
;
3680 if (s
->face
->underline_defaulted_p
)
3681 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3682 s
->background_width
, h
);
3686 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3687 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
3688 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3689 s
->background_width
, h
);
3690 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3694 /* Draw overline. */
3695 if (s
->face
->overline_p
)
3697 unsigned long dy
= 0, h
= 1;
3699 if (s
->face
->overline_color_defaulted_p
)
3700 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3701 s
->background_width
, h
);
3705 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3706 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
3707 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3708 s
->background_width
, h
);
3709 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3713 /* Draw strike-through. */
3714 if (s
->face
->strike_through_p
)
3716 unsigned long h
= 1;
3717 unsigned long dy
= (s
->height
- h
) / 2;
3719 if (s
->face
->strike_through_color_defaulted_p
)
3720 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3725 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3726 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
3727 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3729 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3733 /* Draw relief if not yet drawn. */
3734 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3735 x_draw_glyph_string_box (s
);
3738 /* Reset clipping. */
3739 mac_reset_clip_rectangles (s
->display
, s
->gc
);
3742 /* Shift display to make room for inserted glyphs. */
3745 mac_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
3747 int x
, y
, width
, height
, shift_by
;
3749 mac_scroll_area (f
, f
->output_data
.mac
->normal_gc
,
3750 x
, y
, width
, height
,
3754 /* Delete N glyphs at the nominal cursor position. Not implemented
3765 /* Clear entire frame. If updating_frame is non-null, clear that
3766 frame. Otherwise clear the selected frame. */
3776 f
= SELECTED_FRAME ();
3778 /* Clearing the frame will erase any cursor, so mark them all as no
3780 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3781 output_cursor
.hpos
= output_cursor
.vpos
= 0;
3782 output_cursor
.x
= -1;
3784 /* We don't set the output cursor here because there will always
3785 follow an explicit cursor_to. */
3787 mac_clear_window (f
);
3789 /* We have to clear the scroll bars, too. If we have changed
3790 colors or something like that, then they should be notified. */
3791 x_scroll_bar_clear (f
);
3793 XFlush (FRAME_MAC_DISPLAY (f
));
3799 /* Invert the middle quarter of the frame for .15 sec. */
3801 /* We use the select system call to do the waiting, so we have to make
3802 sure it's available. If it isn't, we just won't do visual bells. */
3804 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3807 /* Subtract the `struct timeval' values X and Y, storing the result in
3808 *RESULT. Return 1 if the difference is negative, otherwise 0. */
3811 timeval_subtract (result
, x
, y
)
3812 struct timeval
*result
, x
, y
;
3814 /* Perform the carry for the later subtraction by updating y. This
3815 is safer because on some systems the tv_sec member is unsigned. */
3816 if (x
.tv_usec
< y
.tv_usec
)
3818 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
3819 y
.tv_usec
-= 1000000 * nsec
;
3823 if (x
.tv_usec
- y
.tv_usec
> 1000000)
3825 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
3826 y
.tv_usec
+= 1000000 * nsec
;
3830 /* Compute the time remaining to wait. tv_usec is certainly
3832 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
3833 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
3835 /* Return indication of whether the result should be considered
3837 return x
.tv_sec
< y
.tv_sec
;
3844 /* Get the height not including a menu bar widget. */
3845 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
3846 /* Height of each line to flash. */
3847 int flash_height
= FRAME_LINE_HEIGHT (f
);
3848 /* These will be the left and right margins of the rectangles. */
3849 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3850 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3854 /* Don't flash the area between a scroll bar and the frame
3855 edge it is next to. */
3856 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
3858 case vertical_scroll_bar_left
:
3859 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3862 case vertical_scroll_bar_right
:
3863 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3870 width
= flash_right
- flash_left
;
3874 /* If window is tall, flash top and bottom line. */
3875 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3877 mac_invert_rectangle (f
, flash_left
,
3878 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3879 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3880 width
, flash_height
);
3881 mac_invert_rectangle (f
, flash_left
,
3882 (height
- flash_height
3883 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3884 width
, flash_height
);
3887 /* If it is short, flash it all. */
3888 mac_invert_rectangle (f
, flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3889 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3894 struct timeval wakeup
;
3896 EMACS_GET_TIME (wakeup
);
3898 /* Compute time to wait until, propagating carry from usecs. */
3899 wakeup
.tv_usec
+= 150000;
3900 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
3901 wakeup
.tv_usec
%= 1000000;
3903 /* Keep waiting until past the time wakeup or any input gets
3905 while (! detect_input_pending ())
3907 struct timeval current
;
3908 struct timeval timeout
;
3910 EMACS_GET_TIME (current
);
3912 /* Break if result would be negative. */
3913 if (timeval_subtract (¤t
, wakeup
, current
))
3916 /* How long `select' should wait. */
3918 timeout
.tv_usec
= 10000;
3920 /* Try to wait that long--but we might wake up sooner. */
3921 select (0, NULL
, NULL
, NULL
, &timeout
);
3925 /* If window is tall, flash top and bottom line. */
3926 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3928 mac_invert_rectangle (f
, flash_left
,
3929 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3930 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3931 width
, flash_height
);
3932 mac_invert_rectangle (f
, flash_left
,
3933 (height
- flash_height
3934 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3935 width
, flash_height
);
3938 /* If it is short, flash it all. */
3939 mac_invert_rectangle (f
, flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3940 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3947 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3950 /* Make audible bell. */
3955 struct frame
*f
= SELECTED_FRAME ();
3957 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3965 XFlush (FRAME_MAC_DISPLAY (f
));
3971 /* Specify how many text lines, from the top of the window,
3972 should be affected by insert-lines and delete-lines operations.
3973 This, and those operations, are used only within an update
3974 that is bounded by calls to x_update_begin and x_update_end. */
3977 XTset_terminal_window (n
)
3980 /* This function intentionally left blank. */
3985 /***********************************************************************
3987 ***********************************************************************/
3989 /* Perform an insert-lines or delete-lines operation, inserting N
3990 lines or deleting -N lines at vertical position VPOS. */
3993 x_ins_del_lines (vpos
, n
)
4000 /* Scroll part of the display as described by RUN. */
4003 x_scroll_run (w
, run
)
4007 struct frame
*f
= XFRAME (w
->frame
);
4008 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
4010 /* Get frame-relative bounding box of the text display area of W,
4011 without mode lines. Include in this box the left and right
4013 window_box (w
, -1, &x
, &y
, &width
, &height
);
4015 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
4016 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
4017 bottom_y
= y
+ height
;
4021 /* Scrolling up. Make sure we don't copy part of the mode
4022 line at the bottom. */
4023 if (from_y
+ run
->height
> bottom_y
)
4024 height
= bottom_y
- from_y
;
4026 height
= run
->height
;
4030 /* Scolling down. Make sure we don't copy over the mode line.
4032 if (to_y
+ run
->height
> bottom_y
)
4033 height
= bottom_y
- to_y
;
4035 height
= run
->height
;
4040 /* Cursor off. Will be switched on again in x_update_window_end. */
4044 mac_scroll_area (f
, f
->output_data
.mac
->normal_gc
,
4054 /***********************************************************************
4056 ***********************************************************************/
4064 ControlRef root_control
;
4067 err
= GetRootControl (FRAME_MAC_WINDOW (f
), &root_control
);
4069 ActivateControl (root_control
);
4071 x_update_cursor (f
, 1);
4075 frame_unhighlight (f
)
4079 ControlRef root_control
;
4082 err
= GetRootControl (FRAME_MAC_WINDOW (f
), &root_control
);
4084 DeactivateControl (root_control
);
4086 x_update_cursor (f
, 1);
4089 /* The focus has changed. Update the frames as necessary to reflect
4090 the new situation. Note that we can't change the selected frame
4091 here, because the Lisp code we are interrupting might become confused.
4092 Each event gets marked with the frame in which it occurred, so the
4093 Lisp code can tell when the switch took place by examining the events. */
4096 x_new_focus_frame (dpyinfo
, frame
)
4097 struct x_display_info
*dpyinfo
;
4098 struct frame
*frame
;
4100 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
4102 if (frame
!= dpyinfo
->x_focus_frame
)
4104 /* Set this before calling other routines, so that they see
4105 the correct value of x_focus_frame. */
4106 dpyinfo
->x_focus_frame
= frame
;
4108 if (old_focus
&& old_focus
->auto_lower
)
4109 x_lower_frame (old_focus
);
4112 selected_frame
= frame
;
4113 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
4115 Fselect_window (selected_frame
->selected_window
, Qnil
);
4116 choose_minibuf_frame ();
4119 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
4120 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
4122 pending_autoraise_frame
= 0;
4124 #if USE_MAC_FONT_PANEL
4126 mac_set_font_info_for_selection (frame
, DEFAULT_FACE_ID
, 0);
4130 x_frame_rehighlight (dpyinfo
);
4133 /* Handle FocusIn and FocusOut state changes for FRAME.
4134 If FRAME has focus and there exists more than one frame, puts
4135 a FOCUS_IN_EVENT into *BUFP. */
4138 mac_focus_changed (type
, dpyinfo
, frame
, bufp
)
4140 struct mac_display_info
*dpyinfo
;
4141 struct frame
*frame
;
4142 struct input_event
*bufp
;
4144 if (type
== activeFlag
)
4146 if (dpyinfo
->x_focus_event_frame
!= frame
)
4148 x_new_focus_frame (dpyinfo
, frame
);
4149 dpyinfo
->x_focus_event_frame
= frame
;
4151 /* Don't stop displaying the initial startup message
4152 for a switch-frame event we don't need. */
4153 if (GC_NILP (Vterminal_frame
)
4154 && GC_CONSP (Vframe_list
)
4155 && !GC_NILP (XCDR (Vframe_list
)))
4157 bufp
->kind
= FOCUS_IN_EVENT
;
4158 XSETFRAME (bufp
->frame_or_window
, frame
);
4164 if (dpyinfo
->x_focus_event_frame
== frame
)
4166 dpyinfo
->x_focus_event_frame
= 0;
4167 x_new_focus_frame (dpyinfo
, 0);
4172 /* The focus may have changed. Figure out if it is a real focus change,
4173 by checking both FocusIn/Out and Enter/LeaveNotify events.
4175 Returns FOCUS_IN_EVENT event in *BUFP. */
4178 x_detect_focus_change (dpyinfo
, event
, bufp
)
4179 struct mac_display_info
*dpyinfo
;
4181 struct input_event
*bufp
;
4183 struct frame
*frame
;
4185 frame
= mac_window_to_frame ((WindowPtr
) event
->message
);
4189 /* On Mac, this is only called from focus events, so no switch needed. */
4190 mac_focus_changed ((event
->modifiers
& activeFlag
),
4191 dpyinfo
, frame
, bufp
);
4195 /* Handle an event saying the mouse has moved out of an Emacs frame. */
4198 x_mouse_leave (dpyinfo
)
4199 struct x_display_info
*dpyinfo
;
4201 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
4204 /* The focus has changed, or we have redirected a frame's focus to
4205 another frame (this happens when a frame uses a surrogate
4206 mini-buffer frame). Shift the highlight as appropriate.
4208 The FRAME argument doesn't necessarily have anything to do with which
4209 frame is being highlighted or un-highlighted; we only use it to find
4210 the appropriate X display info. */
4213 XTframe_rehighlight (frame
)
4214 struct frame
*frame
;
4216 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
4220 x_frame_rehighlight (dpyinfo
)
4221 struct x_display_info
*dpyinfo
;
4223 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
4225 if (dpyinfo
->x_focus_frame
)
4227 dpyinfo
->x_highlight_frame
4228 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
4229 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
4230 : dpyinfo
->x_focus_frame
);
4231 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
4233 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
4234 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
4238 dpyinfo
->x_highlight_frame
= 0;
4240 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
4243 frame_unhighlight (old_highlight
);
4244 if (dpyinfo
->x_highlight_frame
)
4245 frame_highlight (dpyinfo
->x_highlight_frame
);
4251 /* Convert a keysym to its name. */
4254 x_get_keysym_name (keysym
)
4261 value
= XKeysymToString (keysym
);
4272 /* Function to report a mouse movement to the mainstream Emacs code.
4273 The input handler calls this.
4275 We have received a mouse movement event, which is given in *event.
4276 If the mouse is over a different glyph than it was last time, tell
4277 the mainstream emacs code by setting mouse_moved. If not, ask for
4278 another motion event, so we can check again the next time it moves. */
4280 static Point last_mouse_motion_position
;
4281 static Lisp_Object last_mouse_motion_frame
;
4284 note_mouse_movement (frame
, pos
)
4288 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (frame
);
4289 #if TARGET_API_MAC_CARBON
4293 last_mouse_movement_time
= TickCount () * (1000 / 60); /* to milliseconds */
4294 last_mouse_motion_position
= *pos
;
4295 XSETFRAME (last_mouse_motion_frame
, frame
);
4297 #if TARGET_API_MAC_CARBON
4298 if (!PtInRect (*pos
, GetWindowPortBounds (FRAME_MAC_WINDOW (frame
), &r
)))
4300 if (!PtInRect (*pos
, &FRAME_MAC_WINDOW (frame
)->portRect
))
4303 if (frame
== dpyinfo
->mouse_face_mouse_frame
)
4304 /* This case corresponds to LeaveNotify in X11. */
4306 /* If we move outside the frame, then we're certainly no
4307 longer on any text in the frame. */
4308 clear_mouse_face (dpyinfo
);
4309 dpyinfo
->mouse_face_mouse_frame
= 0;
4310 if (!dpyinfo
->grabbed
)
4311 rif
->define_frame_cursor (frame
,
4312 frame
->output_data
.mac
->nontext_cursor
);
4316 /* Has the mouse moved off the glyph it was on at the last sighting? */
4317 if (frame
!= last_mouse_glyph_frame
4318 || !PtInRect (*pos
, &last_mouse_glyph
))
4320 frame
->mouse_moved
= 1;
4321 last_mouse_scroll_bar
= Qnil
;
4322 note_mouse_highlight (frame
, pos
->h
, pos
->v
);
4323 /* Remember which glyph we're now on. */
4324 remember_mouse_glyph (frame
, pos
->h
, pos
->v
, &last_mouse_glyph
);
4325 last_mouse_glyph_frame
= frame
;
4333 /************************************************************************
4335 ************************************************************************/
4337 /* MAC TODO: This should be called from somewhere (or removed) ++KFS */
4340 redo_mouse_highlight ()
4342 if (!NILP (last_mouse_motion_frame
)
4343 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
4344 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
4345 last_mouse_motion_position
.h
,
4346 last_mouse_motion_position
.v
);
4350 static struct frame
*
4351 mac_focus_frame (dpyinfo
)
4352 struct mac_display_info
*dpyinfo
;
4354 if (dpyinfo
->x_focus_frame
)
4355 return dpyinfo
->x_focus_frame
;
4357 /* Mac version may get events, such as a menu bar click, even when
4358 all the frames are invisible. In this case, we regard the
4359 event came to the selected frame. */
4360 return SELECTED_FRAME ();
4364 /* Return the current position of the mouse.
4365 *FP should be a frame which indicates which display to ask about.
4367 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
4368 and *PART to the frame, window, and scroll bar part that the mouse
4369 is over. Set *X and *Y to the portion and whole of the mouse's
4370 position on the scroll bar.
4372 If the mouse movement started elsewhere, set *FP to the frame the
4373 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
4376 Set *TIME to the server time-stamp for the time at which the mouse
4377 was at this position.
4379 Don't store anything if we don't have a valid set of values to report.
4381 This clears the mouse_moved flag, so we can wait for the next mouse
4385 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
4388 Lisp_Object
*bar_window
;
4389 enum scroll_bar_part
*part
;
4391 unsigned long *time
;
4397 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
4398 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
4401 Lisp_Object frame
, tail
;
4403 /* Clear the mouse-moved flag for every frame on this display. */
4404 FOR_EACH_FRAME (tail
, frame
)
4405 XFRAME (frame
)->mouse_moved
= 0;
4407 last_mouse_scroll_bar
= Qnil
;
4409 if (FRAME_MAC_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
4410 && FRAME_LIVE_P (last_mouse_frame
))
4411 f1
= last_mouse_frame
;
4413 f1
= mac_focus_frame (FRAME_MAC_DISPLAY_INFO (*fp
));
4417 /* Ok, we found a frame. Store all the values.
4418 last_mouse_glyph is a rectangle used to reduce the
4419 generation of mouse events. To not miss any motion
4420 events, we must divide the frame into rectangles of the
4421 size of the smallest character that could be displayed
4422 on it, i.e. into the same rectangles that matrices on
4423 the frame are divided into. */
4426 SetPortWindowPort (FRAME_MAC_WINDOW (f1
));
4427 GetMouse (&mouse_pos
);
4428 remember_mouse_glyph (f1
, mouse_pos
.h
, mouse_pos
.v
,
4430 last_mouse_glyph_frame
= f1
;
4435 XSETINT (*x
, mouse_pos
.h
);
4436 XSETINT (*y
, mouse_pos
.v
);
4437 *time
= last_mouse_movement_time
;
4445 /************************************************************************
4447 ************************************************************************/
4449 #ifdef USE_TOOLKIT_SCROLL_BARS
4451 static pascal void scroll_bar_timer_callback
P_ ((EventLoopTimerRef
, void *));
4452 static OSStatus install_scroll_bar_timer
P_ ((void));
4453 static OSStatus set_scroll_bar_timer
P_ ((EventTimerInterval
));
4454 static int control_part_code_to_scroll_bar_part
P_ ((ControlPartCode
));
4455 static void construct_scroll_bar_click
P_ ((struct scroll_bar
*, int,
4456 struct input_event
*));
4457 static OSStatus get_control_part_bounds
P_ ((ControlHandle
, ControlPartCode
,
4459 static void x_scroll_bar_handle_press
P_ ((struct scroll_bar
*,
4461 struct input_event
*));
4462 static void x_scroll_bar_handle_release
P_ ((struct scroll_bar
*,
4463 struct input_event
*));
4464 static void x_scroll_bar_handle_drag
P_ ((WindowPtr
, struct scroll_bar
*,
4465 Point
, struct input_event
*));
4466 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
4469 /* Last scroll bar part sent in x_scroll_bar_handle_*. */
4471 static int last_scroll_bar_part
;
4473 static EventLoopTimerRef scroll_bar_timer
;
4475 static int scroll_bar_timer_event_posted_p
;
4477 #define SCROLL_BAR_FIRST_DELAY 0.5
4478 #define SCROLL_BAR_CONTINUOUS_DELAY (1.0 / 15)
4481 scroll_bar_timer_callback (timer
, data
)
4482 EventLoopTimerRef timer
;
4487 err
= mac_post_mouse_moved_event ();
4489 scroll_bar_timer_event_posted_p
= 1;
4493 install_scroll_bar_timer ()
4495 static EventLoopTimerUPP scroll_bar_timer_callbackUPP
= NULL
;
4497 if (scroll_bar_timer_callbackUPP
== NULL
)
4498 scroll_bar_timer_callbackUPP
=
4499 NewEventLoopTimerUPP (scroll_bar_timer_callback
);
4501 if (scroll_bar_timer
== NULL
)
4502 /* Mac OS X and CarbonLib 1.5 and later allow us to specify
4503 kEventDurationForever as delays. */
4505 InstallEventLoopTimer (GetCurrentEventLoop (),
4506 kEventDurationForever
, kEventDurationForever
,
4507 scroll_bar_timer_callbackUPP
, NULL
,
4512 set_scroll_bar_timer (delay
)
4513 EventTimerInterval delay
;
4515 if (scroll_bar_timer
== NULL
)
4516 install_scroll_bar_timer ();
4518 scroll_bar_timer_event_posted_p
= 0;
4520 return SetEventLoopTimerNextFireTime (scroll_bar_timer
, delay
);
4524 control_part_code_to_scroll_bar_part (part_code
)
4525 ControlPartCode part_code
;
4529 case kControlUpButtonPart
: return scroll_bar_up_arrow
;
4530 case kControlDownButtonPart
: return scroll_bar_down_arrow
;
4531 case kControlPageUpPart
: return scroll_bar_above_handle
;
4532 case kControlPageDownPart
: return scroll_bar_below_handle
;
4533 case kControlIndicatorPart
: return scroll_bar_handle
;
4540 construct_scroll_bar_click (bar
, part
, bufp
)
4541 struct scroll_bar
*bar
;
4543 struct input_event
*bufp
;
4545 bufp
->kind
= SCROLL_BAR_CLICK_EVENT
;
4546 bufp
->frame_or_window
= bar
->window
;
4550 XSETINT (bufp
->x
, 0);
4551 XSETINT (bufp
->y
, 0);
4552 bufp
->modifiers
= 0;
4556 get_control_part_bounds (ch
, part_code
, rect
)
4558 ControlPartCode part_code
;
4561 RgnHandle region
= NewRgn ();
4564 err
= GetControlRegion (ch
, part_code
, region
);
4566 GetRegionBounds (region
, rect
);
4567 DisposeRgn (region
);
4573 x_scroll_bar_handle_press (bar
, part_code
, bufp
)
4574 struct scroll_bar
*bar
;
4575 ControlPartCode part_code
;
4576 struct input_event
*bufp
;
4578 int part
= control_part_code_to_scroll_bar_part (part_code
);
4583 if (part
!= scroll_bar_handle
)
4585 construct_scroll_bar_click (bar
, part
, bufp
);
4586 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), part_code
);
4587 set_scroll_bar_timer (SCROLL_BAR_FIRST_DELAY
);
4590 last_scroll_bar_part
= part
;
4591 bar
->dragging
= Qnil
;
4592 tracked_scroll_bar
= bar
;
4596 x_scroll_bar_handle_release (bar
, bufp
)
4597 struct scroll_bar
*bar
;
4598 struct input_event
*bufp
;
4600 if (last_scroll_bar_part
!= scroll_bar_handle
4601 || !GC_NILP (bar
->dragging
))
4602 construct_scroll_bar_click (bar
, scroll_bar_end_scroll
, bufp
);
4604 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), 0);
4605 set_scroll_bar_timer (kEventDurationForever
);
4607 last_scroll_bar_part
= -1;
4608 bar
->dragging
= Qnil
;
4609 tracked_scroll_bar
= NULL
;
4613 x_scroll_bar_handle_drag (win
, bar
, mouse_pos
, bufp
)
4615 struct scroll_bar
*bar
;
4617 struct input_event
*bufp
;
4619 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4621 if (last_scroll_bar_part
== scroll_bar_handle
)
4626 get_control_part_bounds (SCROLL_BAR_CONTROL_HANDLE (bar
),
4627 kControlIndicatorPart
, &r
);
4629 if (GC_NILP (bar
->dragging
))
4630 XSETINT (bar
->dragging
, mouse_pos
.v
- r
.top
);
4632 top
= mouse_pos
.v
- XINT (bar
->dragging
) - XINT (bar
->track_top
);
4633 top_range
= (XINT (bar
->track_height
) - (r
.bottom
- r
.top
)) *
4634 (1.0 + (float) GetControlViewSize (ch
) / GetControl32BitMaximum (ch
))
4639 if (top
> top_range
)
4642 construct_scroll_bar_click (bar
, scroll_bar_handle
, bufp
);
4643 XSETINT (bufp
->x
, top
);
4644 XSETINT (bufp
->y
, top_range
);
4648 ControlPartCode part_code
;
4649 int unhilite_p
= 0, part
;
4651 if (ch
!= FindControlUnderMouse (mouse_pos
, win
, &part_code
))
4655 part
= control_part_code_to_scroll_bar_part (part_code
);
4657 switch (last_scroll_bar_part
)
4659 case scroll_bar_above_handle
:
4660 case scroll_bar_below_handle
:
4661 if (part
!= scroll_bar_above_handle
4662 && part
!= scroll_bar_below_handle
)
4666 case scroll_bar_up_arrow
:
4667 case scroll_bar_down_arrow
:
4668 if (part
!= scroll_bar_up_arrow
4669 && part
!= scroll_bar_down_arrow
)
4676 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), 0);
4677 else if (part
!= last_scroll_bar_part
4678 || scroll_bar_timer_event_posted_p
)
4680 construct_scroll_bar_click (bar
, part
, bufp
);
4681 last_scroll_bar_part
= part
;
4682 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), part_code
);
4683 set_scroll_bar_timer (SCROLL_BAR_CONTINUOUS_DELAY
);
4688 /* Set the thumb size and position of scroll bar BAR. We are currently
4689 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4692 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4693 struct scroll_bar
*bar
;
4694 int portion
, position
, whole
;
4696 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4697 int value
, viewsize
, maximum
;
4699 if (XINT (bar
->track_height
) == 0)
4703 value
= 0, viewsize
= 1, maximum
= 0;
4708 maximum
= max (0, whole
- portion
);
4713 if (GetControlViewSize (ch
) != viewsize
4714 || GetControl32BitValue (ch
) != value
4715 || GetControl32BitMaximum (ch
) != maximum
)
4717 /* Temporarily hide the scroll bar to avoid multiple redraws. */
4718 SetControlVisibility (ch
, false, false);
4720 SetControl32BitMaximum (ch
, maximum
);
4721 SetControl32BitValue (ch
, value
);
4722 SetControlViewSize (ch
, viewsize
);
4724 SetControlVisibility (ch
, true, true);
4730 #endif /* USE_TOOLKIT_SCROLL_BARS */
4734 /************************************************************************
4735 Scroll bars, general
4736 ************************************************************************/
4738 /* Create a scroll bar and return the scroll bar vector for it. W is
4739 the Emacs window on which to create the scroll bar. TOP, LEFT,
4740 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4743 static struct scroll_bar
*
4744 x_scroll_bar_create (w
, top
, left
, width
, height
, disp_top
, disp_height
)
4746 int top
, left
, width
, height
, disp_top
, disp_height
;
4748 struct frame
*f
= XFRAME (w
->frame
);
4749 struct scroll_bar
*bar
4750 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
4758 r
.right
= left
+ width
;
4759 r
.bottom
= disp_top
+ disp_height
;
4762 mac_prepare_for_quickdraw (f
);
4764 #if TARGET_API_MAC_CARBON
4765 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p",
4766 #if USE_TOOLKIT_SCROLL_BARS
4769 width
< disp_height
,
4771 0, 0, 0, kControlScrollBarProc
, (long) bar
);
4773 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p", width
< disp_height
,
4774 0, 0, 0, scrollBarProc
, (long) bar
);
4776 SET_SCROLL_BAR_CONTROL_HANDLE (bar
, ch
);
4778 XSETWINDOW (bar
->window
, w
);
4779 XSETINT (bar
->top
, top
);
4780 XSETINT (bar
->left
, left
);
4781 XSETINT (bar
->width
, width
);
4782 XSETINT (bar
->height
, height
);
4783 XSETINT (bar
->start
, 0);
4784 XSETINT (bar
->end
, 0);
4785 bar
->dragging
= Qnil
;
4786 #ifdef USE_TOOLKIT_SCROLL_BARS
4787 bar
->track_top
= Qnil
;
4788 bar
->track_height
= Qnil
;
4791 /* Add bar to its frame's list of scroll bars. */
4792 bar
->next
= FRAME_SCROLL_BARS (f
);
4794 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4795 if (!NILP (bar
->next
))
4796 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4803 /* Draw BAR's handle in the proper position.
4805 If the handle is already drawn from START to END, don't bother
4806 redrawing it, unless REBUILD is non-zero; in that case, always
4807 redraw it. (REBUILD is handy for drawing the handle after expose
4810 Normally, we want to constrain the start and end of the handle to
4811 fit inside its rectangle, but if the user is dragging the scroll
4812 bar handle, we want to let them drag it down all the way, so that
4813 the bar's top is as far down as it goes; otherwise, there's no way
4814 to move to the very end of the buffer. */
4816 #ifndef USE_TOOLKIT_SCROLL_BARS
4819 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
4820 struct scroll_bar
*bar
;
4824 int dragging
= ! NILP (bar
->dragging
);
4825 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4826 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4827 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
4828 int length
= end
- start
;
4830 /* If the display is already accurate, do nothing. */
4832 && start
== XINT (bar
->start
)
4833 && end
== XINT (bar
->end
))
4838 /* Make sure the values are reasonable, and try to preserve the
4839 distance between start and end. */
4842 else if (start
> top_range
)
4844 end
= start
+ length
;
4848 else if (end
> top_range
&& ! dragging
)
4851 /* Store the adjusted setting in the scroll bar. */
4852 XSETINT (bar
->start
, start
);
4853 XSETINT (bar
->end
, end
);
4855 /* Clip the end position, just for display. */
4856 if (end
> top_range
)
4859 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
4860 top positions, to make sure the handle is always at least that
4861 many pixels tall. */
4862 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4864 SetControlMinimum (ch
, 0);
4865 /* Don't inadvertently activate deactivated scroll bars */
4866 if (GetControlMaximum (ch
) != -1)
4867 SetControlMaximum (ch
, top_range
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
4869 SetControlValue (ch
, start
);
4870 #if TARGET_API_MAC_CARBON
4871 SetControlViewSize (ch
, end
- start
);
4877 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4879 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4883 x_scroll_bar_remove (bar
)
4884 struct scroll_bar
*bar
;
4886 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4891 mac_prepare_for_quickdraw (f
);
4893 /* Destroy the Mac scroll bar control */
4894 DisposeControl (SCROLL_BAR_CONTROL_HANDLE (bar
));
4896 /* Disassociate this scroll bar from its window. */
4897 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
4903 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4904 that we are displaying PORTION characters out of a total of WHOLE
4905 characters, starting at POSITION. If WINDOW has no scroll bar,
4909 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
4911 int portion
, whole
, position
;
4913 struct frame
*f
= XFRAME (w
->frame
);
4914 struct scroll_bar
*bar
;
4915 int top
, height
, left
, sb_left
, width
, sb_width
, disp_top
, disp_height
;
4916 int window_y
, window_height
;
4918 /* Get window dimensions. */
4919 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
4921 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
4922 height
= window_height
;
4924 /* Compute the left edge of the scroll bar area. */
4925 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
4927 /* Compute the width of the scroll bar which might be less than
4928 the width of the area reserved for the scroll bar. */
4929 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
4930 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
4934 /* Compute the left edge of the scroll bar. */
4935 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
4938 sb_left
= left
+ width
- sb_width
;
4940 /* Adjustments according to Inside Macintosh to make it look nice */
4942 disp_height
= height
;
4949 else if (disp_top
== FRAME_PIXEL_HEIGHT (f
) - 16)
4955 if (sb_left
+ sb_width
== FRAME_PIXEL_WIDTH (f
))
4959 /* Does the scroll bar exist yet? */
4960 if (NILP (w
->vertical_scroll_bar
))
4963 mac_clear_area (f
, left
, top
, width
, height
);
4965 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
, disp_top
,
4967 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
4971 /* It may just need to be moved and resized. */
4974 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
4975 ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4979 /* If already correctly positioned, do nothing. */
4980 if (!(XINT (bar
->left
) == sb_left
4981 && XINT (bar
->top
) == top
4982 && XINT (bar
->width
) == sb_width
4983 && XINT (bar
->height
) == height
))
4985 /* Since toolkit scroll bars are smaller than the space reserved
4986 for them on the frame, we have to clear "under" them. */
4987 mac_clear_area (f
, left
, top
, width
, height
);
4990 mac_prepare_for_quickdraw (f
);
4993 MoveControl (ch
, sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
, disp_top
);
4994 SizeControl (ch
, sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4996 #ifndef USE_TOOLKIT_SCROLL_BARS
4997 if (sb_width
< disp_height
)
5001 /* Remember new settings. */
5002 XSETINT (bar
->left
, sb_left
);
5003 XSETINT (bar
->top
, top
);
5004 XSETINT (bar
->width
, sb_width
);
5005 XSETINT (bar
->height
, height
);
5006 #ifdef USE_TOOLKIT_SCROLL_BARS
5007 bar
->track_top
= Qnil
;
5008 bar
->track_height
= Qnil
;
5015 #ifdef USE_TOOLKIT_SCROLL_BARS
5016 if (NILP (bar
->track_top
))
5018 if (sb_width
>= disp_height
)
5020 XSETINT (bar
->track_top
, 0);
5021 XSETINT (bar
->track_height
, 0);
5025 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
5030 SetControl32BitMinimum (ch
, 0);
5031 SetControl32BitMaximum (ch
, 1);
5032 SetControlViewSize (ch
, 1);
5034 /* Move the scroll bar thumb to the top. */
5035 SetControl32BitValue (ch
, 0);
5036 get_control_part_bounds (ch
, kControlIndicatorPart
, &r0
);
5038 /* Move the scroll bar thumb to the bottom. */
5039 SetControl32BitValue (ch
, 1);
5040 get_control_part_bounds (ch
, kControlIndicatorPart
, &r1
);
5042 UnionRect (&r0
, &r1
, &r0
);
5043 XSETINT (bar
->track_top
, r0
.top
);
5044 XSETINT (bar
->track_height
, r0
.bottom
- r0
.top
);
5046 /* Don't show the scroll bar if its height is not enough to
5047 display the scroll bar thumb. */
5048 if (r0
.bottom
- r0
.top
> 0)
5055 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5056 #else /* not USE_TOOLKIT_SCROLL_BARS */
5057 /* Set the scroll bar's current state, unless we're currently being
5059 if (NILP (bar
->dragging
))
5061 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5064 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5067 int start
= ((double) position
* top_range
) / whole
;
5068 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5069 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5072 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5076 /* The following three hooks are used when we're doing a thorough
5077 redisplay of the frame. We don't explicitly know which scroll bars
5078 are going to be deleted, because keeping track of when windows go
5079 away is a real pain - "Can you say set-window-configuration, boys
5080 and girls?" Instead, we just assert at the beginning of redisplay
5081 that *all* scroll bars are to be removed, and then save a scroll bar
5082 from the fiery pit when we actually redisplay its window. */
5084 /* Arrange for all scroll bars on FRAME to be removed at the next call
5085 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5086 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5089 XTcondemn_scroll_bars (frame
)
5092 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5093 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5096 bar
= FRAME_SCROLL_BARS (frame
);
5097 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5098 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5099 XSCROLL_BAR (bar
)->prev
= Qnil
;
5100 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5101 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5102 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5107 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5108 Note that WINDOW isn't necessarily condemned at all. */
5111 XTredeem_scroll_bar (window
)
5112 struct window
*window
;
5114 struct scroll_bar
*bar
;
5117 /* We can't redeem this window's scroll bar if it doesn't have one. */
5118 if (NILP (window
->vertical_scroll_bar
))
5121 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5123 /* Unlink it from the condemned list. */
5124 f
= XFRAME (WINDOW_FRAME (window
));
5125 if (NILP (bar
->prev
))
5127 /* If the prev pointer is nil, it must be the first in one of
5129 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5130 /* It's not condemned. Everything's fine. */
5132 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5133 window
->vertical_scroll_bar
))
5134 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5136 /* If its prev pointer is nil, it must be at the front of
5137 one or the other! */
5141 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5143 if (! NILP (bar
->next
))
5144 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5146 bar
->next
= FRAME_SCROLL_BARS (f
);
5148 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5149 if (! NILP (bar
->next
))
5150 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5153 /* Remove all scroll bars on FRAME that haven't been saved since the
5154 last call to `*condemn_scroll_bars_hook'. */
5157 XTjudge_scroll_bars (f
)
5160 Lisp_Object bar
, next
;
5162 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5164 /* Clear out the condemned list now so we won't try to process any
5165 more events on the hapless scroll bars. */
5166 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5168 for (; ! NILP (bar
); bar
= next
)
5170 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5172 x_scroll_bar_remove (b
);
5175 b
->next
= b
->prev
= Qnil
;
5178 /* Now there should be no references to the condemned scroll bars,
5179 and they should get garbage-collected. */
5183 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5184 is set to something other than NO_EVENT, it is enqueued.
5186 This may be called from a signal handler, so we have to ignore GC
5190 x_scroll_bar_handle_click (bar
, part_code
, er
, bufp
)
5191 struct scroll_bar
*bar
;
5192 ControlPartCode part_code
;
5194 struct input_event
*bufp
;
5196 int win_y
, top_range
;
5198 if (! GC_WINDOWP (bar
->window
))
5201 bufp
->kind
= SCROLL_BAR_CLICK_EVENT
;
5202 bufp
->frame_or_window
= bar
->window
;
5205 bar
->dragging
= Qnil
;
5209 case kControlUpButtonPart
:
5210 bufp
->part
= scroll_bar_up_arrow
;
5212 case kControlDownButtonPart
:
5213 bufp
->part
= scroll_bar_down_arrow
;
5215 case kControlPageUpPart
:
5216 bufp
->part
= scroll_bar_above_handle
;
5218 case kControlPageDownPart
:
5219 bufp
->part
= scroll_bar_below_handle
;
5221 #if TARGET_API_MAC_CARBON
5224 case kControlIndicatorPart
:
5226 if (er
->what
== mouseDown
)
5227 bar
->dragging
= make_number (0);
5228 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5229 bufp
->part
= scroll_bar_handle
;
5233 win_y
= XINT (bufp
->y
) - XINT (bar
->top
);
5234 top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (0/*dummy*/, XINT (bar
->height
));
5236 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5240 if (! NILP (bar
->dragging
))
5241 win_y
-= XINT (bar
->dragging
);
5245 if (win_y
> top_range
)
5248 XSETINT (bufp
->x
, win_y
);
5249 XSETINT (bufp
->y
, top_range
);
5252 #ifndef USE_TOOLKIT_SCROLL_BARS
5254 /* Handle some mouse motion while someone is dragging the scroll bar.
5256 This may be called from a signal handler, so we have to ignore GC
5260 x_scroll_bar_note_movement (bar
, y_pos
, t
)
5261 struct scroll_bar
*bar
;
5265 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5267 last_mouse_movement_time
= t
;
5270 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5272 /* If we're dragging the bar, display it. */
5273 if (! GC_NILP (bar
->dragging
))
5275 /* Where should the handle be now? */
5276 int new_start
= y_pos
- 24;
5278 if (new_start
!= XINT (bar
->start
))
5280 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
5282 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5287 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5289 /* Return information to the user about the current position of the mouse
5290 on the scroll bar. */
5293 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
5295 Lisp_Object
*bar_window
;
5296 enum scroll_bar_part
*part
;
5298 unsigned long *time
;
5300 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5301 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
5302 #if TARGET_API_MAC_CARBON
5303 WindowPtr wp
= GetControlOwner (ch
);
5305 WindowPtr wp
= (*ch
)->contrlOwner
;
5308 struct frame
*f
= mac_window_to_frame (wp
);
5309 int win_y
, top_range
;
5311 SetPortWindowPort (wp
);
5313 GetMouse (&mouse_pos
);
5315 win_y
= mouse_pos
.v
- XINT (bar
->top
);
5316 top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
5318 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5322 if (! NILP (bar
->dragging
))
5323 win_y
-= XINT (bar
->dragging
);
5327 if (win_y
> top_range
)
5331 *bar_window
= bar
->window
;
5333 if (! NILP (bar
->dragging
))
5334 *part
= scroll_bar_handle
;
5335 else if (win_y
< XINT (bar
->start
))
5336 *part
= scroll_bar_above_handle
;
5337 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5338 *part
= scroll_bar_handle
;
5340 *part
= scroll_bar_below_handle
;
5342 XSETINT (*x
, win_y
);
5343 XSETINT (*y
, top_range
);
5346 last_mouse_scroll_bar
= Qnil
;
5348 *time
= last_mouse_movement_time
;
5352 /* The screen has been cleared so we may have changed foreground or
5353 background colors, and the scroll bars may need to be redrawn.
5354 Clear out the scroll bars, and ask for expose events, so we can
5358 x_scroll_bar_clear (f
)
5361 XTcondemn_scroll_bars (f
);
5362 XTjudge_scroll_bars (f
);
5366 /***********************************************************************
5368 ***********************************************************************/
5370 /* Set clipping for output in glyph row ROW. W is the window in which
5371 we operate. GC is the graphics context to set clipping in.
5373 ROW may be a text row or, e.g., a mode line. Text rows must be
5374 clipped to the interior of the window dedicated to text display,
5375 mode lines must be clipped to the whole window. */
5378 x_clip_to_row (w
, row
, area
, gc
)
5380 struct glyph_row
*row
;
5384 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5386 int window_x
, window_y
, window_width
;
5388 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
5390 clip_rect
.left
= window_x
;
5391 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
5392 clip_rect
.top
= max (clip_rect
.top
, window_y
);
5393 clip_rect
.right
= clip_rect
.left
+ window_width
;
5394 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
5396 mac_set_clip_rectangles (FRAME_MAC_DISPLAY (f
), gc
, &clip_rect
, 1);
5400 /* Draw a hollow box cursor on window W in glyph row ROW. */
5403 x_draw_hollow_cursor (w
, row
)
5405 struct glyph_row
*row
;
5407 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5408 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
5409 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
5412 struct glyph
*cursor_glyph
;
5415 /* Get the glyph the cursor is on. If we can't tell because
5416 the current matrix is invalid or such, give up. */
5417 cursor_glyph
= get_phys_cursor_glyph (w
);
5418 if (cursor_glyph
== NULL
)
5421 /* Compute frame-relative coordinates for phys cursor. */
5422 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
5423 wd
= w
->phys_cursor_width
;
5425 /* The foreground of cursor_gc is typically the same as the normal
5426 background color, which can cause the cursor box to be invisible. */
5427 xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
5428 if (dpyinfo
->scratch_cursor_gc
)
5429 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
5431 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_MAC_WINDOW (f
),
5432 GCForeground
, &xgcv
);
5433 gc
= dpyinfo
->scratch_cursor_gc
;
5435 /* Set clipping, draw the rectangle, and reset clipping again. */
5436 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
5437 mac_draw_rectangle (f
, gc
, x
, y
, wd
, h
- 1);
5438 mac_reset_clip_rectangles (dpy
, gc
);
5442 /* Draw a bar cursor on window W in glyph row ROW.
5444 Implementation note: One would like to draw a bar cursor with an
5445 angle equal to the one given by the font property XA_ITALIC_ANGLE.
5446 Unfortunately, I didn't find a font yet that has this property set.
5450 x_draw_bar_cursor (w
, row
, width
, kind
)
5452 struct glyph_row
*row
;
5454 enum text_cursor_kinds kind
;
5456 struct frame
*f
= XFRAME (w
->frame
);
5457 struct glyph
*cursor_glyph
;
5459 /* If cursor is out of bounds, don't draw garbage. This can happen
5460 in mini-buffer windows when switching between echo area glyphs
5462 cursor_glyph
= get_phys_cursor_glyph (w
);
5463 if (cursor_glyph
== NULL
)
5466 /* If on an image, draw like a normal cursor. That's usually better
5467 visible than drawing a bar, esp. if the image is large so that
5468 the bar might not be in the window. */
5469 if (cursor_glyph
->type
== IMAGE_GLYPH
)
5471 struct glyph_row
*row
;
5472 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
5473 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
5477 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
5478 Window window
= FRAME_MAC_WINDOW (f
);
5479 GC gc
= FRAME_MAC_DISPLAY_INFO (f
)->scratch_cursor_gc
;
5480 unsigned long mask
= GCForeground
| GCBackground
;
5481 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
5484 /* If the glyph's background equals the color we normally draw
5485 the bar cursor in, the bar cursor in its normal color is
5486 invisible. Use the glyph's foreground color instead in this
5487 case, on the assumption that the glyph's colors are chosen so
5488 that the glyph is legible. */
5489 if (face
->background
== f
->output_data
.mac
->cursor_pixel
)
5490 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
5492 xgcv
.background
= xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
5495 XChangeGC (dpy
, gc
, mask
, &xgcv
);
5498 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
5499 FRAME_MAC_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
5503 width
= FRAME_CURSOR_WIDTH (f
);
5504 width
= min (cursor_glyph
->pixel_width
, width
);
5506 w
->phys_cursor_width
= width
;
5507 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
5509 if (kind
== BAR_CURSOR
)
5510 mac_fill_rectangle (f
, gc
,
5511 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
5512 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
5513 width
, row
->height
);
5515 mac_fill_rectangle (f
, gc
,
5516 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
5517 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
5518 row
->height
- width
),
5519 cursor_glyph
->pixel_width
,
5522 mac_reset_clip_rectangles (dpy
, gc
);
5527 /* RIF: Define cursor CURSOR on frame F. */
5530 mac_define_frame_cursor (f
, cursor
)
5534 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
5536 if (dpyinfo
->x_focus_frame
== f
)
5537 SetThemeCursor (cursor
);
5541 /* RIF: Clear area on frame F. */
5544 mac_clear_frame_area (f
, x
, y
, width
, height
)
5546 int x
, y
, width
, height
;
5548 mac_clear_area (f
, x
, y
, width
, height
);
5552 /* RIF: Draw cursor on window W. */
5555 mac_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
5557 struct glyph_row
*glyph_row
;
5559 int cursor_type
, cursor_width
;
5564 w
->phys_cursor_type
= cursor_type
;
5565 w
->phys_cursor_on_p
= 1;
5567 if (glyph_row
->exact_window_width_line_p
5568 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
5570 glyph_row
->cursor_in_fringe_p
= 1;
5571 draw_fringe_bitmap (w
, glyph_row
, 0);
5574 switch (cursor_type
)
5576 case HOLLOW_BOX_CURSOR
:
5577 x_draw_hollow_cursor (w
, glyph_row
);
5580 case FILLED_BOX_CURSOR
:
5581 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
5585 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
5589 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
5593 w
->phys_cursor_width
= 0;
5605 #if 0 /* MAC_TODO: no icon support yet. */
5607 x_bitmap_icon (f
, icon
)
5613 if (FRAME_W32_WINDOW (f
) == 0)
5617 hicon
= LoadIcon (hinst
, EMACS_CLASS
);
5618 else if (STRINGP (icon
))
5619 hicon
= LoadImage (NULL
, (LPCTSTR
) SDATA (icon
), IMAGE_ICON
, 0, 0,
5620 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
5621 else if (SYMBOLP (icon
))
5625 if (EQ (icon
, intern ("application")))
5626 name
= (LPCTSTR
) IDI_APPLICATION
;
5627 else if (EQ (icon
, intern ("hand")))
5628 name
= (LPCTSTR
) IDI_HAND
;
5629 else if (EQ (icon
, intern ("question")))
5630 name
= (LPCTSTR
) IDI_QUESTION
;
5631 else if (EQ (icon
, intern ("exclamation")))
5632 name
= (LPCTSTR
) IDI_EXCLAMATION
;
5633 else if (EQ (icon
, intern ("asterisk")))
5634 name
= (LPCTSTR
) IDI_ASTERISK
;
5635 else if (EQ (icon
, intern ("winlogo")))
5636 name
= (LPCTSTR
) IDI_WINLOGO
;
5640 hicon
= LoadIcon (NULL
, name
);
5648 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
5653 #endif /* MAC_TODO */
5655 /************************************************************************
5657 ************************************************************************/
5659 /* Display Error Handling functions not used on W32. Listing them here
5660 helps diff stay in step when comparing w32term.c with xterm.c.
5662 x_error_catcher (display, error)
5663 x_catch_errors (dpy)
5664 x_catch_errors_unwind (old_val)
5665 x_check_errors (dpy, format)
5666 x_had_errors_p (dpy)
5667 x_clear_errors (dpy)
5668 x_uncatch_errors (dpy, count)
5670 x_connection_signal (signalnum)
5671 x_connection_closed (dpy, error_message)
5672 x_error_quitter (display, error)
5673 x_error_handler (display, error)
5674 x_io_error_quitter (display)
5679 /* Changing the font of the frame. */
5681 /* Give frame F the font named FONTNAME as its default font, and
5682 return the full name of that font. FONTNAME may be a wildcard
5683 pattern; in that case, we choose some font that fits the pattern.
5684 The return value shows which font we chose. */
5687 x_new_font (f
, fontname
)
5689 register char *fontname
;
5691 struct font_info
*fontp
5692 = FS_LOAD_FONT (f
, 0, fontname
, -1);
5697 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
5698 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
5699 FRAME_FONTSET (f
) = -1;
5701 FRAME_COLUMN_WIDTH (f
) = fontp
->average_width
;
5702 FRAME_SPACE_WIDTH (f
) = fontp
->space_width
;
5703 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (FRAME_FONT (f
));
5705 compute_fringe_widths (f
, 1);
5707 /* Compute the scroll bar width in character columns. */
5708 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
5710 int wid
= FRAME_COLUMN_WIDTH (f
);
5711 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
5712 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
5716 int wid
= FRAME_COLUMN_WIDTH (f
);
5717 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
5720 /* Now make the frame display the given font. */
5721 if (FRAME_MAC_WINDOW (f
) != 0)
5723 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->normal_gc
,
5725 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->reverse_gc
,
5727 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->cursor_gc
,
5730 /* Don't change the size of a tip frame; there's no point in
5731 doing it because it's done in Fx_show_tip, and it leads to
5732 problems because the tip frame has no widget. */
5733 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
5734 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
5737 return build_string (fontp
->full_name
);
5740 /* Give frame F the fontset named FONTSETNAME as its default font, and
5741 return the full name of that fontset. FONTSETNAME may be a wildcard
5742 pattern; in that case, we choose some fontset that fits the pattern.
5743 The return value shows which fontset we chose. */
5746 x_new_fontset (f
, fontsetname
)
5750 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
5756 if (FRAME_FONTSET (f
) == fontset
)
5757 /* This fontset is already set in frame F. There's nothing more
5759 return fontset_name (fontset
);
5761 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
5763 if (!STRINGP (result
))
5764 /* Can't load ASCII font. */
5767 /* Since x_new_font doesn't update any fontset information, do it now. */
5768 FRAME_FONTSET (f
) = fontset
;
5770 return build_string (fontsetname
);
5774 /***********************************************************************
5775 TODO: W32 Input Methods
5776 ***********************************************************************/
5777 /* Listing missing functions from xterm.c helps diff stay in step.
5779 xim_destroy_callback (xim, client_data, call_data)
5780 xim_open_dpy (dpyinfo, resource_name)
5782 xim_instantiate_callback (display, client_data, call_data)
5783 xim_initialize (dpyinfo, resource_name)
5784 xim_close_dpy (dpyinfo)
5790 mac_get_window_bounds (f
, inner
, outer
)
5792 Rect
*inner
, *outer
;
5794 #if TARGET_API_MAC_CARBON
5795 GetWindowBounds (FRAME_MAC_WINDOW (f
), kWindowContentRgn
, inner
);
5796 GetWindowBounds (FRAME_MAC_WINDOW (f
), kWindowStructureRgn
, outer
);
5797 #else /* not TARGET_API_MAC_CARBON */
5798 RgnHandle region
= NewRgn ();
5800 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowContentRgn
, region
);
5801 *inner
= (*region
)->rgnBBox
;
5802 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowStructureRgn
, region
);
5803 *outer
= (*region
)->rgnBBox
;
5804 DisposeRgn (region
);
5805 #endif /* not TARGET_API_MAC_CARBON */
5809 mac_handle_origin_change (f
)
5812 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
5816 mac_handle_size_change (f
, pixelwidth
, pixelheight
)
5818 int pixelwidth
, pixelheight
;
5822 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, pixelwidth
);
5823 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, pixelheight
);
5825 if (cols
!= FRAME_COLS (f
)
5826 || rows
!= FRAME_LINES (f
)
5827 || pixelwidth
!= FRAME_PIXEL_WIDTH (f
)
5828 || pixelheight
!= FRAME_PIXEL_HEIGHT (f
))
5830 /* We pass 1 for DELAY since we can't run Lisp code inside of
5832 change_frame_size (f
, rows
, cols
, 0, 1, 0);
5833 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
5834 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
5835 SET_FRAME_GARBAGED (f
);
5837 /* If cursor was outside the new size, mark it as off. */
5838 mark_window_cursors_off (XWINDOW (f
->root_window
));
5840 /* Clear out any recollection of where the mouse highlighting
5841 was, since it might be in a place that's outside the new
5842 frame size. Actually checking whether it is outside is a
5843 pain in the neck, so don't try--just let the highlighting be
5844 done afresh with new size. */
5845 cancel_mouse_face (f
);
5847 #if TARGET_API_MAC_CARBON
5848 if (f
->output_data
.mac
->hourglass_control
)
5851 mac_prepare_for_quickdraw (f
);
5853 MoveControl (f
->output_data
.mac
->hourglass_control
,
5854 pixelwidth
- HOURGLASS_WIDTH
, 0);
5861 /* Calculate the absolute position in frame F
5862 from its current recorded position values and gravity. */
5865 x_calc_absolute_position (f
)
5868 int width_diff
= 0, height_diff
= 0;
5869 int flags
= f
->size_hint_flags
;
5872 /* We have nothing to do if the current position
5873 is already for the top-left corner. */
5874 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
5877 /* Find the offsets of the outside upper-left corner of
5878 the inner window, with respect to the outer window. */
5879 mac_get_window_bounds (f
, &inner
, &outer
);
5881 width_diff
= (outer
.right
- outer
.left
) - (inner
.right
- inner
.left
);
5882 height_diff
= (outer
.bottom
- outer
.top
) - (inner
.bottom
- inner
.top
);
5884 /* Treat negative positions as relative to the leftmost bottommost
5885 position that fits on the screen. */
5886 if (flags
& XNegative
)
5887 f
->left_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->width
5889 - FRAME_PIXEL_WIDTH (f
)
5892 if (flags
& YNegative
)
5893 f
->top_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->height
5895 - FRAME_PIXEL_HEIGHT (f
)
5898 /* The left_pos and top_pos
5899 are now relative to the top and left screen edges,
5900 so the flags should correspond. */
5901 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5904 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
5905 to really change the position, and 0 when calling from
5906 x_make_frame_visible (in that case, XOFF and YOFF are the current
5907 position values). It is -1 when calling from x_set_frame_parameters,
5908 which means, do adjust for borders but don't change the gravity. */
5911 x_set_offset (f
, xoff
, yoff
, change_gravity
)
5913 register int xoff
, yoff
;
5916 if (change_gravity
> 0)
5920 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5922 f
->size_hint_flags
|= XNegative
;
5924 f
->size_hint_flags
|= YNegative
;
5925 f
->win_gravity
= NorthWestGravity
;
5927 x_calc_absolute_position (f
);
5930 x_wm_set_size_hint (f
, (long) 0, 0);
5932 #if TARGET_API_MAC_CARBON
5933 MoveWindowStructure (FRAME_MAC_WINDOW (f
), f
->left_pos
, f
->top_pos
);
5934 /* If the title bar is completely outside the screen, adjust the
5936 ConstrainWindowToScreen (FRAME_MAC_WINDOW (f
), kWindowTitleBarRgn
,
5937 kWindowConstrainMoveRegardlessOfFit
5938 | kWindowConstrainAllowPartial
, NULL
, NULL
);
5939 #if USE_CARBON_EVENTS
5940 if (!NILP (tip_frame
) && XFRAME (tip_frame
) == f
)
5942 mac_handle_origin_change (f
);
5945 Rect inner
, outer
, screen_rect
, dummy
;
5946 RgnHandle region
= NewRgn ();
5948 mac_get_window_bounds (f
, &inner
, &outer
);
5949 f
->x_pixels_diff
= inner
.left
- outer
.left
;
5950 f
->y_pixels_diff
= inner
.top
- outer
.top
;
5951 MoveWindow (FRAME_MAC_WINDOW (f
), f
->left_pos
+ f
->x_pixels_diff
,
5952 f
->top_pos
+ f
->y_pixels_diff
, false);
5954 /* If the title bar is completely outside the screen, adjust the
5955 position. The variable `outer' holds the title bar rectangle.
5956 The variable `inner' holds slightly smaller one than `outer',
5957 so that the calculation of overlapping may not become too
5959 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowTitleBarRgn
, region
);
5960 outer
= (*region
)->rgnBBox
;
5961 DisposeRgn (region
);
5963 InsetRect (&inner
, 8, 8);
5964 screen_rect
= qd
.screenBits
.bounds
;
5965 screen_rect
.top
+= GetMBarHeight ();
5967 if (!SectRect (&inner
, &screen_rect
, &dummy
))
5969 if (inner
.right
<= screen_rect
.left
)
5970 f
->left_pos
= screen_rect
.left
;
5971 else if (inner
.left
>= screen_rect
.right
)
5972 f
->left_pos
= screen_rect
.right
- (outer
.right
- outer
.left
);
5974 if (inner
.bottom
<= screen_rect
.top
)
5975 f
->top_pos
= screen_rect
.top
;
5976 else if (inner
.top
>= screen_rect
.bottom
)
5977 f
->top_pos
= screen_rect
.bottom
- (outer
.bottom
- outer
.top
);
5979 MoveWindow (FRAME_MAC_WINDOW (f
), f
->left_pos
+ f
->x_pixels_diff
,
5980 f
->top_pos
+ f
->y_pixels_diff
, false);
5988 /* Call this to change the size of frame F's x-window.
5989 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
5990 for this size change and subsequent size changes.
5991 Otherwise we leave the window gravity unchanged. */
5994 x_set_window_size (f
, change_gravity
, cols
, rows
)
5999 int pixelwidth
, pixelheight
;
6003 check_frame_size (f
, &rows
, &cols
);
6004 f
->scroll_bar_actual_width
6005 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
6007 compute_fringe_widths (f
, 0);
6009 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
6010 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
6012 f
->win_gravity
= NorthWestGravity
;
6013 x_wm_set_size_hint (f
, (long) 0, 0);
6015 SizeWindow (FRAME_MAC_WINDOW (f
), pixelwidth
, pixelheight
, 0);
6017 #if USE_CARBON_EVENTS
6018 if (!NILP (tip_frame
) && f
== XFRAME (tip_frame
))
6020 mac_handle_size_change (f
, pixelwidth
, pixelheight
);
6025 /* Mouse warping. */
6027 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
6030 x_set_mouse_position (f
, x
, y
)
6036 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
6037 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
6039 if (pix_x
< 0) pix_x
= 0;
6040 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
6042 if (pix_y
< 0) pix_y
= 0;
6043 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
6045 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
6049 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
6058 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
6064 CGWarpMouseCursorPosition (point
);
6067 #if 0 /* MAC_TODO: LMSetMouseLocation and CursorDeviceMoveTo are non-Carbon */
6070 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
6071 0, 0, 0, 0, pix_x
, pix_y
);
6077 /* focus shifting, raising and lowering. */
6080 x_focus_on_frame (f
)
6083 #if 0 /* This proves to be unpleasant. */
6087 /* I don't think that the ICCCM allows programs to do things like this
6088 without the interaction of the window manager. Whatever you end up
6089 doing with this code, do it to x_unfocus_frame too. */
6090 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6091 RevertToPointerRoot
, CurrentTime
);
6101 /* Raise frame F. */
6107 if (f
->async_visible
)
6110 BringToFront (FRAME_MAC_WINDOW (f
));
6115 /* Lower frame F. */
6121 if (f
->async_visible
)
6124 SendBehind (FRAME_MAC_WINDOW (f
), NULL
);
6130 XTframe_raise_lower (f
, raise_flag
)
6140 /* Change of visibility. */
6143 mac_handle_visibility_change (f
)
6146 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
6147 int visible
= 0, iconified
= 0;
6148 struct input_event buf
;
6150 if (IsWindowVisible (wp
))
6152 if (IsWindowCollapsed (wp
))
6158 if (!f
->async_visible
&& visible
)
6162 /* wait_reading_process_output will notice this and update
6163 the frame's display structures. If we were made
6164 invisible, we should not set garbaged, because that stops
6165 redrawing on Update events. */
6166 SET_FRAME_GARBAGED (f
);
6169 buf
.kind
= DEICONIFY_EVENT
;
6170 XSETFRAME (buf
.frame_or_window
, f
);
6172 kbd_buffer_store_event (&buf
);
6174 else if (! NILP (Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
6175 /* Force a redisplay sooner or later to update the
6176 frame titles in case this is the second frame. */
6177 record_asynch_buffer_change ();
6179 else if (f
->async_visible
&& !visible
)
6183 buf
.kind
= ICONIFY_EVENT
;
6184 XSETFRAME (buf
.frame_or_window
, f
);
6186 kbd_buffer_store_event (&buf
);
6189 f
->async_visible
= visible
;
6190 f
->async_iconified
= iconified
;
6193 /* This tries to wait until the frame is really visible.
6194 However, if the window manager asks the user where to position
6195 the frame, this will return before the user finishes doing that.
6196 The frame will not actually be visible at that time,
6197 but it will become visible later when the window manager
6198 finishes with it. */
6201 x_make_frame_visible (f
)
6206 if (! FRAME_VISIBLE_P (f
))
6208 /* We test FRAME_GARBAGED_P here to make sure we don't
6209 call x_set_offset a second time
6210 if we get to x_make_frame_visible a second time
6211 before the window gets really visible. */
6212 if (! FRAME_ICONIFIED_P (f
)
6213 && ! f
->output_data
.mac
->asked_for_visible
)
6215 #if TARGET_API_MAC_CARBON
6216 if (!(FRAME_SIZE_HINTS (f
)->flags
& (USPosition
| PPosition
)))
6218 struct frame
*sf
= SELECTED_FRAME ();
6219 if (!FRAME_MAC_P (sf
))
6220 RepositionWindow (FRAME_MAC_WINDOW (f
), NULL
,
6221 kWindowCenterOnMainScreen
);
6223 RepositionWindow (FRAME_MAC_WINDOW (f
),
6224 FRAME_MAC_WINDOW (sf
),
6225 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
6226 kWindowCascadeStartAtParentWindowScreen
6228 kWindowCascadeOnParentWindowScreen
6231 #if USE_CARBON_EVENTS
6232 if (!NILP (tip_frame
) && f
== XFRAME (tip_frame
))
6234 mac_handle_origin_change (f
);
6238 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
6241 f
->output_data
.mac
->asked_for_visible
= 1;
6243 CollapseWindow (FRAME_MAC_WINDOW (f
), false);
6244 ShowWindow (FRAME_MAC_WINDOW (f
));
6247 XFlush (FRAME_MAC_DISPLAY (f
));
6249 /* Synchronize to ensure Emacs knows the frame is visible
6250 before we do anything else. We do this loop with input not blocked
6251 so that incoming events are handled. */
6256 /* This must come after we set COUNT. */
6259 XSETFRAME (frame
, f
);
6261 /* Wait until the frame is visible. Process X events until a
6262 MapNotify event has been seen, or until we think we won't get a
6263 MapNotify at all.. */
6264 for (count
= input_signal_count
+ 10;
6265 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
6267 /* Force processing of queued events. */
6270 /* Machines that do polling rather than SIGIO have been
6271 observed to go into a busy-wait here. So we'll fake an
6272 alarm signal to let the handler know that there's something
6273 to be read. We used to raise a real alarm, but it seems
6274 that the handler isn't always enabled here. This is
6276 if (input_polling_used ())
6278 /* It could be confusing if a real alarm arrives while
6279 processing the fake one. Turn it off and let the
6280 handler reset it. */
6281 extern void poll_for_input_1
P_ ((void));
6282 int old_poll_suppress_count
= poll_suppress_count
;
6283 poll_suppress_count
= 1;
6284 poll_for_input_1 ();
6285 poll_suppress_count
= old_poll_suppress_count
;
6288 /* See if a MapNotify event has been processed. */
6289 FRAME_SAMPLE_VISIBILITY (f
);
6294 /* Change from mapped state to withdrawn state. */
6296 /* Make the frame visible (mapped and not iconified). */
6299 x_make_frame_invisible (f
)
6302 /* A deactivate event does not occur when the last visible frame is
6303 made invisible. So if we clear the highlight here, it will not
6304 be rehighlighted when it is made visible. */
6306 /* Don't keep the highlight on an invisible frame. */
6307 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
6308 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
6313 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
6314 that the current position of the window is user-specified, rather than
6315 program-specified, so that when the window is mapped again, it will be
6316 placed at the same location, without forcing the user to position it
6317 by hand again (they have already done that once for this window.) */
6318 x_wm_set_size_hint (f
, (long) 0, 1);
6320 HideWindow (FRAME_MAC_WINDOW (f
));
6324 #if !USE_CARBON_EVENTS
6325 mac_handle_visibility_change (f
);
6329 /* Change window state from mapped to iconified. */
6337 /* A deactivate event does not occur when the last visible frame is
6338 iconified. So if we clear the highlight here, it will not be
6339 rehighlighted when it is deiconified. */
6341 /* Don't keep the highlight on an invisible frame. */
6342 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
6343 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
6346 if (f
->async_iconified
)
6351 FRAME_SAMPLE_VISIBILITY (f
);
6353 if (! FRAME_VISIBLE_P (f
))
6354 ShowWindow (FRAME_MAC_WINDOW (f
));
6356 err
= CollapseWindow (FRAME_MAC_WINDOW (f
), true);
6361 error ("Can't notify window manager of iconification");
6363 #if !USE_CARBON_EVENTS
6364 mac_handle_visibility_change (f
);
6369 /* Free X resources of frame F. */
6372 x_free_frame_resources (f
)
6375 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6376 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
6380 if (wp
!= tip_window
)
6381 remove_window_handler (wp
);
6384 if (wp
== tip_window
)
6385 /* Neither WaitNextEvent nor ReceiveNextEvent receives `window
6386 closed' event. So we reset tip_window here. */
6389 free_frame_menubar (f
);
6391 if (FRAME_FACE_CACHE (f
))
6392 free_frame_faces (f
);
6396 if (FRAME_SIZE_HINTS (f
))
6397 xfree (FRAME_SIZE_HINTS (f
));
6399 xfree (f
->output_data
.mac
);
6400 f
->output_data
.mac
= NULL
;
6402 if (f
== dpyinfo
->x_focus_frame
)
6404 dpyinfo
->x_focus_frame
= 0;
6405 #if USE_MAC_FONT_PANEL
6406 mac_set_font_info_for_selection (NULL
, DEFAULT_FACE_ID
, 0);
6409 if (f
== dpyinfo
->x_focus_event_frame
)
6410 dpyinfo
->x_focus_event_frame
= 0;
6411 if (f
== dpyinfo
->x_highlight_frame
)
6412 dpyinfo
->x_highlight_frame
= 0;
6414 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6416 dpyinfo
->mouse_face_beg_row
6417 = dpyinfo
->mouse_face_beg_col
= -1;
6418 dpyinfo
->mouse_face_end_row
6419 = dpyinfo
->mouse_face_end_col
= -1;
6420 dpyinfo
->mouse_face_window
= Qnil
;
6421 dpyinfo
->mouse_face_deferred_gc
= 0;
6422 dpyinfo
->mouse_face_mouse_frame
= 0;
6429 /* Destroy the X window of frame F. */
6432 x_destroy_window (f
)
6435 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6437 x_free_frame_resources (f
);
6439 dpyinfo
->reference_count
--;
6443 /* Setting window manager hints. */
6445 /* Set the normal size hints for the window manager, for frame F.
6446 FLAGS is the flags word to use--or 0 meaning preserve the flags
6447 that the window now has.
6448 If USER_POSITION is nonzero, we set the USPosition
6449 flag (this is useful when FLAGS is 0). */
6451 x_wm_set_size_hint (f
, flags
, user_position
)
6456 int base_width
, base_height
, width_inc
, height_inc
;
6457 int min_rows
= 0, min_cols
= 0;
6458 XSizeHints
*size_hints
;
6460 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
6461 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
6462 width_inc
= FRAME_COLUMN_WIDTH (f
);
6463 height_inc
= FRAME_LINE_HEIGHT (f
);
6465 check_frame_size (f
, &min_rows
, &min_cols
);
6467 size_hints
= FRAME_SIZE_HINTS (f
);
6468 if (size_hints
== NULL
)
6470 size_hints
= FRAME_SIZE_HINTS (f
) = xmalloc (sizeof (XSizeHints
));
6471 bzero (size_hints
, sizeof (XSizeHints
));
6474 size_hints
->flags
|= PResizeInc
| PMinSize
| PBaseSize
;
6475 size_hints
->width_inc
= width_inc
;
6476 size_hints
->height_inc
= height_inc
;
6477 size_hints
->min_width
= base_width
+ min_cols
* width_inc
;
6478 size_hints
->min_height
= base_height
+ min_rows
* height_inc
;
6479 size_hints
->base_width
= base_width
;
6480 size_hints
->base_height
= base_height
;
6483 size_hints
->flags
= flags
;
6484 else if (user_position
)
6486 size_hints
->flags
&= ~ PPosition
;
6487 size_hints
->flags
|= USPosition
;
6491 #if 0 /* MAC_TODO: hide application instead of iconify? */
6492 /* Used for IconicState or NormalState */
6495 x_wm_set_window_state (f
, state
)
6499 #ifdef USE_X_TOOLKIT
6502 XtSetArg (al
[0], XtNinitialState
, state
);
6503 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6504 #else /* not USE_X_TOOLKIT */
6505 Window window
= FRAME_X_WINDOW (f
);
6507 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
6508 f
->output_data
.x
->wm_hints
.initial_state
= state
;
6510 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6511 #endif /* not USE_X_TOOLKIT */
6515 x_wm_set_icon_pixmap (f
, pixmap_id
)
6521 #ifndef USE_X_TOOLKIT
6522 Window window
= FRAME_X_WINDOW (f
);
6527 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
6528 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
6532 /* It seems there is no way to turn off use of an icon pixmap.
6533 The following line does it, only if no icon has yet been created,
6534 for some window managers. But with mwm it crashes.
6535 Some people say it should clear the IconPixmapHint bit in this case,
6536 but that doesn't work, and the X consortium said it isn't the
6537 right thing at all. Since there is no way to win,
6538 best to explicitly give up. */
6540 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
6546 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
6550 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
6551 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6554 #else /* not USE_X_TOOLKIT */
6556 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
6557 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6559 #endif /* not USE_X_TOOLKIT */
6562 #endif /* MAC_TODO */
6565 x_wm_set_icon_position (f
, icon_x
, icon_y
)
6569 #if 0 /* MAC_TODO: no icons on Mac */
6570 #ifdef USE_X_TOOLKIT
6571 Window window
= XtWindow (f
->output_data
.x
->widget
);
6573 Window window
= FRAME_X_WINDOW (f
);
6576 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
6577 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
6578 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
6580 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6581 #endif /* MAC_TODO */
6585 /***********************************************************************
6587 ***********************************************************************/
6589 /* An XLFD pattern is divided into blocks delimited by '*'. This
6590 structure holds information for each block. */
6591 struct xlfdpat_block
6593 /* Length of the pattern string in this block. Non-zero except for
6594 the first and the last blocks. */
6597 /* Pattern string except the last character in this block. The last
6598 character is replaced with NUL in order to use it as a
6600 unsigned char *pattern
;
6602 /* Last character of the pattern string. Must not be '?'. */
6603 unsigned char last_char
;
6605 /* One of the tables for the Boyer-Moore string search. It
6606 specifies the number of positions to proceed for each character
6607 with which the match fails. */
6610 /* The skip value for the last character in the above `skip' is
6611 assigned to `infinity' in order to simplify a loop condition.
6612 The original value is saved here. */
6618 /* Normalized pattern string. "Normalized" means that capital
6619 letters are lowered, blocks are not empty except the first and
6620 the last ones, and trailing '?'s in a block that is not the last
6621 one are moved to the next one. The last character in each block
6622 is replaced with NUL. */
6625 /* Number of characters except '*'s and trailing '?'s in the
6626 normalized pattern string. */
6629 /* Number of trailing '?'s in the normalized pattern string. */
6630 int trailing_anychars
;
6632 /* Number of blocks and information for each block. The latter is
6633 NULL if the pattern is exact (no '*' or '?' in it). */
6635 struct xlfdpat_block
*blocks
;
6639 xlfdpat_destroy (pat
)
6640 struct xlfdpat
*pat
;
6647 xfree (pat
->blocks
);
6654 static struct xlfdpat
*
6655 xlfdpat_create (pattern
)
6658 struct xlfdpat
*pat
;
6659 int nblocks
, i
, skip
;
6660 unsigned char last_char
, *p
, *q
, *anychar_head
;
6661 struct xlfdpat_block
*blk
;
6663 pat
= xmalloc (sizeof (struct xlfdpat
));
6664 pat
->buf
= xmalloc (strlen (pattern
) + 1);
6666 /* Normalize the pattern string and store it to `pat->buf'. */
6668 anychar_head
= NULL
;
6671 for (p
= pattern
; *p
; p
++)
6673 unsigned char c
= *p
;
6676 if (last_char
== '*')
6677 /* ...a** -> ...a* */
6681 if (last_char
== '?')
6683 if (anychar_head
> pat
->buf
&& *(anychar_head
- 1) == '*')
6684 /* ...*??* -> ...*?? */
6687 /* ...a??* -> ...a*?? */
6689 *anychar_head
++ = '*';
6697 if (last_char
!= '?')
6701 /* On Mac OS X 10.3, tolower also converts non-ASCII
6702 characters for some locales. */
6706 *q
++ = last_char
= c
;
6710 pat
->nblocks
= nblocks
;
6711 if (last_char
!= '?')
6712 pat
->trailing_anychars
= 0;
6715 pat
->trailing_anychars
= q
- anychar_head
;
6718 pat
->nchars
= q
- pat
->buf
- (nblocks
- 1);
6720 if (anychar_head
== NULL
&& nblocks
== 1)
6722 /* The pattern is exact. */
6727 pat
->blocks
= xmalloc (sizeof (struct xlfdpat_block
) * nblocks
);
6729 /* Divide the normalized pattern into blocks. */
6731 for (blk
= pat
->blocks
; blk
< pat
->blocks
+ nblocks
- 1; blk
++)
6736 blk
->len
= p
- blk
->pattern
;
6740 blk
->len
= q
- blk
->pattern
;
6742 /* Setup a table for the Boyer-Moore string search. */
6743 for (blk
= pat
->blocks
; blk
< pat
->blocks
+ nblocks
; blk
++)
6746 blk
->last_char
= blk
->pattern
[blk
->len
- 1];
6747 blk
->pattern
[blk
->len
- 1] = '\0';
6749 for (skip
= 1; skip
< blk
->len
; skip
++)
6750 if (blk
->pattern
[blk
->len
- skip
- 1] == '?')
6753 for (i
= 0; i
< 256; i
++)
6754 blk
->skip
[i
] = skip
;
6756 p
= blk
->pattern
+ (blk
->len
- skip
);
6758 blk
->skip
[*p
++] = skip
;
6760 blk
->last_char_skip
= blk
->skip
[blk
->last_char
];
6767 xlfdpat_exact_p (pat
)
6768 struct xlfdpat
*pat
;
6770 return pat
->blocks
== NULL
;
6773 /* Return the first string in STRING + 0, ..., STRING + START_MAX such
6774 that the pattern in *BLK matches with its prefix. Return NULL
6775 there is no such strings. STRING must be lowered in advance. */
6778 xlfdpat_block_match_1 (blk
, string
, start_max
)
6779 struct xlfdpat_block
*blk
;
6780 unsigned char *string
;
6783 int start
, infinity
;
6784 unsigned char *p
, *s
;
6786 xassert (blk
->len
> 0);
6787 xassert (start_max
+ blk
->len
<= strlen (string
));
6788 xassert (blk
->last_char
!= '?');
6790 /* See the comments in the function `boyer_moore' (search.c) for the
6791 use of `infinity'. */
6792 infinity
= start_max
+ blk
->len
+ 1;
6793 blk
->skip
[blk
->last_char
] = infinity
;
6798 /* Check the last character of the pattern. */
6799 s
= string
+ blk
->len
- 1;
6802 start
+= blk
->skip
[*(s
+ start
)];
6804 while (start
<= start_max
);
6806 if (start
< infinity
)
6807 /* Couldn't find the last character. */
6810 /* No less than `infinity' means we could find the last
6811 character at `s[start - infinity]'. */
6814 /* Check the remaining characters. We prefer making no-'?'
6815 cases faster because the use of '?' is really rare. */
6820 while (*p
++ == *s
++)
6823 while (*(p
- 1) == '?');
6825 if (*(p
- 1) == '\0')
6827 return string
+ start
;
6830 start
+= blk
->last_char_skip
;
6832 while (start
<= start_max
);
6837 #define xlfdpat_block_match(b, s, m) \
6838 ((b)->len == 1 ? memchr ((s), (b)->last_char, (m) + 1) \
6839 : xlfdpat_block_match_1 (b, s, m))
6841 /* Check if XLFD pattern PAT, which is generated by `xfldpat_create',
6842 matches with STRING. STRING must be lowered in advance. */
6845 xlfdpat_match (pat
, string
)
6846 struct xlfdpat
*pat
;
6847 unsigned char *string
;
6849 int str_len
, nblocks
, i
, start_max
;
6850 struct xlfdpat_block
*blk
;
6853 xassert (pat
->nblocks
> 0);
6855 if (xlfdpat_exact_p (pat
))
6856 return strcmp (pat
->buf
, string
) == 0;
6858 /* The number of the characters in the string must not be smaller
6859 than that in the pattern. */
6860 str_len
= strlen (string
);
6861 if (str_len
< pat
->nchars
+ pat
->trailing_anychars
)
6864 /* Chop off the trailing '?'s. */
6865 str_len
-= pat
->trailing_anychars
;
6867 /* The last block. When it is non-empty, it must match at the end
6869 nblocks
= pat
->nblocks
;
6870 blk
= pat
->blocks
+ (nblocks
- 1);
6872 /* The last block is also the first one. */
6873 return (str_len
== blk
->len
6874 && (blk
->len
== 0 || xlfdpat_block_match (blk
, string
, 0)));
6875 else if (blk
->len
!= 0)
6876 if (!xlfdpat_block_match (blk
, string
+ (str_len
- blk
->len
), 0))
6879 /* The first block. When it is non-empty, it must match at the
6880 beginning of the string. */
6884 s
= xlfdpat_block_match (blk
, string
, 0);
6887 string
= s
+ blk
->len
;
6890 /* The rest of the blocks. */
6891 start_max
= str_len
- pat
->nchars
;
6892 for (i
= 1, blk
++; i
< nblocks
- 1; i
++, blk
++)
6894 s
= xlfdpat_block_match (blk
, string
, start_max
);
6897 start_max
-= s
- string
;
6898 string
= s
+ blk
->len
;
6905 /***********************************************************************
6907 ***********************************************************************/
6909 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6912 x_get_font_info (f
, font_idx
)
6916 return (FRAME_MAC_FONT_TABLE (f
) + font_idx
);
6919 /* the global font name table */
6920 static char **font_name_table
= NULL
;
6921 static int font_name_table_size
= 0;
6922 static int font_name_count
= 0;
6924 /* Alist linking font family names to Font Manager font family
6925 references (which can also be used as QuickDraw font IDs). We use
6926 an alist because hash tables are not ready when the terminal frame
6927 for Mac OS Classic is created. */
6928 static Lisp_Object fm_font_family_alist
;
6930 /* Hash table linking font family names to ATSU font IDs. */
6931 static Lisp_Object atsu_font_id_hash
;
6932 /* Alist linking Font Manager style to face attributes. */
6933 static Lisp_Object fm_style_face_attributes_alist
;
6934 static Lisp_Object Vmac_atsu_font_table
;
6935 extern Lisp_Object QCfamily
, QCweight
, QCslant
, Qnormal
, Qbold
, Qitalic
;
6938 /* Alist linking character set strings to Mac text encoding and Emacs
6940 static Lisp_Object Vmac_charset_info_alist
;
6943 create_text_encoding_info_alist ()
6945 Lisp_Object result
= Qnil
, rest
;
6947 for (rest
= Vmac_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
6949 Lisp_Object charset_info
= XCAR (rest
);
6950 Lisp_Object charset
, coding_system
, text_encoding
;
6951 Lisp_Object existing_info
;
6953 if (!(CONSP (charset_info
)
6954 && STRINGP (charset
= XCAR (charset_info
))
6955 && CONSP (XCDR (charset_info
))
6956 && INTEGERP (text_encoding
= XCAR (XCDR (charset_info
)))
6957 && CONSP (XCDR (XCDR (charset_info
)))
6958 && SYMBOLP (coding_system
= XCAR (XCDR (XCDR (charset_info
))))))
6961 existing_info
= assq_no_quit (text_encoding
, result
);
6962 if (NILP (existing_info
))
6963 result
= Fcons (list3 (text_encoding
, coding_system
, charset
),
6966 if (NILP (Fmember (charset
, XCDR (XCDR (existing_info
)))))
6967 XSETCDR (XCDR (existing_info
),
6968 Fcons (charset
, XCDR (XCDR (existing_info
))));
6976 decode_mac_font_name (name
, size
, coding_system
)
6979 Lisp_Object coding_system
;
6981 struct coding_system coding
;
6984 if (!NILP (coding_system
) && !NILP (Fcoding_system_p (coding_system
)))
6986 for (p
= name
; *p
; p
++)
6987 if (!isascii (*p
) || iscntrl (*p
))
6992 setup_coding_system (coding_system
, &coding
);
6993 coding
.src_multibyte
= 0;
6994 coding
.dst_multibyte
= 1;
6995 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6996 coding
.composing
= COMPOSITION_DISABLED
;
6997 buf
= (char *) alloca (size
);
6999 decode_coding (&coding
, name
, buf
, strlen (name
), size
- 1);
7000 bcopy (buf
, name
, coding
.produced
);
7001 name
[coding
.produced
] = '\0';
7005 /* If there's just one occurrence of '-' in the family name, it is
7006 replaced with '_'. (More than one occurrence of '-' means a
7007 "FOUNDRY-FAMILY-CHARSET"-style name.) */
7008 p
= strchr (name
, '-');
7009 if (p
&& strchr (p
+ 1, '-') == NULL
)
7012 for (p
= name
; *p
; p
++)
7013 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
7014 for some locales. */
7021 mac_to_x_fontname (name
, size
, style
, charset
)
7029 char xf
[256], *result
;
7032 if (sscanf (name
, "%31[^-]-%255[^-]-%31s", foundry
, family
, cs
) == 3)
7036 strcpy(foundry
, "Apple");
7037 strcpy(family
, name
);
7040 sprintf (xf
, "%s-%c-normal--%d-%d-%d-%d-m-%d-%s",
7041 style
& bold
? "bold" : "medium", style
& italic
? 'i' : 'r',
7042 size
, size
* 10, size
? 72 : 0, size
? 72 : 0, size
* 10, charset
);
7044 result
= xmalloc (strlen (foundry
) + strlen (family
) + strlen (xf
) + 3 + 1);
7045 sprintf (result
, "-%s-%s-%s", foundry
, family
, xf
);
7046 for (p
= result
; *p
; p
++)
7047 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
7048 for some locales. */
7055 /* Parse fully-specified and instantiated X11 font spec XF, and store
7056 the results to FAMILY, *SIZE, *STYLE, and CHARSET. Return 1 if the
7057 parsing succeeded, and 0 otherwise. For FAMILY and CHARSET, the
7058 caller must allocate at least 256 and 32 bytes respectively. For
7059 ordinary Mac fonts, the value stored to FAMILY should just be their
7060 names, like "monaco", "Taipei", etc. Fonts converted from the GNU
7061 intlfonts collection contain their charset designation in their
7062 names, like "ETL-Fixed-iso8859-1", "ETL-Fixed-koi8-r", etc. Both
7063 types of font names are handled accordingly. */
7065 const int kDefaultFontSize
= 12;
7068 parse_x_font_name (xf
, family
, size
, style
, charset
)
7074 Str31 foundry
, weight
;
7075 int point_size
, avgwidth
;
7078 if (sscanf (xf
, "-%31[^-]-%255[^-]-%31[^-]-%1[^-]-%*[^-]-%*[^-]-%d-%d-%*[^-]-%*[^-]-%*c-%d-%31s",
7079 foundry
, family
, weight
, slant
, size
,
7080 &point_size
, &avgwidth
, charset
) != 8
7081 && sscanf (xf
, "-%31[^-]-%255[^-]-%31[^-]-%1[^-]-%*[^-]--%d-%d-%*[^-]-%*[^-]-%*c-%d-%31s",
7082 foundry
, family
, weight
, slant
, size
,
7083 &point_size
, &avgwidth
, charset
) != 8)
7089 *size
= point_size
/ 10;
7090 else if (avgwidth
> 0)
7091 *size
= avgwidth
/ 10;
7094 *size
= kDefaultFontSize
;
7097 if (strcmp (weight
, "bold") == 0)
7102 if (NILP (Fassoc (build_string (charset
), Vmac_charset_info_alist
)))
7104 int foundry_len
= strlen (foundry
), family_len
= strlen (family
);
7106 if (foundry_len
+ family_len
+ strlen (charset
) + 2 < sizeof (Str255
))
7108 /* Like sprintf (family, "%s-%s-%s", foundry, family, charset),
7109 but take overlap into account. */
7110 memmove (family
+ foundry_len
+ 1, family
, family_len
);
7111 memcpy (family
, foundry
, foundry_len
);
7112 family
[foundry_len
] = '-';
7113 family
[foundry_len
+ 1 + family_len
] = '-';
7114 strcpy (family
+ foundry_len
+ 1 + family_len
+ 1, charset
);
7120 for (p
= family
; *p
; p
++)
7121 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
7122 for some locales. */
7131 add_font_name_table_entry (char *font_name
)
7133 if (font_name_table_size
== 0)
7135 font_name_table_size
= 256;
7136 font_name_table
= (char **)
7137 xmalloc (font_name_table_size
* sizeof (char *));
7139 else if (font_name_count
+ 1 >= font_name_table_size
)
7141 font_name_table_size
*= 2;
7142 font_name_table
= (char **)
7143 xrealloc (font_name_table
,
7144 font_name_table_size
* sizeof (char *));
7147 font_name_table
[font_name_count
++] = font_name
;
7151 add_mac_font_name (name
, size
, style
, charset
)
7158 add_font_name_table_entry (mac_to_x_fontname (name
, size
, style
, charset
));
7161 add_font_name_table_entry (mac_to_x_fontname (name
, 0, style
, charset
));
7162 add_font_name_table_entry (mac_to_x_fontname (name
, 0, italic
, charset
));
7163 add_font_name_table_entry (mac_to_x_fontname (name
, 0, bold
, charset
));
7164 add_font_name_table_entry (mac_to_x_fontname (name
, 0, italic
| bold
,
7171 fm_style_to_face_attributes (fm_style
)
7172 FMFontStyle fm_style
;
7176 fm_style
&= (bold
| italic
);
7177 tem
= assq_no_quit (make_number (fm_style
),
7178 fm_style_face_attributes_alist
);
7182 tem
= list4 (QCweight
, fm_style
& bold
? Qbold
: Qnormal
,
7183 QCslant
, fm_style
& italic
? Qitalic
: Qnormal
);
7184 fm_style_face_attributes_alist
=
7185 Fcons (Fcons (make_number (fm_style
), tem
),
7186 fm_style_face_attributes_alist
);
7192 /* Sets up the table font_name_table to contain the list of all fonts
7193 in the system the first time the table is used so that the Resource
7194 Manager need not be accessed every time this information is
7198 init_font_name_table ()
7200 #if TARGET_API_MAC_CARBON
7201 FMFontFamilyIterator ffi
;
7202 FMFontFamilyInstanceIterator ffii
;
7204 Lisp_Object text_encoding_info_alist
;
7205 struct gcpro gcpro1
;
7207 text_encoding_info_alist
= create_text_encoding_info_alist ();
7210 #if USE_CG_TEXT_DRAWING
7211 init_cg_text_anti_aliasing_threshold ();
7213 if (!NILP (assq_no_quit (make_number (kTextEncodingMacUnicode
),
7214 text_encoding_info_alist
)))
7217 struct Lisp_Hash_Table
*h
;
7219 ItemCount nfonts
, i
;
7220 ATSUFontID
*font_ids
= NULL
;
7226 make_hash_table (Qequal
, make_number (DEFAULT_HASH_SIZE
),
7227 make_float (DEFAULT_REHASH_SIZE
),
7228 make_float (DEFAULT_REHASH_THRESHOLD
),
7230 h
= XHASH_TABLE (atsu_font_id_hash
);
7232 err
= ATSUFontCount (&nfonts
);
7235 font_ids
= xmalloc (sizeof (ATSUFontID
) * nfonts
);
7236 err
= ATSUGetFontIDs (font_ids
, nfonts
, NULL
);
7239 for (i
= 0; i
< nfonts
; i
++)
7241 err
= ATSUFindFontName (font_ids
[i
], kFontFamilyName
,
7242 kFontMacintoshPlatform
, kFontNoScript
,
7243 kFontNoLanguage
, 0, NULL
, &name_len
, NULL
);
7246 name
= xmalloc (name_len
+ 1);
7247 name
[name_len
] = '\0';
7248 err
= ATSUFindFontName (font_ids
[i
], kFontFamilyName
,
7249 kFontMacintoshPlatform
, kFontNoScript
,
7250 kFontNoLanguage
, name_len
, name
,
7255 FMFontStyle style
= normal
;
7257 decode_mac_font_name (name
, name_len
+ 1, Qnil
);
7258 family
= make_unibyte_string (name
, name_len
);
7259 FMGetFontFamilyInstanceFromFont (font_ids
[i
], &ff
, &style
);
7260 Fputhash ((font_ids
[i
] > MOST_POSITIVE_FIXNUM
7261 ? make_float (font_ids
[i
])
7262 : make_number (font_ids
[i
])),
7265 fm_style_to_face_attributes (style
))),
7266 Vmac_atsu_font_table
);
7268 && hash_lookup (h
, family
, &hash_code
) < 0)
7270 add_mac_font_name (name
, 0, normal
, "iso10646-1");
7271 hash_put (h
, family
, long_to_cons (font_ids
[i
]),
7282 /* Create a dummy instance iterator here to avoid creating and
7283 destroying it in the loop. */
7284 if (FMCreateFontFamilyInstanceIterator (0, &ffii
) != noErr
)
7286 /* Create an iterator to enumerate the font families. */
7287 if (FMCreateFontFamilyIterator (NULL
, NULL
, kFMDefaultOptions
, &ffi
)
7290 FMDisposeFontFamilyInstanceIterator (&ffii
);
7294 GCPRO1 (text_encoding_info_alist
);
7296 while (FMGetNextFontFamily (&ffi
, &ff
) == noErr
)
7302 TextEncoding encoding
;
7303 TextEncodingBase sc
;
7304 Lisp_Object text_encoding_info
, family
;
7306 if (FMGetFontFamilyName (ff
, name
) != noErr
)
7312 if (FMGetFontFamilyTextEncoding (ff
, &encoding
) != noErr
)
7314 sc
= GetTextEncodingBase (encoding
);
7315 text_encoding_info
= assq_no_quit (make_number (sc
),
7316 text_encoding_info_alist
);
7317 if (NILP (text_encoding_info
))
7318 text_encoding_info
= assq_no_quit (make_number (kTextEncodingMacRoman
),
7319 text_encoding_info_alist
);
7320 decode_mac_font_name (name
, sizeof (name
),
7321 XCAR (XCDR (text_encoding_info
)));
7322 family
= build_string (name
);
7323 if (!NILP (Fassoc (family
, fm_font_family_alist
)))
7325 fm_font_family_alist
= Fcons (Fcons (family
, make_number (ff
)),
7326 fm_font_family_alist
);
7328 /* Point the instance iterator at the current font family. */
7329 if (FMResetFontFamilyInstanceIterator (ff
, &ffii
) != noErr
)
7332 while (FMGetNextFontFamilyInstance (&ffii
, &font
, &style
, &size
)
7335 Lisp_Object rest
= XCDR (XCDR (text_encoding_info
));
7337 if (size
> 0 || style
== normal
)
7338 for (; !NILP (rest
); rest
= XCDR (rest
))
7339 add_mac_font_name (name
, size
, style
, SDATA (XCAR (rest
)));
7345 /* Dispose of the iterators. */
7346 FMDisposeFontFamilyIterator (&ffi
);
7347 FMDisposeFontFamilyInstanceIterator (&ffii
);
7348 #else /* !TARGET_API_MAC_CARBON */
7350 SInt16 fontnum
, old_fontnum
;
7351 int num_mac_fonts
= CountResources('FOND');
7353 Handle font_handle
, font_handle_2
;
7354 short id
, scriptcode
;
7357 struct FontAssoc
*fat
;
7358 struct AsscEntry
*assc_entry
;
7359 Lisp_Object text_encoding_info_alist
, text_encoding_info
, family
;
7360 struct gcpro gcpro1
;
7362 GetPort (&port
); /* save the current font number used */
7363 old_fontnum
= port
->txFont
;
7365 text_encoding_info_alist
= create_text_encoding_info_alist ();
7367 GCPRO1 (text_encoding_info_alist
);
7369 for (i
= 1; i
<= num_mac_fonts
; i
++) /* get all available fonts */
7371 font_handle
= GetIndResource ('FOND', i
);
7375 GetResInfo (font_handle
, &id
, &type
, name
);
7376 GetFNum (name
, &fontnum
);
7378 if (fontnum
== 0 || *name
== '.')
7382 scriptcode
= FontToScript (fontnum
);
7383 text_encoding_info
= assq_no_quit (make_number (scriptcode
),
7384 text_encoding_info_alist
);
7385 if (NILP (text_encoding_info
))
7386 text_encoding_info
= assq_no_quit (make_number (smRoman
),
7387 text_encoding_info_alist
);
7388 decode_mac_font_name (name
, sizeof (name
),
7389 XCAR (XCDR (text_encoding_info
)));
7390 family
= build_string (name
);
7391 if (!NILP (Fassoc (family
, fm_font_family_alist
)))
7393 fm_font_family_alist
= Fcons (Fcons (family
, make_number (fontnum
)),
7394 fm_font_family_alist
);
7397 HLock (font_handle
);
7399 if (GetResourceSizeOnDisk (font_handle
)
7400 >= sizeof (struct FamRec
))
7402 fat
= (struct FontAssoc
*) (*font_handle
7403 + sizeof (struct FamRec
));
7405 = (struct AsscEntry
*) (*font_handle
7406 + sizeof (struct FamRec
)
7407 + sizeof (struct FontAssoc
));
7409 for (j
= 0; j
<= fat
->numAssoc
; j
++, assc_entry
++)
7411 Lisp_Object rest
= XCDR (XCDR (text_encoding_info
));
7413 for (; !NILP (rest
); rest
= XCDR (rest
))
7414 add_mac_font_name (name
, assc_entry
->fontSize
,
7415 assc_entry
->fontStyle
,
7416 SDATA (XCAR (rest
)));
7420 HUnlock (font_handle
);
7421 font_handle_2
= GetNextFOND (font_handle
);
7422 ReleaseResource (font_handle
);
7423 font_handle
= font_handle_2
;
7425 while (ResError () == noErr
&& font_handle
);
7430 TextFont (old_fontnum
);
7431 #endif /* !TARGET_API_MAC_CARBON */
7436 mac_clear_font_name_table ()
7440 for (i
= 0; i
< font_name_count
; i
++)
7441 xfree (font_name_table
[i
]);
7442 xfree (font_name_table
);
7443 font_name_table
= NULL
;
7444 font_name_table_size
= font_name_count
= 0;
7445 fm_font_family_alist
= Qnil
;
7449 enum xlfd_scalable_field_index
7451 XLFD_SCL_PIXEL_SIZE
,
7452 XLFD_SCL_POINT_SIZE
,
7457 static int xlfd_scalable_fields
[] =
7466 mac_do_list_fonts (pattern
, maxnames
)
7471 Lisp_Object font_list
= Qnil
;
7472 struct xlfdpat
*pat
;
7474 int scl_val
[XLFD_SCL_LAST
], *field
, *val
;
7477 if (font_name_table
== NULL
) /* Initialize when first used. */
7478 init_font_name_table ();
7480 for (i
= 0; i
< XLFD_SCL_LAST
; i
++)
7483 /* If the pattern contains 14 dashes and one of PIXEL_SIZE,
7484 POINT_SIZE, and AVGWIDTH fields is explicitly specified, scalable
7485 fonts are scaled according to the specified size. */
7488 field
= xlfd_scalable_fields
;
7496 if ('0' <= *ptr
&& *ptr
<= '9')
7498 *val
= *ptr
++ - '0';
7499 while ('0' <= *ptr
&& *ptr
<= '9' && *val
< 10000)
7500 *val
= *val
* 10 + *ptr
++ - '0';
7507 ptr
= strchr (ptr
, '-');
7510 while (ptr
&& i
< 14);
7512 if (i
== 14 && ptr
== NULL
)
7514 if (scl_val
[XLFD_SCL_PIXEL_SIZE
] < 0)
7515 scl_val
[XLFD_SCL_PIXEL_SIZE
] =
7516 (scl_val
[XLFD_SCL_POINT_SIZE
] > 0 ? scl_val
[XLFD_SCL_POINT_SIZE
] / 10
7517 : (scl_val
[XLFD_SCL_AVGWIDTH
] > 0 ? scl_val
[XLFD_SCL_AVGWIDTH
] / 10
7519 if (scl_val
[XLFD_SCL_POINT_SIZE
] < 0)
7520 scl_val
[XLFD_SCL_POINT_SIZE
] =
7521 (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0 ? scl_val
[XLFD_SCL_PIXEL_SIZE
] * 10
7522 : (scl_val
[XLFD_SCL_AVGWIDTH
] > 0 ? scl_val
[XLFD_SCL_AVGWIDTH
]
7524 if (scl_val
[XLFD_SCL_AVGWIDTH
] < 0)
7525 scl_val
[XLFD_SCL_AVGWIDTH
] =
7526 (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0 ? scl_val
[XLFD_SCL_PIXEL_SIZE
] * 10
7527 : (scl_val
[XLFD_SCL_POINT_SIZE
] > 0 ? scl_val
[XLFD_SCL_POINT_SIZE
]
7531 scl_val
[XLFD_SCL_PIXEL_SIZE
] = -1;
7533 pat
= xlfdpat_create (pattern
);
7537 exact
= xlfdpat_exact_p (pat
);
7539 for (i
= 0; i
< font_name_count
; i
++)
7541 if (xlfdpat_match (pat
, font_name_table
[i
]))
7543 font_list
= Fcons (build_string (font_name_table
[i
]), font_list
);
7544 if (exact
|| (maxnames
> 0 && ++n_fonts
>= maxnames
))
7547 else if (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0
7548 && (ptr
= strstr (font_name_table
[i
], "-0-0-0-0-m-0-")))
7550 int former_len
= ptr
- font_name_table
[i
];
7552 scaled
= xmalloc (strlen (font_name_table
[i
]) + 20 + 1);
7553 memcpy (scaled
, font_name_table
[i
], former_len
);
7554 sprintf (scaled
+ former_len
,
7555 "-%d-%d-72-72-m-%d-%s",
7556 scl_val
[XLFD_SCL_PIXEL_SIZE
],
7557 scl_val
[XLFD_SCL_POINT_SIZE
],
7558 scl_val
[XLFD_SCL_AVGWIDTH
],
7559 ptr
+ sizeof ("-0-0-0-0-m-0-") - 1);
7561 if (xlfdpat_match (pat
, scaled
))
7563 font_list
= Fcons (build_string (scaled
), font_list
);
7565 if (exact
|| (maxnames
> 0 && ++n_fonts
>= maxnames
))
7573 xlfdpat_destroy (pat
);
7578 /* Return a list of names of available fonts matching PATTERN on frame F.
7580 Frame F null means we have not yet created any frame on Mac, and
7581 consult the first display in x_display_list. MAXNAMES sets a limit
7582 on how many fonts to match. */
7585 x_list_fonts (f
, pattern
, size
, maxnames
)
7587 Lisp_Object pattern
;
7590 Lisp_Object list
= Qnil
, patterns
, tem
, key
;
7591 struct mac_display_info
*dpyinfo
7592 = f
? FRAME_MAC_DISPLAY_INFO (f
) : x_display_list
;
7594 xassert (size
<= 0);
7596 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
7597 if (NILP (patterns
))
7598 patterns
= Fcons (pattern
, Qnil
);
7600 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
7602 pattern
= XCAR (patterns
);
7604 if (!STRINGP (pattern
))
7607 tem
= XCAR (XCDR (dpyinfo
->name_list_element
));
7608 key
= Fcons (pattern
, make_number (maxnames
));
7610 list
= Fassoc (key
, tem
);
7613 list
= Fcdr_safe (list
);
7614 /* We have a cashed list. Don't have to get the list again. */
7619 list
= mac_do_list_fonts (SDATA (pattern
), maxnames
);
7622 /* MAC_TODO: add code for matching outline fonts here */
7624 /* Now store the result in the cache. */
7625 XSETCAR (XCDR (dpyinfo
->name_list_element
),
7626 Fcons (Fcons (key
, list
),
7627 XCAR (XCDR (dpyinfo
->name_list_element
))));
7630 if (NILP (list
)) continue; /* Try the remaining alternatives. */
7639 /* Check that FONT is valid on frame F. It is if it can be found in F's
7643 x_check_font (f
, font
)
7648 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7650 xassert (font
!= NULL
);
7652 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7653 if (dpyinfo
->font_table
[i
].name
7654 && font
== dpyinfo
->font_table
[i
].font
)
7657 xassert (i
< dpyinfo
->n_fonts
);
7660 #endif /* GLYPH_DEBUG != 0 */
7662 /* Set *W to the minimum width, *H to the minimum font height of FONT.
7663 Note: There are (broken) X fonts out there with invalid XFontStruct
7664 min_bounds contents. For example, handa@etl.go.jp reports that
7665 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
7666 have font->min_bounds.width == 0. */
7669 x_font_min_bounds (font
, w
, h
)
7670 MacFontStruct
*font
;
7673 *h
= FONT_HEIGHT (font
);
7674 *w
= font
->min_bounds
.width
;
7678 /* Compute the smallest character width and smallest font height over
7679 all fonts available on frame F. Set the members smallest_char_width
7680 and smallest_font_height in F's x_display_info structure to
7681 the values computed. Value is non-zero if smallest_font_height or
7682 smallest_char_width become smaller than they were before. */
7685 x_compute_min_glyph_bounds (f
)
7689 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7690 MacFontStruct
*font
;
7691 int old_width
= dpyinfo
->smallest_char_width
;
7692 int old_height
= dpyinfo
->smallest_font_height
;
7694 dpyinfo
->smallest_font_height
= 100000;
7695 dpyinfo
->smallest_char_width
= 100000;
7697 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
7698 if (dpyinfo
->font_table
[i
].name
)
7700 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
7703 font
= (MacFontStruct
*) fontp
->font
;
7704 xassert (font
!= (MacFontStruct
*) ~0);
7705 x_font_min_bounds (font
, &w
, &h
);
7707 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
7708 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
7711 xassert (dpyinfo
->smallest_char_width
> 0
7712 && dpyinfo
->smallest_font_height
> 0);
7714 return (dpyinfo
->n_fonts
== 1
7715 || dpyinfo
->smallest_char_width
< old_width
7716 || dpyinfo
->smallest_font_height
< old_height
);
7720 /* Determine whether given string is a fully-specified XLFD: all 14
7721 fields are present, none is '*'. */
7724 is_fully_specified_xlfd (char *p
)
7732 for (i
= 0; i
< 13; i
++)
7734 q
= strchr (p
+ 1, '-');
7737 if (q
- p
== 2 && *(p
+ 1) == '*')
7742 if (strchr (p
+ 1, '-') != NULL
)
7745 if (*(p
+ 1) == '*' && *(p
+ 2) == '\0')
7752 /* XLoadQueryFont creates and returns an internal representation for a
7753 font in a MacFontStruct struct. There is really no concept
7754 corresponding to "loading" a font on the Mac. But we check its
7755 existence and find the font number and all other information for it
7756 and store them in the returned MacFontStruct. */
7758 static MacFontStruct
*
7759 XLoadQueryFont (Display
*dpy
, char *fontname
)
7767 static ATSUFontID font_id
;
7768 ATSUStyle mac_style
= NULL
;
7771 #if TARGET_API_MAC_CARBON
7772 TextEncoding encoding
;
7777 MacFontStruct
*font
;
7778 XCharStruct
*space_bounds
= NULL
, *pcm
;
7780 if (is_fully_specified_xlfd (fontname
))
7784 Lisp_Object matched_fonts
;
7786 matched_fonts
= mac_do_list_fonts (fontname
, 1);
7787 if (NILP (matched_fonts
))
7789 name
= SDATA (XCAR (matched_fonts
));
7792 if (parse_x_font_name (name
, family
, &size
, &fontface
, charset
) == 0)
7796 if (strcmp (charset
, "iso10646-1") == 0) /* XXX */
7799 ATSUAttributeTag tags
[] = {kATSUFontTag
, kATSUSizeTag
,
7800 kATSUQDBoldfaceTag
, kATSUQDItalicTag
};
7801 ByteCount sizes
[] = {sizeof (ATSUFontID
), sizeof (Fixed
),
7802 sizeof (Boolean
), sizeof (Boolean
)};
7803 static Fixed size_fixed
;
7804 static Boolean bold_p
, italic_p
;
7805 ATSUAttributeValuePtr values
[] = {&font_id
, &size_fixed
,
7806 &bold_p
, &italic_p
};
7807 ATSUFontFeatureType types
[] = {kAllTypographicFeaturesType
,
7809 ATSUFontFeatureSelector selectors
[] = {kAllTypeFeaturesOffSelector
,
7810 kDecomposeDiacriticsSelector
};
7811 Lisp_Object font_id_cons
;
7814 font_id_cons
= Fgethash (make_unibyte_string (family
, strlen (family
)),
7815 atsu_font_id_hash
, Qnil
);
7816 if (NILP (font_id_cons
))
7818 font_id
= cons_to_long (font_id_cons
);
7819 size_fixed
= Long2Fix (size
);
7820 bold_p
= (fontface
& bold
) != 0;
7821 italic_p
= (fontface
& italic
) != 0;
7822 err
= ATSUCreateStyle (&mac_style
);
7825 err
= ATSUSetFontFeatures (mac_style
, sizeof (types
) / sizeof (types
[0]),
7829 err
= ATSUSetAttributes (mac_style
, sizeof (tags
) / sizeof (tags
[0]),
7830 tags
, sizes
, values
);
7833 err
= FMGetFontFamilyInstanceFromFont (font_id
, &fontnum
, &style
);
7836 scriptcode
= kTextEncodingMacUnicode
;
7841 Lisp_Object tmp
= Fassoc (build_string (family
), fm_font_family_alist
);
7845 fontnum
= XINT (XCDR (tmp
));
7846 #if TARGET_API_MAC_CARBON
7847 if (FMGetFontFamilyTextEncoding (fontnum
, &encoding
) != noErr
)
7849 scriptcode
= GetTextEncodingBase (encoding
);
7851 scriptcode
= FontToScript (fontnum
);
7855 font
= (MacFontStruct
*) xmalloc (sizeof (struct MacFontStruct
));
7857 font
->mac_fontnum
= fontnum
;
7858 font
->mac_fontsize
= size
;
7859 font
->mac_fontface
= fontface
;
7860 font
->mac_scriptcode
= scriptcode
;
7862 font
->mac_style
= mac_style
;
7863 #if USE_CG_TEXT_DRAWING
7864 font
->cg_font
= NULL
;
7865 font
->cg_glyphs
= NULL
;
7869 /* Apple Japanese (SJIS) font is listed as both
7870 "*-jisx0208.1983-sjis" (Japanese script) and "*-jisx0201.1976-0"
7871 (Roman script) in init_font_name_table (). The latter should be
7872 treated as a one-byte font. */
7873 if (scriptcode
== smJapanese
&& strcmp (charset
, "jisx0201.1976-0") == 0)
7874 font
->mac_scriptcode
= smRoman
;
7876 font
->full_name
= mac_to_x_fontname (family
, size
, fontface
, charset
);
7879 if (font
->mac_style
)
7884 font
->min_byte1
= 0;
7885 font
->max_byte1
= 0xff;
7886 font
->min_char_or_byte2
= 0;
7887 font
->max_char_or_byte2
= 0xff;
7889 font
->bounds
.rows
= xmalloc (sizeof (XCharStruct
*) * 0x100);
7890 bzero (font
->bounds
.rows
, sizeof (XCharStruct
*) * 0x100);
7891 font
->bounds
.rows
[0] = xmalloc (sizeof (XCharStruct
) * 0x100);
7892 pcm_init (font
->bounds
.rows
[0], 0x100);
7894 #if USE_CG_TEXT_DRAWING
7898 ATSFontRef ats_font
;
7900 err
= FMGetFontFromFontFamilyInstance (fontnum
, fontface
,
7902 /* Use CG text drawing if italic/bold is not synthesized. */
7903 if (err
== noErr
&& style
== fontface
)
7905 ats_font
= FMGetATSFontRefFromFont (font_id
);
7906 font
->cg_font
= CGFontCreateWithPlatformFont (&ats_font
);
7912 font
->cg_glyphs
= xmalloc (sizeof (CGGlyph
) * 0x100);
7913 bzero (font
->cg_glyphs
, sizeof (CGGlyph
) * 0x100);
7916 space_bounds
= font
->bounds
.rows
[0] + 0x20;
7917 err
= mac_query_char_extents (font
->mac_style
, 0x20,
7918 &font
->ascent
, &font
->descent
,
7920 #if USE_CG_TEXT_DRAWING
7921 (font
->cg_glyphs
? font
->cg_glyphs
+ 0x20
7929 mac_unload_font (&one_mac_display_info
, font
);
7933 pcm
= font
->bounds
.rows
[0];
7934 for (c
= 0x21; c
<= 0xff; c
++)
7937 /* Soft hyphen is not supported in ATSUI. */
7945 mac_query_char_extents (font
->mac_style
, c
, NULL
, NULL
, pcm
+ c
,
7946 #if USE_CG_TEXT_DRAWING
7947 (font
->cg_glyphs
? font
->cg_glyphs
+ c
7954 #if USE_CG_TEXT_DRAWING
7955 if (font
->cg_glyphs
&& font
->cg_glyphs
[c
] == 0)
7957 /* Don't use CG text drawing if font substitution occurs in
7958 ASCII or Latin-1 characters. */
7959 CGFontRelease (font
->cg_font
);
7960 font
->cg_font
= NULL
;
7961 xfree (font
->cg_glyphs
);
7962 font
->cg_glyphs
= NULL
;
7971 SInt16 old_fontnum
, old_fontsize
;
7973 FontInfo the_fontinfo
;
7974 int is_two_byte_font
;
7976 /* Save the current font number used. */
7978 #if TARGET_API_MAC_CARBON
7979 old_fontnum
= GetPortTextFont (port
);
7980 old_fontsize
= GetPortTextSize (port
);
7981 old_fontface
= GetPortTextFace (port
);
7983 old_fontnum
= port
->txFont
;
7984 old_fontsize
= port
->txSize
;
7985 old_fontface
= port
->txFace
;
7990 TextFace (fontface
);
7992 GetFontInfo (&the_fontinfo
);
7994 font
->ascent
= the_fontinfo
.ascent
;
7995 font
->descent
= the_fontinfo
.descent
;
7997 is_two_byte_font
= (font
->mac_scriptcode
== smJapanese
7998 || font
->mac_scriptcode
== smTradChinese
7999 || font
->mac_scriptcode
== smSimpChinese
8000 || font
->mac_scriptcode
== smKorean
);
8002 if (is_two_byte_font
)
8006 font
->min_byte1
= 0xa1;
8007 font
->max_byte1
= 0xfe;
8008 font
->min_char_or_byte2
= 0xa1;
8009 font
->max_char_or_byte2
= 0xfe;
8011 /* Use the width of an "ideographic space" of that font
8012 because the_fontinfo.widMax returns the wrong width for
8014 switch (font
->mac_scriptcode
)
8017 font
->min_byte1
= 0x81;
8018 font
->max_byte1
= 0xfc;
8019 font
->min_char_or_byte2
= 0x40;
8020 font
->max_char_or_byte2
= 0xfc;
8021 char_width
= StringWidth("\p\x81\x40");
8024 font
->min_char_or_byte2
= 0x40;
8025 char_width
= StringWidth("\p\xa1\x40");
8028 char_width
= StringWidth("\p\xa1\xa1");
8031 char_width
= StringWidth("\p\xa1\xa1");
8035 font
->bounds
.per_char
= NULL
;
8037 if (fontface
& italic
)
8038 font
->max_bounds
.rbearing
= char_width
+ 1;
8040 font
->max_bounds
.rbearing
= char_width
;
8041 font
->max_bounds
.lbearing
= 0;
8042 font
->max_bounds
.width
= char_width
;
8043 font
->max_bounds
.ascent
= the_fontinfo
.ascent
;
8044 font
->max_bounds
.descent
= the_fontinfo
.descent
;
8046 font
->min_bounds
= font
->max_bounds
;
8052 font
->min_byte1
= font
->max_byte1
= 0;
8053 font
->min_char_or_byte2
= 0x20;
8054 font
->max_char_or_byte2
= 0xff;
8056 font
->bounds
.per_char
=
8057 xmalloc (sizeof (XCharStruct
) * (0xff - 0x20 + 1));
8058 bzero (font
->bounds
.per_char
,
8059 sizeof (XCharStruct
) * (0xff - 0x20 + 1));
8061 space_bounds
= font
->bounds
.per_char
;
8062 mac_query_char_extents (NULL
, 0x20, &font
->ascent
, &font
->descent
,
8063 space_bounds
, NULL
);
8065 for (c
= 0x21, pcm
= space_bounds
+ 1; c
<= 0xff; c
++, pcm
++)
8066 mac_query_char_extents (NULL
, c
, NULL
, NULL
, pcm
, NULL
);
8069 /* Restore previous font number, size and face. */
8070 TextFont (old_fontnum
);
8071 TextSize (old_fontsize
);
8072 TextFace (old_fontface
);
8079 font
->min_bounds
= font
->max_bounds
= *space_bounds
;
8080 for (c
= 0x21, pcm
= space_bounds
+ 1; c
<= 0x7f; c
++, pcm
++)
8083 font
->min_bounds
.lbearing
= min (font
->min_bounds
.lbearing
,
8085 font
->min_bounds
.rbearing
= min (font
->min_bounds
.rbearing
,
8087 font
->min_bounds
.width
= min (font
->min_bounds
.width
,
8089 font
->min_bounds
.ascent
= min (font
->min_bounds
.ascent
,
8092 font
->max_bounds
.lbearing
= max (font
->max_bounds
.lbearing
,
8094 font
->max_bounds
.rbearing
= max (font
->max_bounds
.rbearing
,
8096 font
->max_bounds
.width
= max (font
->max_bounds
.width
,
8098 font
->max_bounds
.ascent
= max (font
->max_bounds
.ascent
,
8103 font
->mac_style
== NULL
&&
8105 font
->max_bounds
.width
== font
->min_bounds
.width
8106 && font
->min_bounds
.lbearing
>= 0
8107 && font
->max_bounds
.rbearing
<= font
->max_bounds
.width
)
8109 /* Fixed width and no overhangs. */
8110 xfree (font
->bounds
.per_char
);
8111 font
->bounds
.per_char
= NULL
;
8115 #if !defined (MAC_OS8) || USE_ATSUI
8116 /* AppKit and WebKit do some adjustment to the heights of Courier,
8117 Helvetica, and Times. This only works on the environments where
8118 srcCopy text transfer mode is never used. */
8120 #ifdef MAC_OS8 /* implies USE_ATSUI */
8123 (strcmp (family
, "courier") == 0 || strcmp (family
, "helvetica") == 0
8124 || strcmp (family
, "times") == 0))
8125 font
->ascent
+= (font
->ascent
+ font
->descent
) * .15 + 0.5;
8133 mac_unload_font (dpyinfo
, font
)
8134 struct mac_display_info
*dpyinfo
;
8137 xfree (font
->full_name
);
8139 if (font
->mac_style
)
8143 for (i
= font
->min_byte1
; i
<= font
->max_byte1
; i
++)
8144 if (font
->bounds
.rows
[i
])
8145 xfree (font
->bounds
.rows
[i
]);
8146 xfree (font
->bounds
.rows
);
8147 ATSUDisposeStyle (font
->mac_style
);
8151 if (font
->bounds
.per_char
)
8152 xfree (font
->bounds
.per_char
);
8153 #if USE_CG_TEXT_DRAWING
8155 CGFontRelease (font
->cg_font
);
8156 if (font
->cg_glyphs
)
8157 xfree (font
->cg_glyphs
);
8163 /* Load font named FONTNAME of the size SIZE for frame F, and return a
8164 pointer to the structure font_info while allocating it dynamically.
8165 If SIZE is 0, load any size of font.
8166 If loading is failed, return NULL. */
8169 x_load_font (f
, fontname
, size
)
8171 register char *fontname
;
8174 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
8175 Lisp_Object font_names
;
8177 /* Get a list of all the fonts that match this name. Once we
8178 have a list of matching fonts, we compare them against the fonts
8179 we already have by comparing names. */
8180 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
8182 if (!NILP (font_names
))
8187 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
8188 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
8189 if (dpyinfo
->font_table
[i
].name
8190 && (!strcmp (dpyinfo
->font_table
[i
].name
,
8191 SDATA (XCAR (tail
)))
8192 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
8193 SDATA (XCAR (tail
)))))
8194 return (dpyinfo
->font_table
+ i
);
8199 /* Load the font and add it to the table. */
8201 struct MacFontStruct
*font
;
8202 struct font_info
*fontp
;
8205 fontname
= (char *) SDATA (XCAR (font_names
));
8208 font
= (MacFontStruct
*) XLoadQueryFont (FRAME_MAC_DISPLAY (f
), fontname
);
8213 /* Find a free slot in the font table. */
8214 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
8215 if (dpyinfo
->font_table
[i
].name
== NULL
)
8218 /* If no free slot found, maybe enlarge the font table. */
8219 if (i
== dpyinfo
->n_fonts
8220 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
8223 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
8224 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
8226 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
8229 fontp
= dpyinfo
->font_table
+ i
;
8230 if (i
== dpyinfo
->n_fonts
)
8233 /* Now fill in the slots of *FONTP. */
8235 bzero (fontp
, sizeof (*fontp
));
8237 fontp
->font_idx
= i
;
8238 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
8239 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
8241 if (font
->min_bounds
.width
== font
->max_bounds
.width
)
8243 /* Fixed width font. */
8244 fontp
->average_width
= fontp
->space_width
= font
->min_bounds
.width
;
8251 char2b
.byte1
= 0x00, char2b
.byte2
= 0x20;
8252 pcm
= mac_per_char_metric (font
, &char2b
, 0);
8254 fontp
->space_width
= pcm
->width
;
8256 fontp
->space_width
= FONT_WIDTH (font
);
8260 int width
= pcm
->width
;
8261 for (char2b
.byte2
= 33; char2b
.byte2
<= 126; char2b
.byte2
++)
8262 if ((pcm
= mac_per_char_metric (font
, &char2b
, 0)) != NULL
)
8263 width
+= pcm
->width
;
8264 fontp
->average_width
= width
/ 95;
8267 fontp
->average_width
= FONT_WIDTH (font
);
8270 fontp
->full_name
= (char *) xmalloc (strlen (font
->full_name
) + 1);
8271 bcopy (font
->full_name
, fontp
->full_name
, strlen (font
->full_name
) + 1);
8273 fontp
->size
= font
->max_bounds
.width
;
8274 fontp
->height
= FONT_HEIGHT (font
);
8276 /* For some font, ascent and descent in max_bounds field is
8277 larger than the above value. */
8278 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
8279 if (max_height
> fontp
->height
)
8280 fontp
->height
= max_height
;
8283 /* The slot `encoding' specifies how to map a character
8284 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
8285 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
8286 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
8287 2:0xA020..0xFF7F). For the moment, we don't know which charset
8288 uses this font. So, we set information in fontp->encoding[1]
8289 which is never used by any charset. If mapping can't be
8290 decided, set FONT_ENCODING_NOT_DECIDED. */
8291 if (font
->mac_scriptcode
== smJapanese
)
8292 fontp
->encoding
[1] = 4;
8296 = (font
->max_byte1
== 0
8298 ? (font
->min_char_or_byte2
< 0x80
8299 ? (font
->max_char_or_byte2
< 0x80
8300 ? 0 /* 0x20..0x7F */
8301 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
8302 : 1) /* 0xA0..0xFF */
8304 : (font
->min_byte1
< 0x80
8305 ? (font
->max_byte1
< 0x80
8306 ? (font
->min_char_or_byte2
< 0x80
8307 ? (font
->max_char_or_byte2
< 0x80
8308 ? 0 /* 0x2020..0x7F7F */
8309 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
8310 : 3) /* 0x20A0..0x7FFF */
8311 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
8312 : (font
->min_char_or_byte2
< 0x80
8313 ? (font
->max_char_or_byte2
< 0x80
8314 ? 2 /* 0xA020..0xFF7F */
8315 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
8316 : 1))); /* 0xA0A0..0xFFFF */
8319 #if 0 /* MAC_TODO: fill these out with more reasonably values */
8320 fontp
->baseline_offset
8321 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
8322 ? (long) value
: 0);
8323 fontp
->relative_compose
8324 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
8325 ? (long) value
: 0);
8326 fontp
->default_ascent
8327 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
8328 ? (long) value
: 0);
8330 fontp
->baseline_offset
= 0;
8331 fontp
->relative_compose
= 0;
8332 fontp
->default_ascent
= 0;
8335 /* Set global flag fonts_changed_p to non-zero if the font loaded
8336 has a character with a smaller width than any other character
8337 before, or if the font loaded has a smaller height than any
8338 other font loaded before. If this happens, it will make a
8339 glyph matrix reallocation necessary. */
8340 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
8347 /* Return a pointer to struct font_info of a font named FONTNAME for
8348 frame F. If no such font is loaded, return NULL. */
8351 x_query_font (f
, fontname
)
8353 register char *fontname
;
8355 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
8358 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
8359 if (dpyinfo
->font_table
[i
].name
8360 && (!xstricmp (dpyinfo
->font_table
[i
].name
, fontname
)
8361 || !xstricmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
8362 return (dpyinfo
->font_table
+ i
);
8367 /* Find a CCL program for a font specified by FONTP, and set the member
8368 `encoder' of the structure. */
8371 x_find_ccl_program (fontp
)
8372 struct font_info
*fontp
;
8374 Lisp_Object list
, elt
;
8376 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
8380 && STRINGP (XCAR (elt
))
8381 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
8387 struct ccl_program
*ccl
8388 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
8390 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
8393 fontp
->font_encoder
= ccl
;
8397 #if USE_MAC_FONT_PANEL
8398 /* Whether Font Panel has been shown before. The first call to font
8399 panel functions (FPIsFontPanelVisible, SetFontInfoForSelection) is
8400 slow. This variable is used for deferring such a call as much as
8402 static int font_panel_shown_p
= 0;
8405 mac_font_panel_visible_p ()
8407 return font_panel_shown_p
&& FPIsFontPanelVisible ();
8411 mac_show_hide_font_panel ()
8413 font_panel_shown_p
= 1;
8415 return FPShowHideFontPanel ();
8419 mac_set_font_info_for_selection (f
, face_id
, c
)
8424 EventTargetRef target
= NULL
;
8425 XFontStruct
*font
= NULL
;
8427 if (!mac_font_panel_visible_p ())
8432 target
= GetWindowEventTarget (FRAME_MAC_WINDOW (f
));
8434 if (FRAME_FACE_CACHE (f
) && CHAR_VALID_P (c
, 0))
8438 face_id
= FACE_FOR_CHAR (f
, FACE_FROM_ID (f
, face_id
), c
);
8439 face
= FACE_FROM_ID (f
, face_id
);
8445 err
= SetFontInfoForSelection (kFontSelectionATSUIType
, 0, NULL
, target
);
8448 if (font
->mac_fontnum
!= -1)
8450 FontSelectionQDStyle qd_style
;
8452 qd_style
.version
= kFontSelectionQDStyleVersionZero
;
8453 qd_style
.instance
.fontFamily
= font
->mac_fontnum
;
8454 qd_style
.instance
.fontStyle
= font
->mac_fontface
;
8455 qd_style
.size
= font
->mac_fontsize
;
8456 qd_style
.hasColor
= false;
8458 err
= SetFontInfoForSelection (kFontSelectionQDType
,
8459 1, &qd_style
, target
);
8462 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,
8463 1, &font
->mac_style
, target
);
8471 /* The Mac Event loop code */
8473 #if !TARGET_API_MAC_CARBON
8475 #include <Quickdraw.h>
8476 #include <Balloons.h>
8477 #include <Devices.h>
8479 #include <Gestalt.h>
8481 #include <Processes.h>
8483 #include <ToolUtils.h>
8484 #include <TextUtils.h>
8485 #include <Dialogs.h>
8488 #include <Resources.h>
8493 #endif /* ! TARGET_API_MAC_CARBON */
8498 #define WINDOW_RESOURCE 128
8499 #define TERM_WINDOW_RESOURCE 129
8501 #define DEFAULT_NUM_COLS 80
8503 #define MIN_DOC_SIZE 64
8504 #define MAX_DOC_SIZE 32767
8506 #define EXTRA_STACK_ALLOC (256 * 1024)
8508 #define ARGV_STRING_LIST_ID 129
8509 #define ABOUT_ALERT_ID 128
8510 #define RAM_TOO_LARGE_ALERT_ID 129
8512 /* Contains the string "reverse", which is a constant for mouse button emu.*/
8513 Lisp_Object Qreverse
;
8516 /* Modifier associated with the control key, or nil to ignore. */
8517 Lisp_Object Vmac_control_modifier
;
8519 /* Modifier associated with the option key, or nil to ignore. */
8520 Lisp_Object Vmac_option_modifier
;
8522 /* Modifier associated with the command key, or nil to ignore. */
8523 Lisp_Object Vmac_command_modifier
;
8525 /* Modifier associated with the function key, or nil to ignore. */
8526 Lisp_Object Vmac_function_modifier
;
8528 /* True if the option and command modifiers should be used to emulate
8529 a three button mouse */
8530 Lisp_Object Vmac_emulate_three_button_mouse
;
8532 #if USE_CARBON_EVENTS
8533 /* Non-zero if the mouse wheel button (i.e. button 4) should map to
8534 mouse-2, instead of mouse-3. */
8535 int mac_wheel_button_is_mouse_2
;
8537 /* If non-zero, the Mac "Command" key is passed on to the Mac Toolbox
8538 for processing before Emacs sees it. */
8539 int mac_pass_command_to_system
;
8541 /* If non-zero, the Mac "Control" key is passed on to the Mac Toolbox
8542 for processing before Emacs sees it. */
8543 int mac_pass_control_to_system
;
8546 /* Points to the variable `inev' in the function XTread_socket. It is
8547 used for passing an input event to the function back from
8548 Carbon/Apple event handlers. */
8549 static struct input_event
*read_socket_inev
= NULL
;
8551 Point saved_menu_event_location
;
8554 #if USE_CARBON_EVENTS
8555 static Lisp_Object Qhi_command
;
8557 extern Lisp_Object Qwindow
;
8558 static Lisp_Object Qtoolbar_switch_mode
;
8560 #if USE_MAC_FONT_PANEL
8561 extern Lisp_Object Qfont
;
8562 static Lisp_Object Qpanel_closed
, Qselection
;
8565 static TSMDocumentID tsm_document_id
;
8566 static Lisp_Object Qtext_input
;
8567 static Lisp_Object Qupdate_active_input_area
, Qunicode_for_key_event
;
8568 static Lisp_Object Vmac_ts_active_input_overlay
;
8569 extern Lisp_Object Qbefore_string
;
8570 static Lisp_Object Vmac_ts_script_language_on_focus
;
8571 static Lisp_Object saved_ts_script_language_on_focus
;
8572 static ScriptLanguageRecord saved_ts_language
;
8573 static Component saved_ts_component
;
8576 extern int mac_ready_for_apple_events
;
8577 extern Lisp_Object Qundefined
;
8578 extern void init_apple_event_handler
P_ ((void));
8579 extern void mac_find_apple_event_spec
P_ ((AEEventClass
, AEEventID
,
8580 Lisp_Object
*, Lisp_Object
*,
8582 extern OSErr init_coercion_handler
P_ ((void));
8585 OSErr install_drag_handler
P_ ((WindowRef
));
8586 void remove_drag_handler
P_ ((WindowRef
));
8588 #if USE_CARBON_EVENTS
8590 extern void init_service_handler ();
8591 static Lisp_Object Qservice
, Qpaste
, Qperform
;
8593 /* Window Event Handler */
8594 static pascal OSStatus
mac_handle_window_event (EventHandlerCallRef
,
8597 OSStatus
install_window_handler (WindowPtr
);
8599 extern void init_emacs_passwd_dir ();
8600 extern int emacs_main (int, char **, char **);
8602 extern void initialize_applescript();
8603 extern void terminate_applescript();
8605 /* Table for translating Mac keycode to X keysym values. Contributed
8607 Mapping for special keys is now identical to that in Apple X11
8608 except `clear' (-> <clear>) on the KeyPad, `enter' (-> <kp-enter>)
8609 on the right of the Cmd key on laptops, and fn + `enter' (->
8611 static unsigned char keycode_to_xkeysym_table
[] = {
8612 /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8613 /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8614 /*0x20*/ 0, 0, 0, 0, 0x0d /*return*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8616 /*0x30*/ 0x09 /*tab*/, 0 /*0x0020 space*/, 0, 0x08 /*backspace*/,
8617 /*0x34*/ 0x8d /*enter on laptops*/, 0x1b /*escape*/, 0, 0,
8618 /*0x38*/ 0, 0, 0, 0,
8619 /*0x3C*/ 0, 0, 0, 0,
8621 /*0x40*/ 0, 0xae /*kp-decimal*/, 0, 0xaa /*kp-multiply*/,
8622 /*0x44*/ 0, 0xab /*kp-add*/, 0, 0x0b /*clear*/,
8623 /*0x48*/ 0, 0, 0, 0xaf /*kp-divide*/,
8624 /*0x4C*/ 0x8d /*kp-enter*/, 0, 0xad /*kp-subtract*/, 0,
8626 /*0x50*/ 0, 0xbd /*kp-equal*/, 0xb0 /*kp-0*/, 0xb1 /*kp-1*/,
8627 /*0x54*/ 0xb2 /*kp-2*/, 0xb3 /*kp-3*/, 0xb4 /*kp-4*/, 0xb5 /*kp-5*/,
8628 /*0x58*/ 0xb6 /*kp-6*/, 0xb7 /*kp-7*/, 0, 0xb8 /*kp-8*/,
8629 /*0x5C*/ 0xb9 /*kp-9*/, 0, 0, 0,
8631 /*0x60*/ 0xc2 /*f5*/, 0xc3 /*f6*/, 0xc4 /*f7*/, 0xc0 /*f3*/,
8632 /*0x64*/ 0xc5 /*f8*/, 0xc6 /*f9*/, 0, 0xc8 /*f11*/,
8633 /*0x68*/ 0, 0xca /*f13*/, 0xcd /*f16*/, 0xcb /*f14*/,
8634 /*0x6C*/ 0, 0xc7 /*f10*/, 0x0a /*fn+enter on laptops*/, 0xc9 /*f12*/,
8636 /*0x70*/ 0, 0xcc /*f15*/, 0x6a /*help*/, 0x50 /*home*/,
8637 /*0x74*/ 0x55 /*pgup*/, 0xff /*delete*/, 0xc1 /*f4*/, 0x57 /*end*/,
8638 /*0x78*/ 0xbf /*f2*/, 0x56 /*pgdown*/, 0xbe /*f1*/, 0x51 /*left*/,
8639 /*0x7C*/ 0x53 /*right*/, 0x54 /*down*/, 0x52 /*up*/, 0
8643 /* Table for translating Mac keycode with the laptop `fn' key to that
8644 without it. Destination symbols in comments are keys on US
8645 keyboard, and they may not be the same on other types of keyboards.
8646 If the destination is identical to the source (f1 ... f12), it
8647 doesn't map `fn' key to a modifier. */
8648 static unsigned char fn_keycode_to_keycode_table
[] = {
8649 /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8650 /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8651 /*0x20*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8653 /*0x30*/ 0, 0, 0, 0,
8654 /*0x34*/ 0, 0, 0, 0,
8655 /*0x38*/ 0, 0, 0, 0,
8656 /*0x3C*/ 0, 0, 0, 0,
8658 /*0x40*/ 0, 0x2f /*kp-decimal -> '.'*/, 0, 0x23 /*kp-multiply -> 'p'*/,
8659 /*0x44*/ 0, 0x2c /*kp-add -> '/'*/, 0, 0x16 /*clear -> '6'*/,
8660 /*0x48*/ 0, 0, 0, 0x1d /*kp-/ -> '0'*/,
8661 /*0x4C*/ 0x24 /*kp-enter -> return*/, 0, 0x29 /*kp-subtract -> ';'*/, 0,
8663 /*0x50*/ 0, 0x1b /*kp-equal -> '-'*/, 0x2e /*kp-0 -> 'm'*/, 0x26 /*kp-1 -> 'j'*/,
8664 /*0x54*/ 0x28 /*kp-2 -> 'k'*/, 0x25 /*kp-3 -> 'l'*/, 0x20 /*kp-4 -> 'u'*/, 0x22 /*kp-5 ->'i'*/,
8665 /*0x58*/ 0x1f /*kp-6 -> 'o'*/, 0x1a /*kp-7 -> '7'*/, 0, 0x1c /*kp-8 -> '8'*/,
8666 /*0x5C*/ 0x19 /*kp-9 -> '9'*/, 0, 0, 0,
8668 /*0x60*/ 0x60 /*f5 = f5*/, 0x61 /*f6 = f6*/, 0x62 /*f7 = f7*/, 0x63 /*f3 = f3*/,
8669 /*0x64*/ 0x64 /*f8 = f8*/, 0x65 /*f9 = f9*/, 0, 0x67 /*f11 = f11*/,
8670 /*0x68*/ 0, 0, 0, 0,
8671 /*0x6C*/ 0, 0x6d /*f10 = f10*/, 0, 0x6f /*f12 = f12*/,
8673 /*0x70*/ 0, 0, 0, 0x7b /*home -> left*/,
8674 /*0x74*/ 0x7e /*pgup -> up*/, 0x33 /*delete -> backspace*/, 0x76 /*f4 = f4*/, 0x7c /*end -> right*/,
8675 /*0x78*/ 0x78 /*f2 = f2*/, 0x7d /*pgdown -> down*/, 0x7a /*f1 = f1*/, 0,
8678 #endif /* MAC_OSX */
8681 #if USE_CARBON_EVENTS
8682 mac_to_emacs_modifiers (UInt32 mods
)
8684 mac_to_emacs_modifiers (EventModifiers mods
)
8687 unsigned int result
= 0;
8688 if (mods
& shiftKey
)
8689 result
|= shift_modifier
;
8691 /* Deactivated to simplify configuration:
8692 if Vmac_option_modifier is non-NIL, we fully process the Option
8693 key. Otherwise, we only process it if an additional Ctrl or Command
8694 is pressed. That way the system may convert the character to a
8696 if ((mods & optionKey) &&
8697 (( !NILP(Vmac_option_modifier) ||
8698 ((mods & cmdKey) || (mods & controlKey))))) */
8700 if (!NILP (Vmac_option_modifier
) && (mods
& optionKey
)) {
8701 Lisp_Object val
= Fget(Vmac_option_modifier
, Qmodifier_value
);
8703 result
|= XUINT(val
);
8705 if (!NILP (Vmac_command_modifier
) && (mods
& cmdKey
)) {
8706 Lisp_Object val
= Fget(Vmac_command_modifier
, Qmodifier_value
);
8708 result
|= XUINT(val
);
8710 if (!NILP (Vmac_control_modifier
) && (mods
& controlKey
)) {
8711 Lisp_Object val
= Fget(Vmac_control_modifier
, Qmodifier_value
);
8713 result
|= XUINT(val
);
8717 if (!NILP (Vmac_function_modifier
) && (mods
& kEventKeyModifierFnMask
)) {
8718 Lisp_Object val
= Fget(Vmac_function_modifier
, Qmodifier_value
);
8720 result
|= XUINT(val
);
8728 mac_get_emulated_btn ( UInt32 modifiers
)
8731 if (!NILP (Vmac_emulate_three_button_mouse
)) {
8732 int cmdIs3
= !EQ (Vmac_emulate_three_button_mouse
, Qreverse
);
8733 if (modifiers
& cmdKey
)
8734 result
= cmdIs3
? 2 : 1;
8735 else if (modifiers
& optionKey
)
8736 result
= cmdIs3
? 1 : 2;
8741 #if USE_CARBON_EVENTS
8742 /* Obtains the event modifiers from the event ref and then calls
8743 mac_to_emacs_modifiers. */
8745 mac_event_to_emacs_modifiers (EventRef eventRef
)
8748 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
8749 sizeof (UInt32
), NULL
, &mods
);
8750 if (!NILP (Vmac_emulate_three_button_mouse
) &&
8751 GetEventClass(eventRef
) == kEventClassMouse
)
8753 mods
&= ~(optionKey
| cmdKey
);
8755 return mac_to_emacs_modifiers (mods
);
8758 /* Given an event ref, return the code to use for the mouse button
8759 code in the emacs input_event. */
8761 mac_get_mouse_btn (EventRef ref
)
8763 EventMouseButton result
= kEventMouseButtonPrimary
;
8764 GetEventParameter (ref
, kEventParamMouseButton
, typeMouseButton
, NULL
,
8765 sizeof (EventMouseButton
), NULL
, &result
);
8768 case kEventMouseButtonPrimary
:
8769 if (NILP (Vmac_emulate_three_button_mouse
))
8773 GetEventParameter (ref
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
8774 sizeof (UInt32
), NULL
, &mods
);
8775 return mac_get_emulated_btn(mods
);
8777 case kEventMouseButtonSecondary
:
8778 return mac_wheel_button_is_mouse_2
? 2 : 1;
8779 case kEventMouseButtonTertiary
:
8780 case 4: /* 4 is the number for the mouse wheel button */
8781 return mac_wheel_button_is_mouse_2
? 1 : 2;
8787 /* Normally, ConvertEventRefToEventRecord will correctly handle all
8788 events. However the click of the mouse wheel is not converted to a
8789 mouseDown or mouseUp event. Likewise for dead key down events.
8790 This calls ConvertEventRef, but then checks to see if it is a mouse
8791 up/down, or a dead key down carbon event that has not been
8792 converted, and if so, converts it by hand (to be picked up in the
8793 XTread_socket loop). */
8794 static Boolean
mac_convert_event_ref (EventRef eventRef
, EventRecord
*eventRec
)
8797 Boolean result
= ConvertEventRefToEventRecord (eventRef
, eventRec
);
8802 switch (GetEventClass (eventRef
))
8804 case kEventClassMouse
:
8805 switch (GetEventKind (eventRef
))
8807 case kEventMouseDown
:
8808 eventRec
->what
= mouseDown
;
8813 eventRec
->what
= mouseUp
;
8822 case kEventClassKeyboard
:
8823 switch (GetEventKind (eventRef
))
8825 case kEventRawKeyDown
:
8827 unsigned char char_codes
;
8830 err
= GetEventParameter (eventRef
, kEventParamKeyMacCharCodes
,
8831 typeChar
, NULL
, sizeof (char),
8834 err
= GetEventParameter (eventRef
, kEventParamKeyCode
,
8835 typeUInt32
, NULL
, sizeof (UInt32
),
8839 eventRec
->what
= keyDown
;
8840 eventRec
->message
= char_codes
| ((key_code
& 0xff) << 8);
8857 /* Need where and when. */
8860 GetEventParameter (eventRef
, kEventParamMouseLocation
, typeQDPoint
,
8861 NULL
, sizeof (Point
), NULL
, &eventRec
->where
);
8862 /* Use two step process because new event modifiers are 32-bit
8863 and old are 16-bit. Currently, only loss is NumLock & Fn. */
8864 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
,
8865 NULL
, sizeof (UInt32
), NULL
, &mods
);
8866 eventRec
->modifiers
= mods
;
8868 eventRec
->when
= EventTimeToTicks (GetEventTime (eventRef
));
8880 Handle menubar_handle
;
8881 MenuHandle menu_handle
;
8883 menubar_handle
= GetNewMBar (128);
8884 if(menubar_handle
== NULL
)
8886 SetMenuBar (menubar_handle
);
8889 #if !TARGET_API_MAC_CARBON
8890 menu_handle
= GetMenuHandle (M_APPLE
);
8891 if(menu_handle
!= NULL
)
8892 AppendResMenu (menu_handle
,'DRVR');
8900 do_init_managers (void)
8902 #if !TARGET_API_MAC_CARBON
8903 InitGraf (&qd
.thePort
);
8905 FlushEvents (everyEvent
, 0);
8910 #endif /* !TARGET_API_MAC_CARBON */
8913 #if !TARGET_API_MAC_CARBON
8914 /* set up some extra stack space for use by emacs */
8915 SetApplLimit ((Ptr
) ((long) GetApplLimit () - EXTRA_STACK_ALLOC
));
8917 /* MaxApplZone must be called for AppleScript to execute more
8918 complicated scripts */
8921 #endif /* !TARGET_API_MAC_CARBON */
8925 do_check_ram_size (void)
8927 SInt32 physical_ram_size
, logical_ram_size
;
8929 if (Gestalt (gestaltPhysicalRAMSize
, &physical_ram_size
) != noErr
8930 || Gestalt (gestaltLogicalRAMSize
, &logical_ram_size
) != noErr
8931 || physical_ram_size
> (1 << VALBITS
)
8932 || logical_ram_size
> (1 << VALBITS
))
8934 StopAlert (RAM_TOO_LARGE_ALERT_ID
, NULL
);
8938 #endif /* MAC_OS8 */
8941 do_window_update (WindowPtr win
)
8943 struct frame
*f
= mac_window_to_frame (win
);
8947 /* The tooltip has been drawn already. Avoid the SET_FRAME_GARBAGED
8949 if (win
!= tip_window
)
8951 if (f
->async_visible
== 0)
8953 /* Update events may occur when a frame gets iconified. */
8955 f
->async_visible
= 1;
8956 f
->async_iconified
= 0;
8957 SET_FRAME_GARBAGED (f
);
8963 #if TARGET_API_MAC_CARBON
8964 RgnHandle region
= NewRgn ();
8966 GetPortVisibleRegion (GetWindowPort (win
), region
);
8967 GetRegionBounds (region
, &r
);
8968 expose_frame (f
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
);
8969 UpdateControls (win
, region
);
8970 DisposeRgn (region
);
8972 r
= (*win
->visRgn
)->rgnBBox
;
8973 expose_frame (f
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
);
8974 UpdateControls (win
, win
->visRgn
);
8983 is_emacs_window (WindowPtr win
)
8985 Lisp_Object tail
, frame
;
8990 FOR_EACH_FRAME (tail
, frame
)
8991 if (FRAME_MAC_P (XFRAME (frame
)))
8992 if (FRAME_MAC_WINDOW (XFRAME (frame
)) == win
)
9003 ScriptLanguageRecord slrec
, *slptr
= NULL
;
9005 err
= ActivateTSMDocument (tsm_document_id
);
9009 if (EQ (Vmac_ts_script_language_on_focus
, Qt
)
9010 && EQ (saved_ts_script_language_on_focus
, Qt
))
9011 slptr
= &saved_ts_language
;
9012 else if (CONSP (Vmac_ts_script_language_on_focus
)
9013 && INTEGERP (XCAR (Vmac_ts_script_language_on_focus
))
9014 && INTEGERP (XCDR (Vmac_ts_script_language_on_focus
))
9015 && CONSP (saved_ts_script_language_on_focus
)
9016 && EQ (XCAR (saved_ts_script_language_on_focus
),
9017 XCAR (Vmac_ts_script_language_on_focus
))
9018 && EQ (XCDR (saved_ts_script_language_on_focus
),
9019 XCDR (Vmac_ts_script_language_on_focus
)))
9021 slrec
.fScript
= XINT (XCAR (Vmac_ts_script_language_on_focus
));
9022 slrec
.fLanguage
= XINT (XCDR (Vmac_ts_script_language_on_focus
));
9029 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
9030 err
= SetDefaultInputMethodOfClass (saved_ts_component
, slptr
,
9031 kKeyboardInputMethodClass
);
9033 err
= SetDefaultInputMethod (saved_ts_component
, slptr
);
9036 err
= SetTextServiceLanguage (slptr
);
9038 /* Seems to be needed on Mac OS X 10.2. */
9040 KeyScript (slptr
->fScript
| smKeyForceKeyScriptMask
);
9050 ScriptLanguageRecord slrec
, *slptr
= NULL
;
9052 saved_ts_script_language_on_focus
= Vmac_ts_script_language_on_focus
;
9054 if (EQ (Vmac_ts_script_language_on_focus
, Qt
))
9056 err
= GetTextServiceLanguage (&saved_ts_language
);
9058 slptr
= &saved_ts_language
;
9060 else if (CONSP (Vmac_ts_script_language_on_focus
)
9061 && INTEGERP (XCAR (Vmac_ts_script_language_on_focus
))
9062 && INTEGERP (XCDR (Vmac_ts_script_language_on_focus
)))
9064 slrec
.fScript
= XINT (XCAR (Vmac_ts_script_language_on_focus
));
9065 slrec
.fLanguage
= XINT (XCDR (Vmac_ts_script_language_on_focus
));
9071 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
9072 GetDefaultInputMethodOfClass (&saved_ts_component
, slptr
,
9073 kKeyboardInputMethodClass
);
9075 GetDefaultInputMethod (&saved_ts_component
, slptr
);
9079 err
= DeactivateTSMDocument (tsm_document_id
);
9086 do_apple_menu (SInt16 menu_item
)
9088 #if !TARGET_API_MAC_CARBON
9090 SInt16 da_driver_refnum
;
9092 if (menu_item
== I_ABOUT
)
9093 NoteAlert (ABOUT_ALERT_ID
, NULL
);
9096 GetMenuItemText (GetMenuHandle (M_APPLE
), menu_item
, item_name
);
9097 da_driver_refnum
= OpenDeskAcc (item_name
);
9099 #endif /* !TARGET_API_MAC_CARBON */
9103 do_menu_choice (SInt32 menu_choice
)
9105 SInt16 menu_id
, menu_item
;
9107 menu_id
= HiWord (menu_choice
);
9108 menu_item
= LoWord (menu_choice
);
9116 do_apple_menu (menu_item
);
9121 struct frame
*f
= mac_focus_frame (&one_mac_display_info
);
9122 MenuHandle menu
= GetMenuHandle (menu_id
);
9127 GetMenuItemRefCon (menu
, menu_item
, &refcon
);
9128 menubar_selection_callback (f
, refcon
);
9137 /* Handle drags in size box. Based on code contributed by Ben
9138 Mesander and IM - Window Manager A. */
9141 do_grow_window (WindowPtr w
, EventRecord
*e
)
9144 int rows
, columns
, width
, height
;
9145 struct frame
*f
= mac_window_to_frame (w
);
9146 XSizeHints
*size_hints
= FRAME_SIZE_HINTS (f
);
9147 int min_width
= MIN_DOC_SIZE
, min_height
= MIN_DOC_SIZE
;
9148 #if TARGET_API_MAC_CARBON
9154 if (size_hints
->flags
& PMinSize
)
9156 min_width
= size_hints
->min_width
;
9157 min_height
= size_hints
->min_height
;
9159 SetRect (&limit_rect
, min_width
, min_height
, MAX_DOC_SIZE
, MAX_DOC_SIZE
);
9161 #if TARGET_API_MAC_CARBON
9162 if (!ResizeWindow (w
, e
->where
, &limit_rect
, &new_rect
))
9164 height
= new_rect
.bottom
- new_rect
.top
;
9165 width
= new_rect
.right
- new_rect
.left
;
9167 grow_size
= GrowWindow (w
, e
->where
, &limit_rect
);
9168 /* see if it really changed size */
9171 height
= HiWord (grow_size
);
9172 width
= LoWord (grow_size
);
9175 if (width
!= FRAME_PIXEL_WIDTH (f
)
9176 || height
!= FRAME_PIXEL_HEIGHT (f
))
9178 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, height
);
9179 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, width
);
9181 x_set_window_size (f
, 0, columns
, rows
);
9186 #if TARGET_API_MAC_CARBON
9188 mac_get_ideal_size (f
)
9191 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
9192 WindowPtr w
= FRAME_MAC_WINDOW (f
);
9195 int height
, width
, columns
, rows
;
9197 ideal_size
.h
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
9198 ideal_size
.v
= dpyinfo
->height
;
9199 IsWindowInStandardState (w
, &ideal_size
, &standard_rect
);
9200 /* Adjust the standard size according to character boundaries. */
9201 width
= standard_rect
.right
- standard_rect
.left
;
9202 height
= standard_rect
.bottom
- standard_rect
.top
;
9203 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, width
);
9204 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, height
);
9205 ideal_size
.h
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, columns
);
9206 ideal_size
.v
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
9212 /* Handle clicks in zoom box. Calculation of "standard state" based
9213 on code in IM - Window Manager A and code contributed by Ben
9214 Mesander. The standard state of an Emacs window is 80-characters
9215 wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */
9218 do_zoom_window (WindowPtr w
, int zoom_in_or_out
)
9220 Rect zoom_rect
, port_rect
;
9222 struct frame
*f
= mac_window_to_frame (w
);
9223 #if TARGET_API_MAC_CARBON
9224 Point ideal_size
= mac_get_ideal_size (f
);
9226 GetWindowBounds (w
, kWindowContentRgn
, &port_rect
);
9227 if (IsWindowInStandardState (w
, &ideal_size
, &zoom_rect
)
9228 && port_rect
.left
== zoom_rect
.left
9229 && port_rect
.top
== zoom_rect
.top
)
9230 zoom_in_or_out
= inZoomIn
;
9232 zoom_in_or_out
= inZoomOut
;
9235 mac_clear_window (f
);
9237 ZoomWindowIdeal (w
, zoom_in_or_out
, &ideal_size
);
9238 #else /* not TARGET_API_MAC_CARBON */
9241 int w_title_height
, rows
;
9242 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
9244 GetPort (&save_port
);
9246 SetPortWindowPort (w
);
9248 /* Clear window to avoid flicker. */
9249 EraseRect (&(w
->portRect
));
9250 if (zoom_in_or_out
== inZoomOut
)
9252 SetPt (&top_left
, w
->portRect
.left
, w
->portRect
.top
);
9253 LocalToGlobal (&top_left
);
9255 /* calculate height of window's title bar */
9256 w_title_height
= top_left
.v
- 1
9257 - (**((WindowPeek
) w
)->strucRgn
).rgnBBox
.top
+ GetMBarHeight ();
9259 /* get maximum height of window into zoom_rect.bottom - zoom_rect.top */
9260 zoom_rect
= qd
.screenBits
.bounds
;
9261 zoom_rect
.top
+= w_title_height
;
9262 InsetRect (&zoom_rect
, 8, 4); /* not too tight */
9264 zoom_rect
.right
= zoom_rect
.left
9265 + FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
9267 /* Adjust the standard size according to character boundaries. */
9268 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, zoom_rect
.bottom
- zoom_rect
.top
);
9270 zoom_rect
.top
+ FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
9272 (**((WStateDataHandle
) ((WindowPeek
) w
)->dataHandle
)).stdState
9276 ZoomWindow (w
, zoom_in_or_out
, f
== mac_focus_frame (dpyinfo
));
9278 SetPort (save_port
);
9279 #endif /* not TARGET_API_MAC_CARBON */
9281 #if !USE_CARBON_EVENTS
9282 /* retrieve window size and update application values */
9283 #if TARGET_API_MAC_CARBON
9284 GetWindowPortBounds (w
, &port_rect
);
9286 port_rect
= w
->portRect
;
9288 height
= port_rect
.bottom
- port_rect
.top
;
9289 width
= port_rect
.right
- port_rect
.left
;
9291 mac_handle_size_change (f
, width
, height
);
9292 mac_handle_origin_change (f
);
9297 mac_store_apple_event (class, id
, desc
)
9298 Lisp_Object
class, id
;
9301 struct input_event buf
;
9305 buf
.kind
= MAC_APPLE_EVENT
;
9308 XSETFRAME (buf
.frame_or_window
,
9309 mac_focus_frame (&one_mac_display_info
));
9310 /* Now that Lisp object allocations are protected by BLOCK_INPUT, it
9311 is safe to use them during read_socket_hook. */
9312 buf
.arg
= mac_aedesc_to_lisp (desc
);
9313 kbd_buffer_store_event (&buf
);
9316 #if TARGET_API_MAC_CARBON
9318 mac_store_event_ref_as_apple_event (class, id
, class_key
, id_key
,
9319 event
, num_params
, names
, types
)
9322 Lisp_Object class_key
, id_key
;
9325 EventParamName
*names
;
9326 EventParamType
*types
;
9328 OSStatus err
= eventNotHandledErr
;
9329 Lisp_Object binding
;
9331 mac_find_apple_event_spec (class, id
, &class_key
, &id_key
, &binding
);
9332 if (!NILP (binding
) && !EQ (binding
, Qundefined
))
9334 if (INTEGERP (binding
))
9335 err
= XINT (binding
);
9338 AppleEvent apple_event
;
9339 err
= create_apple_event_from_event_ref (event
, num_params
,
9344 mac_store_apple_event (class_key
, id_key
, &apple_event
);
9345 AEDisposeDesc (&apple_event
);
9346 /* Post a harmless event so as to wake up from
9347 ReceiveNextEvent. */
9348 mac_post_mouse_moved_event ();
9357 mac_store_drag_event (window
, mouse_pos
, modifiers
, desc
)
9363 struct input_event buf
;
9367 buf
.kind
= DRAG_N_DROP_EVENT
;
9368 buf
.modifiers
= mac_to_emacs_modifiers (modifiers
);
9369 buf
.timestamp
= TickCount () * (1000 / 60);
9370 XSETINT (buf
.x
, mouse_pos
.h
);
9371 XSETINT (buf
.y
, mouse_pos
.v
);
9372 XSETFRAME (buf
.frame_or_window
, mac_window_to_frame (window
));
9373 buf
.arg
= mac_aedesc_to_lisp (desc
);
9374 kbd_buffer_store_event (&buf
);
9378 #if USE_CARBON_EVENTS
9379 static pascal OSStatus
9380 mac_handle_command_event (next_handler
, event
, data
)
9381 EventHandlerCallRef next_handler
;
9385 OSStatus result
, err
;
9387 static EventParamName names
[] = {kEventParamDirectObject
,
9388 kEventParamKeyModifiers
};
9389 static EventParamType types
[] = {typeHICommand
,
9391 int num_params
= sizeof (names
) / sizeof (names
[0]);
9393 result
= CallNextEventHandler (next_handler
, event
);
9394 if (result
!= eventNotHandledErr
)
9397 err
= GetEventParameter (event
, kEventParamDirectObject
, typeHICommand
,
9398 NULL
, sizeof (HICommand
), NULL
, &command
);
9400 if (err
!= noErr
|| command
.commandID
== 0)
9401 return eventNotHandledErr
;
9403 /* A HI command event is mapped to an Apple event whose event class
9404 symbol is `hi-command' and event ID is its command ID. */
9405 err
= mac_store_event_ref_as_apple_event (0, command
.commandID
,
9407 event
, num_params
, names
, types
);
9408 return err
== noErr
? noErr
: eventNotHandledErr
;
9412 init_command_handler ()
9414 EventTypeSpec specs
[] = {{kEventClassCommand
, kEventCommandProcess
}};
9415 static EventHandlerUPP handle_command_eventUPP
= NULL
;
9417 if (handle_command_eventUPP
== NULL
)
9418 handle_command_eventUPP
= NewEventHandlerUPP (mac_handle_command_event
);
9419 return InstallApplicationEventHandler (handle_command_eventUPP
,
9420 GetEventTypeCount (specs
), specs
,
9424 static pascal OSStatus
9425 mac_handle_window_event (next_handler
, event
, data
)
9426 EventHandlerCallRef next_handler
;
9431 OSStatus result
, err
;
9434 XSizeHints
*size_hints
;
9436 err
= GetEventParameter (event
, kEventParamDirectObject
, typeWindowRef
,
9437 NULL
, sizeof (WindowPtr
), NULL
, &wp
);
9439 return eventNotHandledErr
;
9441 f
= mac_window_to_frame (wp
);
9442 switch (GetEventKind (event
))
9444 case kEventWindowUpdate
:
9445 result
= CallNextEventHandler (next_handler
, event
);
9446 if (result
!= eventNotHandledErr
)
9449 do_window_update (wp
);
9452 case kEventWindowGetIdealSize
:
9453 result
= CallNextEventHandler (next_handler
, event
);
9454 if (result
!= eventNotHandledErr
)
9458 Point ideal_size
= mac_get_ideal_size (f
);
9460 err
= SetEventParameter (event
, kEventParamDimensions
,
9461 typeQDPoint
, sizeof (Point
), &ideal_size
);
9467 case kEventWindowBoundsChanging
:
9468 result
= CallNextEventHandler (next_handler
, event
);
9469 if (result
!= eventNotHandledErr
)
9472 err
= GetEventParameter (event
, kEventParamAttributes
, typeUInt32
,
9473 NULL
, sizeof (UInt32
), NULL
, &attributes
);
9477 size_hints
= FRAME_SIZE_HINTS (f
);
9478 if ((attributes
& kWindowBoundsChangeUserResize
)
9479 && ((size_hints
->flags
& (PResizeInc
| PBaseSize
| PMinSize
))
9480 == (PResizeInc
| PBaseSize
| PMinSize
)))
9485 err
= GetEventParameter (event
, kEventParamCurrentBounds
,
9486 typeQDRectangle
, NULL
, sizeof (Rect
),
9491 width
= bounds
.right
- bounds
.left
;
9492 height
= bounds
.bottom
- bounds
.top
;
9494 if (width
< size_hints
->min_width
)
9495 width
= size_hints
->min_width
;
9497 width
= size_hints
->base_width
9498 + (int) ((width
- size_hints
->base_width
)
9499 / (float) size_hints
->width_inc
+ .5)
9500 * size_hints
->width_inc
;
9502 if (height
< size_hints
->min_height
)
9503 height
= size_hints
->min_height
;
9505 height
= size_hints
->base_height
9506 + (int) ((height
- size_hints
->base_height
)
9507 / (float) size_hints
->height_inc
+ .5)
9508 * size_hints
->height_inc
;
9510 bounds
.right
= bounds
.left
+ width
;
9511 bounds
.bottom
= bounds
.top
+ height
;
9512 SetEventParameter (event
, kEventParamCurrentBounds
,
9513 typeQDRectangle
, sizeof (Rect
), &bounds
);
9518 case kEventWindowBoundsChanged
:
9519 err
= GetEventParameter (event
, kEventParamAttributes
, typeUInt32
,
9520 NULL
, sizeof (UInt32
), NULL
, &attributes
);
9524 if (attributes
& kWindowBoundsChangeSizeChanged
)
9528 err
= GetEventParameter (event
, kEventParamCurrentBounds
,
9529 typeQDRectangle
, NULL
, sizeof (Rect
),
9535 width
= bounds
.right
- bounds
.left
;
9536 height
= bounds
.bottom
- bounds
.top
;
9537 mac_handle_size_change (f
, width
, height
);
9541 if (attributes
& kWindowBoundsChangeOriginChanged
)
9542 mac_handle_origin_change (f
);
9546 case kEventWindowShown
:
9547 case kEventWindowHidden
:
9548 case kEventWindowExpanded
:
9549 case kEventWindowCollapsed
:
9550 result
= CallNextEventHandler (next_handler
, event
);
9552 mac_handle_visibility_change (f
);
9557 case kEventWindowClose
:
9558 result
= CallNextEventHandler (next_handler
, event
);
9560 struct input_event buf
;
9563 buf
.kind
= DELETE_WINDOW_EVENT
;
9564 XSETFRAME (buf
.frame_or_window
, f
);
9566 kbd_buffer_store_event (&buf
);
9571 case kEventWindowToolbarSwitchMode
:
9572 result
= CallNextEventHandler (next_handler
, event
);
9574 static EventParamName names
[] = {kEventParamDirectObject
,
9575 kEventParamWindowMouseLocation
,
9576 kEventParamKeyModifiers
,
9577 kEventParamMouseButton
,
9578 kEventParamClickCount
,
9579 kEventParamMouseChord
};
9580 static EventParamType types
[] = {typeWindowRef
,
9586 int num_params
= sizeof (names
) / sizeof (names
[0]);
9588 err
= mac_store_event_ref_as_apple_event (0, 0,
9590 Qtoolbar_switch_mode
,
9594 return err
== noErr
? noErr
: result
;
9598 case kEventWindowFocusAcquired
:
9599 result
= CallNextEventHandler (next_handler
, event
);
9600 err
= mac_tsm_resume ();
9601 return err
== noErr
? noErr
: result
;
9603 case kEventWindowFocusRelinquish
:
9604 result
= CallNextEventHandler (next_handler
, event
);
9605 err
= mac_tsm_suspend ();
9606 return err
== noErr
? noErr
: result
;
9610 return eventNotHandledErr
;
9613 static pascal OSStatus
9614 mac_handle_mouse_event (next_handler
, event
, data
)
9615 EventHandlerCallRef next_handler
;
9619 OSStatus result
, err
;
9621 switch (GetEventKind (event
))
9623 case kEventMouseWheelMoved
:
9627 EventMouseWheelAxis axis
;
9631 result
= CallNextEventHandler (next_handler
, event
);
9632 if (result
!= eventNotHandledErr
|| read_socket_inev
== NULL
)
9635 err
= GetEventParameter (event
, kEventParamWindowRef
, typeWindowRef
,
9636 NULL
, sizeof (WindowRef
), NULL
, &wp
);
9640 f
= mac_window_to_frame (wp
);
9641 if (f
!= mac_focus_frame (&one_mac_display_info
))
9644 err
= GetEventParameter (event
, kEventParamMouseWheelAxis
,
9645 typeMouseWheelAxis
, NULL
,
9646 sizeof (EventMouseWheelAxis
), NULL
, &axis
);
9647 if (err
!= noErr
|| axis
!= kEventMouseWheelAxisY
)
9650 err
= GetEventParameter (event
, kEventParamMouseWheelDelta
,
9651 typeSInt32
, NULL
, sizeof (SInt32
),
9655 err
= GetEventParameter (event
, kEventParamMouseLocation
,
9656 typeQDPoint
, NULL
, sizeof (Point
),
9660 read_socket_inev
->kind
= WHEEL_EVENT
;
9661 read_socket_inev
->code
= 0;
9662 read_socket_inev
->modifiers
=
9663 (mac_event_to_emacs_modifiers (event
)
9664 | ((delta
< 0) ? down_modifier
: up_modifier
));
9665 SetPortWindowPort (wp
);
9666 GlobalToLocal (&point
);
9667 XSETINT (read_socket_inev
->x
, point
.h
);
9668 XSETINT (read_socket_inev
->y
, point
.v
);
9669 XSETFRAME (read_socket_inev
->frame_or_window
, f
);
9679 return eventNotHandledErr
;
9682 #if USE_MAC_FONT_PANEL
9683 static pascal OSStatus
9684 mac_handle_font_event (next_handler
, event
, data
)
9685 EventHandlerCallRef next_handler
;
9689 OSStatus result
, err
;
9692 EventParamName
*names
;
9693 EventParamType
*types
;
9694 static EventParamName names_sel
[] = {kEventParamATSUFontID
,
9695 kEventParamATSUFontSize
,
9696 kEventParamFMFontFamily
,
9697 kEventParamFMFontSize
,
9698 kEventParamFontColor
};
9699 static EventParamType types_sel
[] = {typeATSUFontID
,
9705 result
= CallNextEventHandler (next_handler
, event
);
9706 if (result
!= eventNotHandledErr
)
9709 switch (GetEventKind (event
))
9711 case kEventFontPanelClosed
:
9712 id_key
= Qpanel_closed
;
9718 case kEventFontSelection
:
9719 id_key
= Qselection
;
9720 num_params
= sizeof (names_sel
) / sizeof (names_sel
[0]);
9726 err
= mac_store_event_ref_as_apple_event (0, 0, Qfont
, id_key
,
9730 return err
== noErr
? noErr
: eventNotHandledErr
;
9735 static pascal OSStatus
9736 mac_handle_text_input_event (next_handler
, event
, data
)
9737 EventHandlerCallRef next_handler
;
9741 OSStatus result
, err
= noErr
;
9742 Lisp_Object id_key
= Qnil
;
9744 EventParamName
*names
;
9745 EventParamType
*types
;
9746 static UInt32 seqno_uaia
= 0;
9747 static EventParamName names_uaia
[] =
9748 {kEventParamTextInputSendComponentInstance
,
9749 kEventParamTextInputSendRefCon
,
9750 kEventParamTextInputSendSLRec
,
9751 kEventParamTextInputSendFixLen
,
9752 kEventParamTextInputSendText
,
9753 kEventParamTextInputSendUpdateRng
,
9754 kEventParamTextInputSendHiliteRng
,
9755 kEventParamTextInputSendClauseRng
,
9756 kEventParamTextInputSendPinRng
,
9757 kEventParamTextInputSendTextServiceEncoding
,
9758 kEventParamTextInputSendTextServiceMacEncoding
,
9759 EVENT_PARAM_TEXT_INPUT_SEQUENCE_NUMBER
};
9760 static EventParamType types_uaia
[] =
9761 {typeComponentInstance
,
9763 typeIntlWritingCode
,
9777 static EventParamName names_ufke
[] =
9778 {kEventParamTextInputSendComponentInstance
,
9779 kEventParamTextInputSendRefCon
,
9780 kEventParamTextInputSendSLRec
,
9781 kEventParamTextInputSendText
};
9782 static EventParamType types_ufke
[] =
9783 {typeComponentInstance
,
9785 typeIntlWritingCode
,
9788 result
= CallNextEventHandler (next_handler
, event
);
9790 switch (GetEventKind (event
))
9792 case kEventTextInputUpdateActiveInputArea
:
9793 id_key
= Qupdate_active_input_area
;
9794 num_params
= sizeof (names_uaia
) / sizeof (names_uaia
[0]);
9797 SetEventParameter (event
, EVENT_PARAM_TEXT_INPUT_SEQUENCE_NUMBER
,
9798 typeUInt32
, sizeof (UInt32
), &seqno_uaia
);
9802 case kEventTextInputUnicodeForKeyEvent
:
9805 UInt32 actual_size
, modifiers
, mapped_modifiers
;
9807 err
= GetEventParameter (event
, kEventParamTextInputSendKeyboardEvent
,
9808 typeEventRef
, NULL
, sizeof (EventRef
), NULL
,
9811 err
= GetEventParameter (kbd_event
, kEventParamKeyModifiers
,
9813 sizeof (UInt32
), NULL
, &modifiers
);
9817 (NILP (Vmac_control_modifier
) ? 0 : controlKey
)
9818 | (NILP (Vmac_option_modifier
) ? 0 : optionKey
)
9819 | (NILP (Vmac_command_modifier
) ? 0 : cmdKey
);
9822 (NILP (Vmac_function_modifier
) ? 0 : kEventKeyModifierFnMask
);
9824 if (modifiers
& mapped_modifiers
)
9825 /* There're mapped modifier keys. Process it in
9827 return eventNotHandledErr
;
9830 err
= GetEventParameter (kbd_event
, kEventParamKeyUnicodes
,
9831 typeUnicodeText
, NULL
, 0, &actual_size
,
9833 if (err
== noErr
&& actual_size
== sizeof (UniChar
))
9837 err
= GetEventParameter (kbd_event
, kEventParamKeyUnicodes
,
9838 typeUnicodeText
, NULL
,
9839 sizeof (UniChar
), NULL
, &code
);
9840 if (err
== noErr
&& code
< 0x80)
9842 /* ASCII character. Process it in XTread_socket. */
9843 if (read_socket_inev
&& code
>= 0x20 && code
<= 0x7e)
9847 err
= GetEventParameter (kbd_event
, kEventParamKeyCode
,
9848 typeUInt32
, NULL
, sizeof (UInt32
),
9850 if (!(err
== noErr
&& key_code
<= 0x7f
9851 && keycode_to_xkeysym_table
[key_code
]))
9854 mac_focus_frame (&one_mac_display_info
);
9856 read_socket_inev
->kind
= ASCII_KEYSTROKE_EVENT
;
9857 read_socket_inev
->code
= code
;
9858 read_socket_inev
->modifiers
=
9859 mac_to_emacs_modifiers (modifiers
);
9860 read_socket_inev
->modifiers
|=
9861 (extra_keyboard_modifiers
9862 & (meta_modifier
| alt_modifier
9863 | hyper_modifier
| super_modifier
));
9864 XSETFRAME (read_socket_inev
->frame_or_window
, f
);
9867 return eventNotHandledErr
;
9871 /* Non-ASCII keystrokes without mapped modifiers are processed
9872 at the Lisp level. */
9873 id_key
= Qunicode_for_key_event
;
9874 num_params
= sizeof (names_ufke
) / sizeof (names_ufke
[0]);
9879 case kEventTextInputOffsetToPos
:
9885 if (!OVERLAYP (Vmac_ts_active_input_overlay
))
9886 return eventNotHandledErr
;
9888 /* Strictly speaking, this is not always correct because
9889 previous events may change some states about display. */
9890 if (NILP (Foverlay_get (Vmac_ts_active_input_overlay
, Qbefore_string
)))
9892 /* Active input area is displayed in the echo area. */
9893 w
= XWINDOW (echo_area_window
);
9894 f
= WINDOW_XFRAME (w
);
9898 /* Active input area is displayed around the current point. */
9899 f
= SELECTED_FRAME ();
9900 w
= XWINDOW (f
->selected_window
);
9903 p
.h
= (WINDOW_TO_FRAME_PIXEL_X (w
, w
->cursor
.x
)
9904 + WINDOW_LEFT_FRINGE_WIDTH (w
));
9905 p
.v
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->cursor
.y
)
9906 + FONT_BASE (FRAME_FONT (f
)));
9907 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
9909 err
= SetEventParameter (event
, kEventParamTextInputReplyPoint
,
9910 typeQDPoint
, sizeof (typeQDPoint
), &p
);
9919 err
= mac_store_event_ref_as_apple_event (0, 0, Qtext_input
, id_key
,
9923 return err
== noErr
? noErr
: result
;
9929 mac_store_service_event (event
)
9935 EventParamName
*names
;
9936 EventParamType
*types
;
9937 static EventParamName names_pfm
[] = {kEventParamServiceMessageName
,
9938 kEventParamServiceUserData
};
9939 static EventParamType types_pfm
[] = {typeCFStringRef
,
9942 switch (GetEventKind (event
))
9944 case kEventServicePaste
:
9951 case kEventServicePerform
:
9953 num_params
= sizeof (names_pfm
) / sizeof (names_pfm
[0]);
9962 err
= mac_store_event_ref_as_apple_event (0, 0, Qservice
, id_key
,
9968 #endif /* MAC_OSX */
9969 #endif /* USE_CARBON_EVENTS */
9973 install_window_handler (window
)
9976 OSStatus err
= noErr
;
9977 #if USE_CARBON_EVENTS
9978 EventTypeSpec specs_window
[] =
9979 {{kEventClassWindow
, kEventWindowUpdate
},
9980 {kEventClassWindow
, kEventWindowGetIdealSize
},
9981 {kEventClassWindow
, kEventWindowBoundsChanging
},
9982 {kEventClassWindow
, kEventWindowBoundsChanged
},
9983 {kEventClassWindow
, kEventWindowShown
},
9984 {kEventClassWindow
, kEventWindowHidden
},
9985 {kEventClassWindow
, kEventWindowExpanded
},
9986 {kEventClassWindow
, kEventWindowCollapsed
},
9987 {kEventClassWindow
, kEventWindowClose
},
9989 {kEventClassWindow
, kEventWindowToolbarSwitchMode
},
9992 {kEventClassWindow
, kEventWindowFocusAcquired
},
9993 {kEventClassWindow
, kEventWindowFocusRelinquish
},
9996 EventTypeSpec specs_mouse
[] = {{kEventClassMouse
, kEventMouseWheelMoved
}};
9997 static EventHandlerUPP handle_window_eventUPP
= NULL
;
9998 static EventHandlerUPP handle_mouse_eventUPP
= NULL
;
9999 #if USE_MAC_FONT_PANEL
10000 EventTypeSpec specs_font
[] = {{kEventClassFont
, kEventFontPanelClosed
},
10001 {kEventClassFont
, kEventFontSelection
}};
10002 static EventHandlerUPP handle_font_eventUPP
= NULL
;
10005 EventTypeSpec specs_text_input
[] =
10006 {{kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
},
10007 {kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
},
10008 {kEventClassTextInput
, kEventTextInputOffsetToPos
}};
10009 static EventHandlerUPP handle_text_input_eventUPP
= NULL
;
10012 if (handle_window_eventUPP
== NULL
)
10013 handle_window_eventUPP
= NewEventHandlerUPP (mac_handle_window_event
);
10014 if (handle_mouse_eventUPP
== NULL
)
10015 handle_mouse_eventUPP
= NewEventHandlerUPP (mac_handle_mouse_event
);
10016 #if USE_MAC_FONT_PANEL
10017 if (handle_font_eventUPP
== NULL
)
10018 handle_font_eventUPP
= NewEventHandlerUPP (mac_handle_font_event
);
10021 if (handle_text_input_eventUPP
== NULL
)
10022 handle_text_input_eventUPP
=
10023 NewEventHandlerUPP (mac_handle_text_input_event
);
10025 err
= InstallWindowEventHandler (window
, handle_window_eventUPP
,
10026 GetEventTypeCount (specs_window
),
10027 specs_window
, NULL
, NULL
);
10029 err
= InstallWindowEventHandler (window
, handle_mouse_eventUPP
,
10030 GetEventTypeCount (specs_mouse
),
10031 specs_mouse
, NULL
, NULL
);
10032 #if USE_MAC_FONT_PANEL
10034 err
= InstallWindowEventHandler (window
, handle_font_eventUPP
,
10035 GetEventTypeCount (specs_font
),
10036 specs_font
, NULL
, NULL
);
10040 err
= InstallWindowEventHandler (window
, handle_text_input_eventUPP
,
10041 GetEventTypeCount (specs_text_input
),
10042 specs_text_input
, window
, NULL
);
10046 err
= install_drag_handler (window
);
10052 remove_window_handler (window
)
10055 remove_drag_handler (window
);
10061 profiler_exit_proc ()
10063 ProfilerDump ("\pEmacs.prof");
10068 /* These few functions implement Emacs as a normal Mac application
10069 (almost): set up the heap and the Toolbox, handle necessary system
10070 events plus a few simple menu events. They also set up Emacs's
10071 access to functions defined in the rest of this file. Emacs uses
10072 function hooks to perform all its terminal I/O. A complete list of
10073 these functions appear in termhooks.h. For what they do, read the
10074 comments there and see also w32term.c and xterm.c. What's
10075 noticeably missing here is the event loop, which is normally
10076 present in most Mac application. After performing the necessary
10077 Mac initializations, main passes off control to emacs_main
10078 (corresponding to main in emacs.c). Emacs_main calls XTread_socket
10079 (defined further below) to read input. This is where
10080 WaitNextEvent/ReceiveNextEvent is called to process Mac events. */
10087 #if __profile__ /* is the profiler on? */
10088 if (ProfilerInit(collectDetailed
, bestTimeBase
, 5000, 200))
10093 /* set creator and type for files created by MSL */
10094 _fcreator
= 'EMAx';
10098 do_init_managers ();
10102 #ifndef USE_LSB_TAG
10103 do_check_ram_size ();
10106 init_emacs_passwd_dir ();
10110 init_coercion_handler ();
10112 initialize_applescript ();
10114 init_apple_event_handler ();
10120 /* set up argv array from STR# resource */
10121 get_string_list (&argv
, ARGV_STRING_LIST_ID
);
10125 /* free up AppleScript resources on exit */
10126 atexit (terminate_applescript
);
10128 #if __profile__ /* is the profiler on? */
10129 atexit (profiler_exit_proc
);
10132 /* 3rd param "envp" never used in emacs_main */
10133 (void) emacs_main (argc
, argv
, 0);
10136 /* Never reached - real exit in Fkill_emacs */
10141 #if !USE_CARBON_EVENTS
10142 static RgnHandle mouse_region
= NULL
;
10145 mac_wait_next_event (er
, sleep_time
, dequeue
)
10150 static EventRecord er_buf
= {nullEvent
};
10151 UInt32 target_tick
, current_tick
;
10152 EventMask event_mask
;
10154 if (mouse_region
== NULL
)
10155 mouse_region
= NewRgn ();
10157 event_mask
= everyEvent
;
10158 if (!mac_ready_for_apple_events
)
10159 event_mask
-= highLevelEventMask
;
10161 current_tick
= TickCount ();
10162 target_tick
= current_tick
+ sleep_time
;
10164 if (er_buf
.what
== nullEvent
)
10165 while (!WaitNextEvent (event_mask
, &er_buf
,
10166 target_tick
- current_tick
, mouse_region
))
10168 current_tick
= TickCount ();
10169 if (target_tick
<= current_tick
)
10175 er_buf
.what
= nullEvent
;
10178 #endif /* not USE_CARBON_EVENTS */
10180 #if TARGET_API_MAC_CARBON
10182 mac_post_mouse_moved_event ()
10184 EventRef event
= NULL
;
10187 err
= CreateEvent (NULL
, kEventClassMouse
, kEventMouseMoved
, 0,
10188 kEventAttributeNone
, &event
);
10193 GetMouse (&mouse_pos
);
10194 LocalToGlobal (&mouse_pos
);
10195 err
= SetEventParameter (event
, kEventParamMouseLocation
, typeQDPoint
,
10196 sizeof (Point
), &mouse_pos
);
10200 UInt32 modifiers
= GetCurrentKeyModifiers ();
10202 err
= SetEventParameter (event
, kEventParamKeyModifiers
, typeUInt32
,
10203 sizeof (UInt32
), &modifiers
);
10206 err
= PostEventToQueue (GetCurrentEventQueue (), event
,
10207 kEventPriorityStandard
);
10209 ReleaseEvent (event
);
10215 mac_set_unicode_keystroke_event (code
, buf
)
10217 struct input_event
*buf
;
10219 int charset_id
, c1
, c2
;
10223 buf
->kind
= ASCII_KEYSTROKE_EVENT
;
10226 else if (code
< 0x100)
10229 charset_id
= CHARSET_8_BIT_CONTROL
;
10231 charset_id
= charset_latin_iso8859_1
;
10232 buf
->kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
10233 buf
->code
= MAKE_CHAR (charset_id
, code
, 0);
10238 charset_id
= charset_mule_unicode_0100_24ff
,
10240 else if (code
< 0x33FF)
10241 charset_id
= charset_mule_unicode_2500_33ff
,
10243 else if (code
>= 0xE000)
10244 charset_id
= charset_mule_unicode_e000_ffff
,
10246 c1
= (code
/ 96) + 32, c2
= (code
% 96) + 32;
10247 buf
->kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
10248 buf
->code
= MAKE_CHAR (charset_id
, c1
, c2
);
10253 /* Emacs calls this whenever it wants to read an input event from the
10256 XTread_socket (sd
, expected
, hold_quit
)
10258 struct input_event
*hold_quit
;
10260 struct input_event inev
;
10262 #if USE_CARBON_EVENTS
10264 EventTargetRef toolbox_dispatcher
;
10267 struct mac_display_info
*dpyinfo
= &one_mac_display_info
;
10269 if (interrupt_input_blocked
)
10271 interrupt_input_pending
= 1;
10275 interrupt_input_pending
= 0;
10278 /* So people can tell when we have read the available input. */
10279 input_signal_count
++;
10283 #if USE_CARBON_EVENTS
10284 toolbox_dispatcher
= GetEventDispatcherTarget ();
10288 mac_prepare_for_quickdraw (NULL
),
10290 !ReceiveNextEvent (0, NULL
, kEventDurationNoWait
,
10291 kEventRemoveFromQueue
, &eventRef
))
10292 #else /* !USE_CARBON_EVENTS */
10293 while (mac_wait_next_event (&er
, 0, true))
10294 #endif /* !USE_CARBON_EVENTS */
10298 unsigned long timestamp
;
10301 inev
.kind
= NO_EVENT
;
10304 #if USE_CARBON_EVENTS
10305 timestamp
= GetEventTime (eventRef
) / kEventDurationMillisecond
;
10307 timestamp
= er
.when
* (1000 / 60); /* ticks to milliseconds */
10310 #if USE_CARBON_EVENTS
10311 /* Handle new events */
10312 if (!mac_convert_event_ref (eventRef
, &er
))
10314 /* There used to be a handler for the kEventMouseWheelMoved
10315 event here. But as of Mac OS X 10.4, this kind of event
10316 is not directly posted to the main event queue by
10317 two-finger scrolling on the trackpad. Instead, some
10318 private event is posted and it is converted to a wheel
10319 event by the default handler for the application target.
10320 The converted one can be received by a Carbon event
10321 handler installed on a window target. */
10322 read_socket_inev
= &inev
;
10323 SendEventToEventTarget (eventRef
, toolbox_dispatcher
);
10324 read_socket_inev
= NULL
;
10327 #endif /* USE_CARBON_EVENTS */
10333 WindowPtr window_ptr
;
10334 ControlPartCode part_code
;
10335 int tool_bar_p
= 0;
10337 #if USE_CARBON_EVENTS
10338 /* This is needed to send mouse events like aqua window
10339 buttons to the correct handler. */
10340 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
10341 != eventNotHandledErr
)
10344 last_mouse_glyph_frame
= 0;
10346 if (dpyinfo
->grabbed
&& last_mouse_frame
10347 && FRAME_LIVE_P (last_mouse_frame
))
10349 window_ptr
= FRAME_MAC_WINDOW (last_mouse_frame
);
10350 part_code
= inContent
;
10354 part_code
= FindWindow (er
.where
, &window_ptr
);
10355 if (tip_window
&& window_ptr
== tip_window
)
10357 HideWindow (tip_window
);
10358 part_code
= FindWindow (er
.where
, &window_ptr
);
10362 if (er
.what
!= mouseDown
&&
10363 (part_code
!= inContent
|| dpyinfo
->grabbed
== 0))
10369 f
= mac_focus_frame (dpyinfo
);
10370 saved_menu_event_location
= er
.where
;
10371 inev
.kind
= MENU_BAR_ACTIVATE_EVENT
;
10372 XSETFRAME (inev
.frame_or_window
, f
);
10377 #if TARGET_API_MAC_CARBON
10378 FrontNonFloatingWindow ()
10383 SelectWindow (window_ptr
);
10386 ControlPartCode control_part_code
;
10388 Point mouse_loc
= er
.where
;
10390 ControlKind control_kind
;
10393 f
= mac_window_to_frame (window_ptr
);
10394 /* convert to local coordinates of new window */
10395 SetPortWindowPort (window_ptr
);
10397 GlobalToLocal (&mouse_loc
);
10398 #if TARGET_API_MAC_CARBON
10399 ch
= FindControlUnderMouse (mouse_loc
, window_ptr
,
10400 &control_part_code
);
10403 GetControlKind (ch
, &control_kind
);
10406 control_part_code
= FindControl (mouse_loc
, window_ptr
,
10410 #if USE_CARBON_EVENTS
10411 inev
.code
= mac_get_mouse_btn (eventRef
);
10412 inev
.modifiers
= mac_event_to_emacs_modifiers (eventRef
);
10414 inev
.code
= mac_get_emulated_btn (er
.modifiers
);
10415 inev
.modifiers
= mac_to_emacs_modifiers (er
.modifiers
);
10417 XSETINT (inev
.x
, mouse_loc
.h
);
10418 XSETINT (inev
.y
, mouse_loc
.v
);
10420 if ((dpyinfo
->grabbed
&& tracked_scroll_bar
)
10422 #ifndef USE_TOOLKIT_SCROLL_BARS
10423 /* control_part_code becomes kControlNoPart if
10424 a progress indicator is clicked. */
10425 && control_part_code
!= kControlNoPart
10426 #else /* USE_TOOLKIT_SCROLL_BARS */
10428 && control_kind
.kind
== kControlKindScrollBar
10429 #endif /* MAC_OSX */
10430 #endif /* USE_TOOLKIT_SCROLL_BARS */
10433 struct scroll_bar
*bar
;
10435 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
10437 bar
= tracked_scroll_bar
;
10438 #ifndef USE_TOOLKIT_SCROLL_BARS
10439 control_part_code
= kControlIndicatorPart
;
10443 bar
= (struct scroll_bar
*) GetControlReference (ch
);
10444 #ifdef USE_TOOLKIT_SCROLL_BARS
10445 /* Make the "Ctrl-Mouse-2 splits window" work
10446 for toolkit scroll bars. */
10447 if (er
.modifiers
& controlKey
)
10448 x_scroll_bar_handle_click (bar
, control_part_code
,
10450 else if (er
.what
== mouseDown
)
10451 x_scroll_bar_handle_press (bar
, control_part_code
,
10454 x_scroll_bar_handle_release (bar
, &inev
);
10455 #else /* not USE_TOOLKIT_SCROLL_BARS */
10456 x_scroll_bar_handle_click (bar
, control_part_code
,
10458 if (er
.what
== mouseDown
10459 && control_part_code
== kControlIndicatorPart
)
10460 tracked_scroll_bar
= bar
;
10462 tracked_scroll_bar
= NULL
;
10463 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10467 Lisp_Object window
;
10468 int x
= mouse_loc
.h
;
10469 int y
= mouse_loc
.v
;
10471 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
10472 if (EQ (window
, f
->tool_bar_window
))
10474 if (er
.what
== mouseDown
)
10475 handle_tool_bar_click (f
, x
, y
, 1, 0);
10477 handle_tool_bar_click (f
, x
, y
, 0,
10483 XSETFRAME (inev
.frame_or_window
, f
);
10484 inev
.kind
= MOUSE_CLICK_EVENT
;
10488 if (er
.what
== mouseDown
)
10490 dpyinfo
->grabbed
|= (1 << inev
.code
);
10491 last_mouse_frame
= f
;
10494 last_tool_bar_item
= -1;
10498 if ((dpyinfo
->grabbed
& (1 << inev
.code
)) == 0)
10499 /* If a button is released though it was not
10500 previously pressed, that would be because
10501 of multi-button emulation. */
10502 dpyinfo
->grabbed
= 0;
10504 dpyinfo
->grabbed
&= ~(1 << inev
.code
);
10507 /* Ignore any mouse motion that happened before
10508 this event; any subsequent mouse-movement Emacs
10509 events should reflect only motion after the
10512 f
->mouse_moved
= 0;
10514 #ifdef USE_TOOLKIT_SCROLL_BARS
10515 if (inev
.kind
== MOUSE_CLICK_EVENT
)
10520 inev
.modifiers
|= down_modifier
;
10523 inev
.modifiers
|= up_modifier
;
10530 #if TARGET_API_MAC_CARBON
10532 if (IsWindowPathSelectClick (window_ptr
, &er
))
10534 WindowPathSelect (window_ptr
, NULL
, NULL
);
10537 if (part_code
== inProxyIcon
10538 && (TrackWindowProxyDrag (window_ptr
, er
.where
)
10539 != errUserWantsToDragWindow
))
10541 DragWindow (window_ptr
, er
.where
, NULL
);
10542 #else /* not TARGET_API_MAC_CARBON */
10543 DragWindow (window_ptr
, er
.where
, &qd
.screenBits
.bounds
);
10544 #endif /* not TARGET_API_MAC_CARBON */
10545 /* Update the frame parameters. */
10546 #if !USE_CARBON_EVENTS
10548 struct frame
*f
= mac_window_to_frame (window_ptr
);
10550 if (f
&& !f
->async_iconified
)
10551 mac_handle_origin_change (f
);
10557 if (TrackGoAway (window_ptr
, er
.where
))
10559 inev
.kind
= DELETE_WINDOW_EVENT
;
10560 XSETFRAME (inev
.frame_or_window
,
10561 mac_window_to_frame (window_ptr
));
10565 /* window resize handling added --ben */
10567 do_grow_window (window_ptr
, &er
);
10570 /* window zoom handling added --ben */
10573 if (TrackBox (window_ptr
, er
.where
, part_code
))
10574 do_zoom_window (window_ptr
, part_code
);
10584 #if USE_CARBON_EVENTS
10585 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
10586 != eventNotHandledErr
)
10589 do_window_update ((WindowPtr
) er
.message
);
10594 #if USE_CARBON_EVENTS
10595 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
10596 != eventNotHandledErr
)
10599 switch ((er
.message
>> 24) & 0x000000FF)
10601 case suspendResumeMessage
:
10603 if (er
.message
& resumeFlag
)
10606 mac_tsm_suspend ();
10610 case mouseMovedMessage
:
10611 #if !USE_CARBON_EVENTS
10612 SetRectRgn (mouse_region
, er
.where
.h
, er
.where
.v
,
10613 er
.where
.h
+ 1, er
.where
.v
+ 1);
10615 previous_help_echo_string
= help_echo_string
;
10616 help_echo_string
= Qnil
;
10618 if (dpyinfo
->grabbed
&& last_mouse_frame
10619 && FRAME_LIVE_P (last_mouse_frame
))
10620 f
= last_mouse_frame
;
10622 f
= dpyinfo
->x_focus_frame
;
10624 if (dpyinfo
->mouse_face_hidden
)
10626 dpyinfo
->mouse_face_hidden
= 0;
10627 clear_mouse_face (dpyinfo
);
10632 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
10633 Point mouse_pos
= er
.where
;
10635 SetPortWindowPort (wp
);
10637 GlobalToLocal (&mouse_pos
);
10639 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
10640 #ifdef USE_TOOLKIT_SCROLL_BARS
10641 x_scroll_bar_handle_drag (wp
, tracked_scroll_bar
,
10643 #else /* not USE_TOOLKIT_SCROLL_BARS */
10644 x_scroll_bar_note_movement (tracked_scroll_bar
,
10646 - XINT (tracked_scroll_bar
->top
),
10647 er
.when
* (1000 / 60));
10648 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10651 /* Generate SELECT_WINDOW_EVENTs when needed. */
10652 if (!NILP (Vmouse_autoselect_window
))
10654 Lisp_Object window
;
10656 window
= window_from_coordinates (f
,
10661 /* Window will be selected only when it is
10662 not selected now and last mouse movement
10663 event was not in it. Minibuffer window
10664 will be selected iff it is active. */
10665 if (WINDOWP (window
)
10666 && !EQ (window
, last_window
)
10667 && !EQ (window
, selected_window
))
10669 inev
.kind
= SELECT_WINDOW_EVENT
;
10670 inev
.frame_or_window
= window
;
10673 last_window
=window
;
10675 if (!note_mouse_movement (f
, &mouse_pos
))
10676 help_echo_string
= previous_help_echo_string
;
10680 /* If the contents of the global variable
10681 help_echo_string has changed, generate a
10683 if (!NILP (help_echo_string
) || !NILP (previous_help_echo_string
))
10691 WindowPtr window_ptr
= (WindowPtr
) er
.message
;
10693 #if USE_CARBON_EVENTS
10694 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
10695 != eventNotHandledErr
)
10698 if (window_ptr
== tip_window
)
10700 HideWindow (tip_window
);
10704 if (!is_emacs_window (window_ptr
))
10707 if ((er
.modifiers
& activeFlag
) != 0)
10709 /* A window has been activated */
10710 Point mouse_loc
= er
.where
;
10712 x_detect_focus_change (dpyinfo
, &er
, &inev
);
10714 SetPortWindowPort (window_ptr
);
10715 GlobalToLocal (&mouse_loc
);
10716 /* Window-activated event counts as mouse movement,
10717 so update things that depend on mouse position. */
10718 note_mouse_movement (mac_window_to_frame (window_ptr
),
10723 /* A window has been deactivated */
10724 #if USE_TOOLKIT_SCROLL_BARS
10725 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
10727 struct input_event event
;
10729 EVENT_INIT (event
);
10730 event
.kind
= NO_EVENT
;
10731 x_scroll_bar_handle_release (tracked_scroll_bar
, &event
);
10732 if (event
.kind
!= NO_EVENT
)
10734 event
.timestamp
= timestamp
;
10735 kbd_buffer_store_event_hold (&event
, hold_quit
);
10740 dpyinfo
->grabbed
= 0;
10742 x_detect_focus_change (dpyinfo
, &er
, &inev
);
10744 f
= mac_window_to_frame (window_ptr
);
10745 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10747 /* If we move outside the frame, then we're
10748 certainly no longer on any text in the
10750 clear_mouse_face (dpyinfo
);
10751 dpyinfo
->mouse_face_mouse_frame
= 0;
10754 /* Generate a nil HELP_EVENT to cancel a help-echo.
10755 Do it only if there's something to cancel.
10756 Otherwise, the startup message is cleared when the
10757 mouse leaves the frame. */
10758 if (any_help_event_p
)
10768 int keycode
= (er
.message
& keyCodeMask
) >> 8;
10769 static SInt16 last_key_script
= -1;
10770 SInt16 current_key_script
;
10771 UInt32 modifiers
= er
.modifiers
, mapped_modifiers
;
10774 (NILP (Vmac_control_modifier
) ? 0 : controlKey
)
10775 | (NILP (Vmac_option_modifier
) ? 0 : optionKey
)
10776 | (NILP (Vmac_command_modifier
) ? 0 : cmdKey
);
10778 #if USE_CARBON_EVENTS && defined (MAC_OSX)
10779 mapped_modifiers
|=
10780 (NILP (Vmac_function_modifier
) ? 0 : kEventKeyModifierFnMask
);
10782 GetEventParameter (eventRef
, kEventParamKeyModifiers
,
10784 sizeof (UInt32
), NULL
, &modifiers
);
10786 mapped_modifiers
&= modifiers
;
10788 #if USE_CARBON_EVENTS && (defined (MAC_OSX) || USE_MAC_TSM)
10789 /* When using Carbon Events, we need to pass raw keyboard
10790 events to the TSM ourselves. If TSM handles it, it
10791 will pass back noErr, otherwise it will pass back
10792 "eventNotHandledErr" and we can process it
10794 if (!(mapped_modifiers
10795 & ~(mac_pass_command_to_system
? cmdKey
: 0)
10796 & ~(mac_pass_control_to_system
? controlKey
: 0)))
10800 read_socket_inev
= &inev
;
10801 err
= SendEventToEventTarget (eventRef
, toolbox_dispatcher
);
10802 read_socket_inev
= NULL
;
10803 if (err
!= eventNotHandledErr
)
10807 if (er
.what
== keyUp
)
10812 f
= mac_focus_frame (dpyinfo
);
10814 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
10815 && !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
))
10817 clear_mouse_face (dpyinfo
);
10818 dpyinfo
->mouse_face_hidden
= 1;
10821 current_key_script
= GetScriptManagerVariable (smKeyScript
);
10822 if (last_key_script
!= current_key_script
)
10824 struct input_event event
;
10826 EVENT_INIT (event
);
10827 event
.kind
= LANGUAGE_CHANGE_EVENT
;
10829 event
.code
= current_key_script
;
10830 event
.timestamp
= timestamp
;
10831 kbd_buffer_store_event (&event
);
10833 last_key_script
= current_key_script
;
10837 if (inev
.kind
!= NO_EVENT
)
10842 if (mapped_modifiers
& kEventKeyModifierFnMask
10844 && fn_keycode_to_keycode_table
[keycode
])
10845 keycode
= fn_keycode_to_keycode_table
[keycode
];
10847 if (keycode
<= 0x7f && keycode_to_xkeysym_table
[keycode
])
10849 inev
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
10850 inev
.code
= 0xff00 | keycode_to_xkeysym_table
[keycode
];
10852 if (modifiers
& kEventKeyModifierFnMask
10854 && fn_keycode_to_keycode_table
[keycode
] == keycode
)
10855 modifiers
&= ~kEventKeyModifierFnMask
;
10858 else if (mapped_modifiers
)
10860 /* translate the keycode back to determine the
10863 static SInt16 last_key_layout_id
= 0;
10864 static Handle uchr_handle
= (Handle
)-1;
10865 SInt16 current_key_layout_id
=
10866 GetScriptVariable (current_key_script
, smScriptKeys
);
10868 if (uchr_handle
== (Handle
)-1
10869 || last_key_layout_id
!= current_key_layout_id
)
10871 uchr_handle
= GetResource ('uchr', current_key_layout_id
);
10872 last_key_layout_id
= current_key_layout_id
;
10878 UInt16 key_action
= er
.what
- keyDown
;
10879 UInt32 modifier_key_state
=
10880 (modifiers
& ~mapped_modifiers
) >> 8;
10881 UInt32 keyboard_type
= LMGetKbdType ();
10882 SInt32 dead_key_state
= 0;
10884 UniCharCount actual_length
;
10886 status
= UCKeyTranslate ((UCKeyboardLayout
*)*uchr_handle
,
10887 keycode
, key_action
,
10888 modifier_key_state
,
10890 kUCKeyTranslateNoDeadKeysMask
,
10892 1, &actual_length
, &code
);
10893 if (status
== noErr
&& actual_length
== 1)
10894 mac_set_unicode_keystroke_event (code
, &inev
);
10896 #endif /* MAC_OSX */
10898 if (inev
.kind
== NO_EVENT
)
10900 /* This code comes from Keyboard Resource,
10901 Appendix C of IM - Text. This is necessary
10902 since shift is ignored in KCHR table
10903 translation when option or command is pressed.
10904 It also does not translate correctly
10905 control-shift chars like C-% so mask off shift
10907 /* Mask off modifier keys that are mapped to some
10908 Emacs modifiers. */
10909 int new_modifiers
= er
.modifiers
& ~mapped_modifiers
;
10910 /* set high byte of keycode to modifier high byte*/
10911 int new_keycode
= keycode
| new_modifiers
;
10912 Ptr kchr_ptr
= (Ptr
) GetScriptManagerVariable (smKCHRCache
);
10913 unsigned long some_state
= 0;
10914 UInt32 new_char_code
;
10916 new_char_code
= KeyTranslate (kchr_ptr
, new_keycode
,
10918 if (new_char_code
== 0)
10919 /* Seems like a dead key. Append up-stroke. */
10920 new_char_code
= KeyTranslate (kchr_ptr
,
10921 new_keycode
| 0x80,
10925 inev
.kind
= ASCII_KEYSTROKE_EVENT
;
10926 inev
.code
= new_char_code
& 0xff;
10931 if (inev
.kind
== NO_EVENT
)
10933 inev
.kind
= ASCII_KEYSTROKE_EVENT
;
10934 inev
.code
= er
.message
& charCodeMask
;
10937 inev
.modifiers
= mac_to_emacs_modifiers (modifiers
);
10938 inev
.modifiers
|= (extra_keyboard_modifiers
10939 & (meta_modifier
| alt_modifier
10940 | hyper_modifier
| super_modifier
));
10941 XSETFRAME (inev
.frame_or_window
, f
);
10943 #if TARGET_API_MAC_CARBON
10944 if (inev
.kind
== ASCII_KEYSTROKE_EVENT
10945 && inev
.code
>= 0x80 && inev
.modifiers
)
10948 TextEncoding encoding
= kTextEncodingMacRoman
;
10949 TextToUnicodeInfo ttu_info
;
10951 UpgradeScriptInfoToTextEncoding (current_key_script
,
10952 kTextLanguageDontCare
,
10953 kTextRegionDontCare
,
10955 err
= CreateTextToUnicodeInfoByEncoding (encoding
, &ttu_info
);
10960 ByteCount unicode_len
;
10963 pstr
[1] = inev
.code
;
10964 err
= ConvertFromPStringToUnicode (ttu_info
, pstr
,
10966 &unicode_len
, &code
);
10967 if (err
== noErr
&& unicode_len
== sizeof (UniChar
))
10968 mac_set_unicode_keystroke_event (code
, &inev
);
10969 DisposeTextToUnicodeInfo (&ttu_info
);
10976 case kHighLevelEvent
:
10977 AEProcessAppleEvent (&er
);
10983 #if USE_CARBON_EVENTS
10984 ReleaseEvent (eventRef
);
10987 if (inev
.kind
!= NO_EVENT
)
10989 inev
.timestamp
= timestamp
;
10990 kbd_buffer_store_event_hold (&inev
, hold_quit
);
10995 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
11000 XSETFRAME (frame
, f
);
11006 any_help_event_p
= 1;
11007 gen_help_event (help_echo_string
, frame
, help_echo_window
,
11008 help_echo_object
, help_echo_pos
);
11012 help_echo_string
= Qnil
;
11013 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
11020 /* If the focus was just given to an autoraising frame,
11022 /* ??? This ought to be able to handle more than one such frame. */
11023 if (pending_autoraise_frame
)
11025 x_raise_frame (pending_autoraise_frame
);
11026 pending_autoraise_frame
= 0;
11029 #if !USE_CARBON_EVENTS
11030 /* Check which frames are still visible. We do this here because
11031 there doesn't seem to be any direct notification from the Window
11032 Manager that the visibility of a window has changed (at least,
11033 not in all cases). */
11035 Lisp_Object tail
, frame
;
11037 FOR_EACH_FRAME (tail
, frame
)
11039 struct frame
*f
= XFRAME (frame
);
11041 /* The tooltip has been drawn already. Avoid the
11042 SET_FRAME_GARBAGED in mac_handle_visibility_change. */
11043 if (EQ (frame
, tip_frame
))
11046 if (FRAME_MAC_P (f
))
11047 mac_handle_visibility_change (f
);
11058 /* Need to override CodeWarrior's input function so no conversion is
11059 done on newlines Otherwise compiled functions in .elc files will be
11060 read incorrectly. Defined in ...:MSL C:MSL
11061 Common:Source:buffer_io.c. */
11064 __convert_to_newlines (unsigned char * p
, size_t * n
)
11066 #pragma unused(p,n)
11070 __convert_from_newlines (unsigned char * p
, size_t * n
)
11072 #pragma unused(p,n)
11078 make_mac_terminal_frame (struct frame
*f
)
11083 XSETFRAME (frame
, f
);
11085 f
->output_method
= output_mac
;
11086 f
->output_data
.mac
= (struct mac_output
*)
11087 xmalloc (sizeof (struct mac_output
));
11088 bzero (f
->output_data
.mac
, sizeof (struct mac_output
));
11090 XSETFRAME (FRAME_KBOARD (f
)->Vdefault_minibuffer_frame
, f
);
11092 FRAME_COLS (f
) = 96;
11093 FRAME_LINES (f
) = 4;
11095 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
11096 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_right
;
11098 FRAME_DESIRED_CURSOR (f
) = FILLED_BOX_CURSOR
;
11100 f
->output_data
.mac
->cursor_pixel
= 0;
11101 f
->output_data
.mac
->border_pixel
= 0x00ff00;
11102 f
->output_data
.mac
->mouse_pixel
= 0xff00ff;
11103 f
->output_data
.mac
->cursor_foreground_pixel
= 0x0000ff;
11105 f
->output_data
.mac
->text_cursor
= kThemeIBeamCursor
;
11106 f
->output_data
.mac
->nontext_cursor
= kThemeArrowCursor
;
11107 f
->output_data
.mac
->modeline_cursor
= kThemeArrowCursor
;
11108 f
->output_data
.mac
->hand_cursor
= kThemePointingHandCursor
;
11109 f
->output_data
.mac
->hourglass_cursor
= kThemeWatchCursor
;
11110 f
->output_data
.mac
->horizontal_drag_cursor
= kThemeResizeLeftRightCursor
;
11112 FRAME_FONTSET (f
) = -1;
11113 f
->output_data
.mac
->explicit_parent
= 0;
11116 f
->border_width
= 0;
11118 f
->internal_border_width
= 0;
11123 f
->new_text_cols
= 0;
11124 f
->new_text_lines
= 0;
11126 SetRect (&r
, f
->left_pos
, f
->top_pos
,
11127 f
->left_pos
+ FRAME_PIXEL_WIDTH (f
),
11128 f
->top_pos
+ FRAME_PIXEL_HEIGHT (f
));
11132 if (!(FRAME_MAC_WINDOW (f
) =
11133 NewCWindow (NULL
, &r
, "\p", true, dBoxProc
,
11134 (WindowPtr
) -1, 1, (long) f
->output_data
.mac
)))
11136 /* so that update events can find this mac_output struct */
11137 f
->output_data
.mac
->mFP
= f
; /* point back to emacs frame */
11143 /* Need to be initialized for unshow_buffer in window.c. */
11144 selected_window
= f
->selected_window
;
11146 Fmodify_frame_parameters (frame
,
11147 Fcons (Fcons (Qfont
,
11148 build_string ("-*-monaco-medium-r-*--*-90-*-*-*-*-mac-roman")), Qnil
));
11149 Fmodify_frame_parameters (frame
,
11150 Fcons (Fcons (Qforeground_color
,
11151 build_string ("black")), Qnil
));
11152 Fmodify_frame_parameters (frame
,
11153 Fcons (Fcons (Qbackground_color
,
11154 build_string ("white")), Qnil
));
11159 /***********************************************************************
11161 ***********************************************************************/
11163 int mac_initialized
= 0;
11166 mac_initialize_display_info ()
11168 struct mac_display_info
*dpyinfo
= &one_mac_display_info
;
11170 bzero (dpyinfo
, sizeof (*dpyinfo
));
11173 dpyinfo
->mac_id_name
11174 = (char *) xmalloc (SCHARS (Vinvocation_name
)
11175 + SCHARS (Vsystem_name
)
11177 sprintf (dpyinfo
->mac_id_name
, "%s@%s",
11178 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
11180 dpyinfo
->mac_id_name
= (char *) xmalloc (strlen ("Mac Display") + 1);
11181 strcpy (dpyinfo
->mac_id_name
, "Mac Display");
11184 dpyinfo
->reference_count
= 0;
11185 dpyinfo
->resx
= 72.0;
11186 dpyinfo
->resy
= 72.0;
11188 /* HasDepth returns true if it is possible to have a 32 bit display,
11189 but this may not be what is actually used. Mac OSX can do better. */
11190 dpyinfo
->color_p
= CGDisplaySamplesPerPixel (kCGDirectMainDisplay
) > 1;
11191 dpyinfo
->n_planes
= CGDisplayBitsPerPixel (kCGDirectMainDisplay
);
11192 dpyinfo
->height
= CGDisplayPixelsHigh (kCGDirectMainDisplay
);
11193 dpyinfo
->width
= CGDisplayPixelsWide (kCGDirectMainDisplay
);
11196 GDHandle main_device_handle
= LMGetMainDevice();
11198 dpyinfo
->color_p
= TestDeviceAttribute (main_device_handle
, gdDevType
);
11199 for (dpyinfo
->n_planes
= 32; dpyinfo
->n_planes
> 0; dpyinfo
->n_planes
>>= 1)
11200 if (HasDepth (main_device_handle
, dpyinfo
->n_planes
,
11201 gdDevType
, dpyinfo
->color_p
))
11203 dpyinfo
->height
= (**main_device_handle
).gdRect
.bottom
;
11204 dpyinfo
->width
= (**main_device_handle
).gdRect
.right
;
11207 dpyinfo
->grabbed
= 0;
11208 dpyinfo
->root_window
= NULL
;
11209 dpyinfo
->image_cache
= make_image_cache ();
11211 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
11212 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
11213 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
11214 dpyinfo
->mouse_face_window
= Qnil
;
11215 dpyinfo
->mouse_face_overlay
= Qnil
;
11216 dpyinfo
->mouse_face_hidden
= 0;
11221 mac_make_rdb (xrm_option
)
11224 XrmDatabase database
;
11226 database
= xrm_get_preference_database (NULL
);
11228 xrm_merge_string_database (database
, xrm_option
);
11233 struct mac_display_info
*
11234 mac_term_init (display_name
, xrm_option
, resource_name
)
11235 Lisp_Object display_name
;
11237 char *resource_name
;
11239 struct mac_display_info
*dpyinfo
;
11243 if (!mac_initialized
)
11246 mac_initialized
= 1;
11249 if (x_display_list
)
11250 error ("Sorry, this version can only handle one display");
11252 mac_initialize_display_info ();
11254 dpyinfo
= &one_mac_display_info
;
11256 dpyinfo
->xrdb
= mac_make_rdb (xrm_option
);
11258 /* Put this display on the chain. */
11259 dpyinfo
->next
= x_display_list
;
11260 x_display_list
= dpyinfo
;
11262 /* Put it on x_display_name_list. */
11263 x_display_name_list
= Fcons (Fcons (display_name
,
11264 Fcons (Qnil
, dpyinfo
->xrdb
)),
11265 x_display_name_list
);
11266 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
11272 /* Get rid of display DPYINFO, assuming all frames are already gone. */
11275 x_delete_display (dpyinfo
)
11276 struct mac_display_info
*dpyinfo
;
11280 /* Discard this display from x_display_name_list and x_display_list.
11281 We can't use Fdelq because that can quit. */
11282 if (! NILP (x_display_name_list
)
11283 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
11284 x_display_name_list
= XCDR (x_display_name_list
);
11289 tail
= x_display_name_list
;
11290 while (CONSP (tail
) && CONSP (XCDR (tail
)))
11292 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
11294 XSETCDR (tail
, XCDR (XCDR (tail
)));
11297 tail
= XCDR (tail
);
11301 if (x_display_list
== dpyinfo
)
11302 x_display_list
= dpyinfo
->next
;
11305 struct x_display_info
*tail
;
11307 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
11308 if (tail
->next
== dpyinfo
)
11309 tail
->next
= tail
->next
->next
;
11312 /* Free the font names in the font table. */
11313 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11314 if (dpyinfo
->font_table
[i
].name
)
11316 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
11317 xfree (dpyinfo
->font_table
[i
].full_name
);
11318 xfree (dpyinfo
->font_table
[i
].name
);
11321 if (dpyinfo
->font_table
)
11323 if (dpyinfo
->font_table
->font_encoder
)
11324 xfree (dpyinfo
->font_table
->font_encoder
);
11325 xfree (dpyinfo
->font_table
);
11327 if (dpyinfo
->mac_id_name
)
11328 xfree (dpyinfo
->mac_id_name
);
11330 if (x_display_list
== 0)
11332 mac_clear_font_name_table ();
11333 bzero (dpyinfo
, sizeof (*dpyinfo
));
11342 extern int inhibit_window_system
;
11343 extern int noninteractive
;
11344 CFBundleRef appsBundle
;
11346 /* No need to test if already -nw*/
11347 if (inhibit_window_system
|| noninteractive
)
11350 appsBundle
= CFBundleGetMainBundle();
11351 if (appsBundle
!= NULL
)
11353 CFStringRef cfBI
= CFSTR("CFBundleIdentifier");
11354 CFTypeRef res
= CFBundleGetValueForInfoDictionaryKey(appsBundle
, cfBI
);
11355 /* We found the bundle identifier, now we know we are valid. */
11362 /* MAC_TODO: Have this start the bundled executable */
11364 /* For now, prevent the fatal error by bringing it up in the terminal */
11365 inhibit_window_system
= 1;
11369 MakeMeTheFrontProcess ()
11371 ProcessSerialNumber psn
;
11374 err
= GetCurrentProcess (&psn
);
11376 (void) SetFrontProcess (&psn
);
11379 /***** Code to handle C-g testing *****/
11381 /* Contains the Mac modifier formed from quit_char */
11382 int mac_quit_char_modifiers
= 0;
11383 int mac_quit_char_keycode
;
11384 extern int quit_char
;
11387 mac_determine_quit_char_modifiers()
11389 /* Todo: Determine modifiers from quit_char. */
11390 UInt32 qc_modifiers
= ctrl_modifier
;
11392 /* Map modifiers */
11393 mac_quit_char_modifiers
= 0;
11394 if (qc_modifiers
& ctrl_modifier
) mac_quit_char_modifiers
|= controlKey
;
11395 if (qc_modifiers
& shift_modifier
) mac_quit_char_modifiers
|= shiftKey
;
11396 if (qc_modifiers
& alt_modifier
) mac_quit_char_modifiers
|= optionKey
;
11400 init_quit_char_handler ()
11402 /* TODO: Let this support keys other the 'g' */
11403 mac_quit_char_keycode
= 5;
11404 /* Look at <architecture/adb_kb_map.h> for details */
11405 /* http://gemma.apple.com/techpubs/mac/Toolbox/Toolbox-40.html#MARKER-9-184*/
11407 mac_determine_quit_char_modifiers();
11409 #endif /* MAC_OSX */
11417 MenuItemIndex menu_index
;
11419 err
= GetIndMenuItemWithCommandID (NULL
, kHICommandQuit
, 1,
11420 &menu
, &menu_index
);
11422 SetMenuItemCommandKey (menu
, menu_index
, false, 0);
11423 #if USE_CARBON_EVENTS
11424 EnableMenuCommand (NULL
, kHICommandPreferences
);
11425 err
= GetIndMenuItemWithCommandID (NULL
, kHICommandPreferences
, 1,
11426 &menu
, &menu_index
);
11429 SetMenuItemCommandKey (menu
, menu_index
, false, 0);
11430 InsertMenuItemTextWithCFString (menu
, NULL
,
11431 0, kMenuItemAttrSeparator
, 0);
11432 InsertMenuItemTextWithCFString (menu
, CFSTR ("About Emacs"),
11433 0, 0, kHICommandAbout
);
11435 #endif /* USE_CARBON_EVENTS */
11436 #else /* !MAC_OSX */
11437 #if USE_CARBON_EVENTS
11438 SetMenuItemCommandID (GetMenuHandle (M_APPLE
), I_ABOUT
, kHICommandAbout
);
11448 static InterfaceTypeList types
= {kUnicodeDocument
};
11450 static InterfaceTypeList types
= {kTextService
};
11453 NewTSMDocument (sizeof (types
) / sizeof (types
[0]), types
,
11454 &tsm_document_id
, 0);
11458 /* Set up use of X before we make the first connection. */
11460 extern frame_parm_handler mac_frame_parm_handlers
[];
11462 static struct redisplay_interface x_redisplay_interface
=
11464 mac_frame_parm_handlers
,
11468 x_clear_end_of_line
,
11470 x_after_update_window_line
,
11471 x_update_window_begin
,
11472 x_update_window_end
,
11475 0, /* flush_display_optional */
11476 x_clear_window_mouse_face
,
11477 x_get_glyph_overhangs
,
11478 x_fix_overlapping_area
,
11479 x_draw_fringe_bitmap
,
11481 mac_define_fringe_bitmap
,
11482 mac_destroy_fringe_bitmap
,
11484 0, /* define_fringe_bitmap */
11485 0, /* destroy_fringe_bitmap */
11487 mac_per_char_metric
,
11489 mac_compute_glyph_string_overhangs
,
11490 x_draw_glyph_string
,
11491 mac_define_frame_cursor
,
11492 mac_clear_frame_area
,
11493 mac_draw_window_cursor
,
11494 mac_draw_vertical_window_border
,
11495 mac_shift_glyphs_for_insert
11501 rif
= &x_redisplay_interface
;
11503 clear_frame_hook
= x_clear_frame
;
11504 ins_del_lines_hook
= x_ins_del_lines
;
11505 delete_glyphs_hook
= x_delete_glyphs
;
11506 ring_bell_hook
= XTring_bell
;
11507 reset_terminal_modes_hook
= XTreset_terminal_modes
;
11508 set_terminal_modes_hook
= XTset_terminal_modes
;
11509 update_begin_hook
= x_update_begin
;
11510 update_end_hook
= x_update_end
;
11511 set_terminal_window_hook
= XTset_terminal_window
;
11512 read_socket_hook
= XTread_socket
;
11513 frame_up_to_date_hook
= XTframe_up_to_date
;
11514 mouse_position_hook
= XTmouse_position
;
11515 frame_rehighlight_hook
= XTframe_rehighlight
;
11516 frame_raise_lower_hook
= XTframe_raise_lower
;
11518 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
11519 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
11520 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
11521 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
11523 scroll_region_ok
= 1; /* we'll scroll partial frames */
11524 char_ins_del_ok
= 1;
11525 line_ins_del_ok
= 1; /* we'll just blt 'em */
11526 fast_clear_end_of_line
= 1; /* X does this well */
11527 memory_below_frame
= 0; /* we don't remember what scrolls
11531 last_tool_bar_item
= -1;
11532 any_help_event_p
= 0;
11534 /* Try to use interrupt input; if we can't, then start polling. */
11535 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
11539 #if TARGET_API_MAC_CARBON
11541 #if USE_CARBON_EVENTS
11543 init_service_handler ();
11545 init_quit_char_handler ();
11546 #endif /* MAC_OSX */
11548 init_command_handler ();
11555 #endif /* USE_CARBON_EVENTS */
11558 init_coercion_handler ();
11560 init_apple_event_handler ();
11562 if (!inhibit_window_system
)
11563 MakeMeTheFrontProcess ();
11568 mac_init_fringe ();
11579 staticpro (&x_error_message_string
);
11580 x_error_message_string
= Qnil
;
11583 Qcontrol
= intern ("control"); staticpro (&Qcontrol
);
11584 Qmeta
= intern ("meta"); staticpro (&Qmeta
);
11585 Qalt
= intern ("alt"); staticpro (&Qalt
);
11586 Qhyper
= intern ("hyper"); staticpro (&Qhyper
);
11587 Qsuper
= intern ("super"); staticpro (&Qsuper
);
11588 Qmodifier_value
= intern ("modifier-value");
11589 staticpro (&Qmodifier_value
);
11591 Fput (Qcontrol
, Qmodifier_value
, make_number (ctrl_modifier
));
11592 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
11593 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
11594 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
11595 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
11597 #if USE_CARBON_EVENTS
11598 Qhi_command
= intern ("hi-command"); staticpro (&Qhi_command
);
11600 Qtoolbar_switch_mode
= intern ("toolbar-switch-mode");
11601 staticpro (&Qtoolbar_switch_mode
);
11602 #if USE_MAC_FONT_PANEL
11603 Qpanel_closed
= intern ("panel-closed"); staticpro (&Qpanel_closed
);
11604 Qselection
= intern ("selection"); staticpro (&Qselection
);
11607 Qservice
= intern ("service"); staticpro (&Qservice
);
11608 Qpaste
= intern ("paste"); staticpro (&Qpaste
);
11609 Qperform
= intern ("perform"); staticpro (&Qperform
);
11612 Qtext_input
= intern ("text-input"); staticpro (&Qtext_input
);
11613 Qupdate_active_input_area
= intern ("update-active-input-area");
11614 staticpro (&Qupdate_active_input_area
);
11615 Qunicode_for_key_event
= intern ("unicode-for-key-event");
11616 staticpro (&Qunicode_for_key_event
);
11621 Fprovide (intern ("mac-carbon"), Qnil
);
11624 staticpro (&Qreverse
);
11625 Qreverse
= intern ("reverse");
11627 staticpro (&x_display_name_list
);
11628 x_display_name_list
= Qnil
;
11630 staticpro (&last_mouse_scroll_bar
);
11631 last_mouse_scroll_bar
= Qnil
;
11633 staticpro (&fm_font_family_alist
);
11634 fm_font_family_alist
= Qnil
;
11637 staticpro (&atsu_font_id_hash
);
11638 atsu_font_id_hash
= Qnil
;
11640 staticpro (&fm_style_face_attributes_alist
);
11641 fm_style_face_attributes_alist
= Qnil
;
11645 staticpro (&saved_ts_script_language_on_focus
);
11646 saved_ts_script_language_on_focus
= Qnil
;
11649 /* We don't yet support this, but defining this here avoids whining
11650 from cus-start.el and other places, like "M-x set-variable". */
11651 DEFVAR_BOOL ("x-use-underline-position-properties",
11652 &x_use_underline_position_properties
,
11653 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
11654 nil means ignore them. If you encounter fonts with bogus
11655 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
11656 to 4.1, set this to nil.
11658 NOTE: Not supported on Mac yet. */);
11659 x_use_underline_position_properties
= 0;
11661 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
11662 doc
: /* If not nil, Emacs uses toolkit scroll bars. */);
11663 #ifdef USE_TOOLKIT_SCROLL_BARS
11664 Vx_toolkit_scroll_bars
= Qt
;
11666 Vx_toolkit_scroll_bars
= Qnil
;
11669 staticpro (&last_mouse_motion_frame
);
11670 last_mouse_motion_frame
= Qnil
;
11672 /* Variables to configure modifier key assignment. */
11674 DEFVAR_LISP ("mac-control-modifier", &Vmac_control_modifier
,
11675 doc
: /* *Modifier key assumed when the Mac control key is pressed.
11676 The value can be `control', `meta', `alt', `hyper', or `super' for the
11677 respective modifier. The default is `control'. */);
11678 Vmac_control_modifier
= Qcontrol
;
11680 DEFVAR_LISP ("mac-option-modifier", &Vmac_option_modifier
,
11681 doc
: /* *Modifier key assumed when the Mac alt/option key is pressed.
11682 The value can be `control', `meta', `alt', `hyper', or `super' for the
11683 respective modifier. If the value is nil then the key will act as the
11684 normal Mac control modifier, and the option key can be used to compose
11685 characters depending on the chosen Mac keyboard setting. */);
11686 Vmac_option_modifier
= Qnil
;
11688 DEFVAR_LISP ("mac-command-modifier", &Vmac_command_modifier
,
11689 doc
: /* *Modifier key assumed when the Mac command key is pressed.
11690 The value can be `control', `meta', `alt', `hyper', or `super' for the
11691 respective modifier. The default is `meta'. */);
11692 Vmac_command_modifier
= Qmeta
;
11694 DEFVAR_LISP ("mac-function-modifier", &Vmac_function_modifier
,
11695 doc
: /* *Modifier key assumed when the Mac function key is pressed.
11696 The value can be `control', `meta', `alt', `hyper', or `super' for the
11697 respective modifier. Note that remapping the function key may lead to
11698 unexpected results for some keys on non-US/GB keyboards. */);
11699 Vmac_function_modifier
= Qnil
;
11701 DEFVAR_LISP ("mac-emulate-three-button-mouse",
11702 &Vmac_emulate_three_button_mouse
,
11703 doc
: /* *Specify a way of three button mouse emulation.
11704 The value can be nil, t, or the symbol `reverse'.
11705 nil means that no emulation should be done and the modifiers should be
11706 placed on the mouse-1 event.
11707 t means that when the option-key is held down while pressing the mouse
11708 button, the click will register as mouse-2 and while the command-key
11709 is held down, the click will register as mouse-3.
11710 The symbol `reverse' means that the option-key will register for
11711 mouse-3 and the command-key will register for mouse-2. */);
11712 Vmac_emulate_three_button_mouse
= Qnil
;
11714 #if USE_CARBON_EVENTS
11715 DEFVAR_BOOL ("mac-wheel-button-is-mouse-2", &mac_wheel_button_is_mouse_2
,
11716 doc
: /* *Non-nil if the wheel button is mouse-2 and the right click mouse-3.
11717 Otherwise, the right click will be treated as mouse-2 and the wheel
11718 button will be mouse-3. */);
11719 mac_wheel_button_is_mouse_2
= 1;
11721 DEFVAR_BOOL ("mac-pass-command-to-system", &mac_pass_command_to_system
,
11722 doc
: /* *Non-nil if command key presses are passed on to the Mac Toolbox. */);
11723 mac_pass_command_to_system
= 1;
11725 DEFVAR_BOOL ("mac-pass-control-to-system", &mac_pass_control_to_system
,
11726 doc
: /* *Non-nil if control key presses are passed on to the Mac Toolbox. */);
11727 mac_pass_control_to_system
= 1;
11731 DEFVAR_BOOL ("mac-allow-anti-aliasing", &mac_use_core_graphics
,
11732 doc
: /* *If non-nil, allow anti-aliasing.
11733 The text will be rendered using Core Graphics text rendering which
11734 may anti-alias the text. */);
11736 mac_use_core_graphics
= 1;
11738 mac_use_core_graphics
= 0;
11741 /* Register an entry for `mac-roman' so that it can be used when
11742 creating the terminal frame on Mac OS 9 before loading
11743 term/mac-win.elc. */
11744 DEFVAR_LISP ("mac-charset-info-alist", &Vmac_charset_info_alist
,
11745 doc
: /* Alist of Emacs character sets vs text encodings and coding systems.
11746 Each entry should be of the form:
11748 (CHARSET-NAME TEXT-ENCODING CODING-SYSTEM)
11750 where CHARSET-NAME is a string used in font names to identify the
11751 charset, TEXT-ENCODING is a TextEncodingBase value in Mac, and
11752 CODING_SYSTEM is a coding system corresponding to TEXT-ENCODING. */);
11753 Vmac_charset_info_alist
=
11754 Fcons (list3 (build_string ("mac-roman"),
11755 make_number (smRoman
), Qnil
), Qnil
);
11758 DEFVAR_LISP ("mac-atsu-font-table", &Vmac_atsu_font_table
,
11759 doc
: /* Hash table of ATSU font IDs vs plist of attributes and values. */);
11760 Vmac_atsu_font_table
=
11761 make_hash_table (Qeql
, make_number (DEFAULT_HASH_SIZE
),
11762 make_float (DEFAULT_REHASH_SIZE
),
11763 make_float (DEFAULT_REHASH_THRESHOLD
),
11767 DEFVAR_LISP ("mac-ts-active-input-overlay", &Vmac_ts_active_input_overlay
,
11768 doc
: /* Overlay used to display Mac TSM active input area. */);
11769 Vmac_ts_active_input_overlay
= Qnil
;
11771 DEFVAR_LISP ("mac-ts-script-language-on-focus", &Vmac_ts_script_language_on_focus
,
11772 doc
: /* *How to change Mac TSM script/language when a frame gets focus.
11773 If the value is t, the input script and language are restored to those
11774 used in the last focus frame. If the value is a pair of integers, the
11775 input script and language codes, which are defined in the Script
11776 Manager, are set to its car and cdr parts, respectively. Otherwise,
11777 Emacs doesn't set them and thus follows the system default behavior. */);
11778 Vmac_ts_script_language_on_focus
= Qnil
;
11782 /* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b
11783 (do not change this comment) */