1 /* Implementation of GUI terminal on the Mac OS.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, 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 #include <Quickdraw.h>
40 #include <ToolUtils.h>
44 #include <Resources.h>
46 #include <TextUtils.h>
51 #if defined (__MRC__) || (__MSL__ >= 0x6000)
52 #include <ControlDefinitions.h>
58 #endif /* not TARGET_API_MAC_CARBON */
71 #include "dispextern.h"
73 #include "termhooks.h"
80 #include "intervals.h"
86 /* Non-nil means Emacs uses toolkit scroll bars. */
88 Lisp_Object Vx_toolkit_scroll_bars
;
90 /* If non-zero, the text will be rendered using Core Graphics text
91 rendering which may anti-alias the text. */
92 int mac_use_core_graphics
;
95 /* Non-zero means that a HELP_EVENT has been generated since Emacs
98 static int any_help_event_p
;
100 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
101 static Lisp_Object last_window
;
103 /* Non-zero means make use of UNDERLINE_POSITION font properties.
104 (Not yet supported.) */
105 int x_use_underline_position_properties
;
107 /* Non-zero means to draw the underline at the same place as the descent line. */
109 int x_underline_at_descent_line
;
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 static 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_ ((struct terminal
*));
235 static void XTreset_terminal_modes
P_ ((struct terminal
*));
236 static void x_clear_frame
P_ ((struct frame
*));
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
*,
244 struct input_event
*));
245 static void XTframe_rehighlight
P_ ((struct frame
*));
246 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
247 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
248 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
249 enum text_cursor_kinds
));
251 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*, int, GC
));
252 static void x_flush
P_ ((struct frame
*f
));
253 static void x_update_begin
P_ ((struct frame
*));
254 static void x_update_window_begin
P_ ((struct window
*));
255 static void x_after_update_window_line
P_ ((struct glyph_row
*));
256 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
257 enum scroll_bar_part
*,
258 Lisp_Object
*, Lisp_Object
*,
261 static int is_emacs_window
P_ ((WindowRef
));
262 static XCharStruct
*mac_per_char_metric
P_ ((XFontStruct
*, XChar2b
*, int));
263 static void XSetFont
P_ ((Display
*, GC
, XFontStruct
*));
264 static struct terminal
*mac_create_terminal
P_ ((struct mac_display_info
*dpyinfo
));
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)
272 #define CG_SET_FILL_COLOR(context, color) \
273 CGContextSetRGBFillColor (context, \
274 RED_FROM_ULONG (color) / 255.0f, \
275 GREEN_FROM_ULONG (color) / 255.0f, \
276 BLUE_FROM_ULONG (color) / 255.0f, 1.0f)
277 #if USE_CG_DRAWING && MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
278 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
279 #define CG_SET_FILL_COLOR_MAYBE_WITH_CGCOLOR(context, color, cg_color) \
281 if (CGColorGetTypeID != NULL) \
282 CGContextSetFillColorWithColor (context, cg_color); \
284 CG_SET_FILL_COLOR (context, color); \
287 #define CG_SET_FILL_COLOR_MAYBE_WITH_CGCOLOR(context, color, cg_color) \
288 CGContextSetFillColorWithColor (context, cg_color)
291 #define CG_SET_FILL_COLOR_MAYBE_WITH_CGCOLOR(context, color, cg_color) \
292 CG_SET_FILL_COLOR (context, color)
294 #define CG_SET_FILL_COLOR_WITH_GC_FOREGROUND(context, gc) \
295 CG_SET_FILL_COLOR_MAYBE_WITH_CGCOLOR (context, (gc)->xgcv.foreground, \
297 #define CG_SET_FILL_COLOR_WITH_GC_BACKGROUND(context, gc) \
298 CG_SET_FILL_COLOR_MAYBE_WITH_CGCOLOR (context, (gc)->xgcv.background, \
302 #define CG_SET_STROKE_COLOR(context, color) \
303 CGContextSetRGBStrokeColor (context, \
304 RED_FROM_ULONG (color) / 255.0f, \
305 GREEN_FROM_ULONG (color) / 255.0f, \
306 BLUE_FROM_ULONG (color) / 255.0f, 1.0f)
307 #if USE_CG_DRAWING && MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
308 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
309 #define CG_SET_STROKE_COLOR_MAYBE_WITH_CGCOLOR(context, color, cg_color) \
311 if (CGColorGetTypeID != NULL) \
312 CGContextSetStrokeColorWithColor (context, cg_color); \
314 CG_SET_STROKE_COLOR (context, color); \
317 #define CG_SET_STROKE_COLOR_MAYBE_WITH_CGCOLOR(context, color, cg_color) \
318 CGContextSetStrokeColorWithColor (context, cg_color)
321 #define CG_SET_STROKE_COLOR_MAYBE_WITH_CGCOLOR(context, color, cg_color) \
322 CG_SET_STROKE_COLOR (context, color)
324 #define CG_SET_STROKE_COLOR_WITH_GC_FOREGROUND(context, gc) \
325 CG_SET_STROKE_COLOR_MAYBE_WITH_CGCOLOR (context, (gc)->xgcv.foreground, \
329 #define FRAME_CG_CONTEXT(f) ((f)->output_data.mac->cg_context)
331 /* Fringe bitmaps. */
333 static int max_fringe_bmp
= 0;
334 static CGImageRef
*fringe_bmp
= 0;
336 static CGColorSpaceRef mac_cg_color_space_rgb
;
337 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
338 static CGColorRef mac_cg_color_black
;
344 mac_cg_color_space_rgb
= CGColorSpaceCreateDeviceRGB ();
345 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
346 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
347 /* Don't check the availability of CGColorCreate; this symbol is
348 defined even in Mac OS X 10.1. */
349 if (CGColorGetTypeID
!= NULL
)
352 float rgba
[] = {0.0f
, 0.0f
, 0.0f
, 1.0f
};
354 mac_cg_color_black
= CGColorCreate (mac_cg_color_space_rgb
, rgba
);
360 mac_begin_cg_clip (f
, gc
)
364 CGContextRef context
= FRAME_CG_CONTEXT (f
);
368 QDBeginCGContext (GetWindowPort (FRAME_MAC_WINDOW (f
)), &context
);
369 FRAME_CG_CONTEXT (f
) = context
;
372 CGContextSaveGState (context
);
373 CGContextTranslateCTM (context
, 0, FRAME_PIXEL_HEIGHT (f
));
374 CGContextScaleCTM (context
, 1, -1);
375 if (gc
&& gc
->n_clip_rects
)
376 CGContextClipToRects (context
, gc
->clip_rects
, gc
->n_clip_rects
);
385 CGContextRestoreGState (FRAME_CG_CONTEXT (f
));
389 mac_prepare_for_quickdraw (f
)
394 Lisp_Object rest
, frame
;
395 FOR_EACH_FRAME (rest
, frame
)
396 if (FRAME_MAC_P (XFRAME (frame
)))
397 mac_prepare_for_quickdraw (XFRAME (frame
));
401 CGContextRef context
= FRAME_CG_CONTEXT (f
);
405 CGContextSynchronize (context
);
406 QDEndCGContext (GetWindowPort (FRAME_MAC_WINDOW (f
)),
407 &FRAME_CG_CONTEXT (f
));
413 static RgnHandle saved_port_clip_region
= NULL
;
416 mac_begin_clip (f
, gc
)
420 static RgnHandle new_region
= NULL
;
422 if (saved_port_clip_region
== NULL
)
423 saved_port_clip_region
= NewRgn ();
424 if (new_region
== NULL
)
425 new_region
= NewRgn ();
428 mac_prepare_for_quickdraw (f
);
430 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
432 if (gc
->n_clip_rects
)
434 GetClip (saved_port_clip_region
);
435 SectRgn (saved_port_clip_region
, gc
->clip_region
, new_region
);
436 SetClip (new_region
);
444 if (gc
->n_clip_rects
)
445 SetClip (saved_port_clip_region
);
449 /* X display function emulation */
451 /* Mac version of XDrawLine. */
454 mac_draw_line (f
, gc
, x1
, y1
, x2
, y2
)
460 CGContextRef context
;
461 float gx1
= x1
, gy1
= y1
, gx2
= x2
, gy2
= y2
;
464 gx1
+= 0.5f
, gx2
+= 0.5f
;
466 gy1
+= 0.5f
, gy2
+= 0.5f
;
468 context
= mac_begin_cg_clip (f
, gc
);
469 CG_SET_STROKE_COLOR_WITH_GC_FOREGROUND (context
, gc
);
470 CGContextBeginPath (context
);
471 CGContextMoveToPoint (context
, gx1
, gy1
);
472 CGContextAddLineToPoint (context
, gx2
, gy2
);
473 CGContextClosePath (context
);
474 CGContextStrokePath (context
);
492 mac_begin_clip (f
, gc
);
493 RGBForeColor (GC_FORE_COLOR (gc
));
500 /* Mac version of XDrawLine (to Pixmap). */
503 XDrawLine (display
, p
, gc
, x1
, y1
, x2
, y2
)
527 GetGWorld (&old_port
, &old_gdh
);
530 RGBForeColor (GC_FORE_COLOR (gc
));
532 LockPixels (GetGWorldPixMap (p
));
535 UnlockPixels (GetGWorldPixMap (p
));
537 SetGWorld (old_port
, old_gdh
);
542 mac_erase_rectangle (f
, gc
, x
, y
, width
, height
)
546 unsigned int width
, height
;
550 CGContextRef context
;
552 context
= mac_begin_cg_clip (f
, gc
);
553 CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context
, gc
);
554 CGContextFillRect (context
, CGRectMake (x
, y
, width
, height
));
561 mac_begin_clip (f
, gc
);
562 RGBBackColor (GC_BACK_COLOR (gc
));
563 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
565 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
572 /* Mac version of XClearArea. */
575 mac_clear_area (f
, x
, y
, width
, height
)
578 unsigned int width
, height
;
580 mac_erase_rectangle (f
, FRAME_NORMAL_GC (f
), x
, y
, width
, height
);
583 /* Mac version of XClearWindow. */
591 CGContextRef context
;
592 GC gc
= FRAME_NORMAL_GC (f
);
594 context
= mac_begin_cg_clip (f
, NULL
);
595 CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context
, gc
);
596 CGContextFillRect (context
, CGRectMake (0, 0, FRAME_PIXEL_WIDTH (f
),
597 FRAME_PIXEL_HEIGHT (f
)));
600 #else /* !USE_CG_DRAWING */
601 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
603 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
605 #if TARGET_API_MAC_CARBON
609 GetWindowPortBounds (FRAME_MAC_WINDOW (f
), &r
);
612 #else /* not TARGET_API_MAC_CARBON */
613 EraseRect (&(FRAME_MAC_WINDOW (f
)->portRect
));
614 #endif /* not TARGET_API_MAC_CARBON */
619 /* Mac replacement for XCopyArea. */
623 mac_draw_cg_image (image
, f
, gc
, src_x
, src_y
, width
, height
,
624 dest_x
, dest_y
, overlay_p
)
629 unsigned int width
, height
;
630 int dest_x
, dest_y
, overlay_p
;
632 CGContextRef context
;
633 float port_height
= FRAME_PIXEL_HEIGHT (f
);
634 CGRect dest_rect
= CGRectMake (dest_x
, dest_y
, width
, height
);
636 context
= mac_begin_cg_clip (f
, gc
);
639 CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context
, gc
);
640 CGContextFillRect (context
, dest_rect
);
642 CGContextClipToRect (context
, dest_rect
);
643 CGContextScaleCTM (context
, 1, -1);
644 CGContextTranslateCTM (context
, 0, -port_height
);
645 if (CGImageIsMask (image
))
646 CG_SET_FILL_COLOR_WITH_GC_FOREGROUND (context
, gc
);
647 CGContextDrawImage (context
,
648 CGRectMake (dest_x
- src_x
,
649 port_height
- (dest_y
- src_y
650 + CGImageGetHeight (image
)),
651 CGImageGetWidth (image
),
652 CGImageGetHeight (image
)),
657 #else /* !USE_CG_DRAWING */
660 mac_draw_bitmap (f
, gc
, x
, y
, width
, height
, bits
, overlay_p
)
663 int x
, y
, width
, height
;
664 unsigned short *bits
;
670 bitmap
.rowBytes
= sizeof(unsigned short);
671 bitmap
.baseAddr
= (char *)bits
;
672 SetRect (&(bitmap
.bounds
), 0, 0, width
, height
);
674 mac_begin_clip (f
, gc
);
675 RGBForeColor (GC_FORE_COLOR (gc
));
676 RGBBackColor (GC_BACK_COLOR (gc
));
677 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
678 #if TARGET_API_MAC_CARBON
684 CopyBits (&bitmap
, GetPortBitMapForCopyBits (port
),
685 &(bitmap
.bounds
), &r
, overlay_p
? srcOr
: srcCopy
, 0);
686 UnlockPortBits (port
);
688 #else /* not TARGET_API_MAC_CARBON */
689 CopyBits (&bitmap
, &(FRAME_MAC_WINDOW (f
)->portBits
), &(bitmap
.bounds
), &r
,
690 overlay_p
? srcOr
: srcCopy
, 0);
691 #endif /* not TARGET_API_MAC_CARBON */
692 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
695 #endif /* !USE_CG_DRAWING */
698 /* Mac replacement for XCreateBitmapFromBitmapData. */
701 mac_create_bitmap_from_bitmap_data (bitmap
, bits
, w
, h
)
706 static const unsigned char swap_nibble
[16]
707 = { 0x0, 0x8, 0x4, 0xc, /* 0000 1000 0100 1100 */
708 0x2, 0xa, 0x6, 0xe, /* 0010 1010 0110 1110 */
709 0x1, 0x9, 0x5, 0xd, /* 0001 1001 0101 1101 */
710 0x3, 0xb, 0x7, 0xf }; /* 0011 1011 0111 1111 */
714 w1
= (w
+ 7) / 8; /* nb of 8bits elt in X bitmap */
715 bitmap
->rowBytes
= ((w
+ 15) / 16) * 2; /* nb of 16bits elt in Mac bitmap */
716 bitmap
->baseAddr
= xmalloc (bitmap
->rowBytes
* h
);
717 bzero (bitmap
->baseAddr
, bitmap
->rowBytes
* h
);
718 for (i
= 0; i
< h
; i
++)
720 p
= bitmap
->baseAddr
+ i
* bitmap
->rowBytes
;
721 for (j
= 0; j
< w1
; j
++)
723 /* Bitswap XBM bytes to match how Mac does things. */
724 unsigned char c
= *bits
++;
725 *p
++ = (unsigned char)((swap_nibble
[c
& 0xf] << 4)
726 | (swap_nibble
[(c
>>4) & 0xf]));
730 SetRect (&(bitmap
->bounds
), 0, 0, w
, h
);
735 mac_free_bitmap (bitmap
)
738 xfree (bitmap
->baseAddr
);
743 XCreatePixmap (display
, w
, width
, height
, depth
)
746 unsigned int width
, height
;
753 SetPortWindowPort (w
);
755 SetRect (&r
, 0, 0, width
, height
);
756 #if !defined (WORDS_BIG_ENDIAN) && USE_CG_DRAWING
759 err
= NewGWorld (&pixmap
, depth
, &r
, NULL
, NULL
, 0);
760 #if !defined (WORDS_BIG_ENDIAN) && USE_CG_DRAWING
762 /* CreateCGImageFromPixMaps requires ARGB format. */
763 err
= QTNewGWorld (&pixmap
, k32ARGBPixelFormat
, &r
, NULL
, NULL
, 0);
772 XCreatePixmapFromBitmapData (display
, w
, data
, width
, height
, fg
, bg
, depth
)
776 unsigned int width
, height
;
777 unsigned long fg
, bg
;
787 gc
= XCreateGC (display
, w
, 0, NULL
);
789 pixmap
= XCreatePixmap (display
, w
, width
, height
, depth
);
793 GetGWorld (&old_port
, &old_gdh
);
794 SetGWorld (pixmap
, NULL
);
795 mac_create_bitmap_from_bitmap_data (&bitmap
, data
, width
, height
);
796 XSetForeground (display
, gc
, fg
);
797 XSetBackground (display
, gc
, bg
);
798 RGBForeColor (GC_FORE_COLOR (gc
));
799 RGBBackColor (GC_BACK_COLOR (gc
));
800 LockPixels (GetGWorldPixMap (pixmap
));
801 #if TARGET_API_MAC_CARBON
802 CopyBits (&bitmap
, GetPortBitMapForCopyBits (pixmap
),
803 &bitmap
.bounds
, &bitmap
.bounds
, srcCopy
, 0);
804 #else /* not TARGET_API_MAC_CARBON */
805 CopyBits (&bitmap
, &(((GrafPtr
)pixmap
)->portBits
),
806 &bitmap
.bounds
, &bitmap
.bounds
, srcCopy
, 0);
807 #endif /* not TARGET_API_MAC_CARBON */
808 UnlockPixels (GetGWorldPixMap (pixmap
));
809 SetGWorld (old_port
, old_gdh
);
810 mac_free_bitmap (&bitmap
);
817 XFreePixmap (display
, pixmap
)
821 DisposeGWorld (pixmap
);
825 /* Mac replacement for XFillRectangle. */
828 mac_fill_rectangle (f
, gc
, x
, y
, width
, height
)
832 unsigned int width
, height
;
835 CGContextRef context
;
837 context
= mac_begin_cg_clip (f
, gc
);
838 CG_SET_FILL_COLOR_WITH_GC_FOREGROUND (context
, gc
);
839 CGContextFillRect (context
, CGRectMake (x
, y
, width
, height
));
844 mac_begin_clip (f
, gc
);
845 RGBForeColor (GC_FORE_COLOR (gc
));
846 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
847 PaintRect (&r
); /* using foreground color of gc */
853 /* Mac replacement for XDrawRectangle: dest is a window. */
856 mac_draw_rectangle (f
, gc
, x
, y
, width
, height
)
860 unsigned int width
, height
;
863 CGContextRef context
;
865 context
= mac_begin_cg_clip (f
, gc
);
866 CG_SET_STROKE_COLOR_WITH_GC_FOREGROUND (context
, gc
);
867 CGContextStrokeRect (context
,
868 CGRectMake (x
+ 0.5f
, y
+ 0.5f
, width
, height
));
873 mac_begin_clip (f
, gc
);
874 RGBForeColor (GC_FORE_COLOR (gc
));
875 SetRect (&r
, x
, y
, x
+ width
+ 1, y
+ height
+ 1);
876 FrameRect (&r
); /* using foreground color of gc */
883 mac_invert_rectangle (f
, x
, y
, width
, height
)
886 unsigned int width
, height
;
891 mac_prepare_for_quickdraw (f
);
893 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
895 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
903 atsu_get_text_layout_with_text_ptr (text
, text_length
, style
, text_layout
)
904 ConstUniCharArrayPtr text
;
905 UniCharCount text_length
;
907 ATSUTextLayout
*text_layout
;
910 static ATSUTextLayout saved_text_layout
= NULL
;
912 if (saved_text_layout
== NULL
)
914 static const UniCharCount lengths
[] = {kATSUToTextEnd
};
915 static const ATSUAttributeTag tags
[] = {kATSULineLayoutOptionsTag
};
916 static const ByteCount sizes
[] = {sizeof (ATSLineLayoutOptions
)};
917 static ATSLineLayoutOptions line_layout
=
918 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
919 kATSLineDisableAllLayoutOperations
| kATSLineUseDeviceMetrics
920 | kATSLineUseQDRendering
922 kATSLineIsDisplayOnly
| kATSLineFractDisable
925 static const ATSUAttributeValuePtr values
[] = {&line_layout
};
927 err
= ATSUCreateTextLayoutWithTextPtr (text
,
928 kATSUFromTextBeginning
,
934 err
= ATSUSetLayoutControls (saved_text_layout
,
935 sizeof (tags
) / sizeof (tags
[0]),
936 tags
, sizes
, values
);
938 err
= ATSUSetTransientFontMatching (saved_text_layout
, true);
942 err
= ATSUSetRunStyle (saved_text_layout
, style
,
943 kATSUFromTextBeginning
, kATSUToTextEnd
);
945 err
= ATSUSetTextPointerLocation (saved_text_layout
, text
,
946 kATSUFromTextBeginning
,
952 *text_layout
= saved_text_layout
;
958 mac_draw_image_string_atsui (f
, gc
, x
, y
, buf
, nchars
, bg_width
,
959 overstrike_p
, bytes_per_char
)
964 int nchars
, bg_width
, overstrike_p
, bytes_per_char
;
967 ATSUTextLayout text_layout
;
969 xassert (bytes_per_char
== 2);
971 #ifndef WORDS_BIG_ENDIAN
974 UniChar
*text
= (UniChar
*)buf
;
976 for (i
= 0; i
< nchars
; i
++)
977 text
[i
] = EndianU16_BtoN (text
[i
]);
980 err
= atsu_get_text_layout_with_text_ptr ((ConstUniCharArrayPtr
)buf
,
982 GC_FONT (gc
)->mac_style
,
987 if (!mac_use_core_graphics
)
990 mac_begin_clip (f
, gc
);
991 RGBForeColor (GC_FORE_COLOR (gc
));
996 SetRect (&r
, x
, y
- FONT_BASE (GC_FONT (gc
)),
997 x
+ bg_width
, y
+ FONT_DESCENT (GC_FONT (gc
)));
998 RGBBackColor (GC_BACK_COLOR (gc
));
1000 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1003 ATSUDrawText (text_layout
,
1004 kATSUFromTextBeginning
, kATSUToTextEnd
,
1005 kATSUUseGrafPortPenLoc
, kATSUUseGrafPortPenLoc
);
1009 ATSUDrawText (text_layout
,
1010 kATSUFromTextBeginning
, kATSUToTextEnd
,
1011 kATSUUseGrafPortPenLoc
, kATSUUseGrafPortPenLoc
);
1018 static CGContextRef context
;
1019 float port_height
= FRAME_PIXEL_HEIGHT (f
);
1020 static const ATSUAttributeTag tags
[] = {kATSUCGContextTag
};
1021 static const ByteCount sizes
[] = {sizeof (CGContextRef
)};
1022 static const ATSUAttributeValuePtr values
[] = {&context
};
1025 context
= mac_begin_cg_clip (f
, gc
);
1030 QDBeginCGContext (port
, &context
);
1031 if (gc
->n_clip_rects
|| bg_width
)
1033 CGContextTranslateCTM (context
, 0, port_height
);
1034 CGContextScaleCTM (context
, 1, -1);
1035 if (gc
->n_clip_rects
)
1036 CGContextClipToRects (context
, gc
->clip_rects
,
1041 CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context
, gc
);
1042 CGContextFillRect (context
,
1043 CGRectMake (x
, y
- FONT_BASE (GC_FONT (gc
)),
1045 FONT_HEIGHT (GC_FONT (gc
))));
1047 CGContextScaleCTM (context
, 1, -1);
1048 CGContextTranslateCTM (context
, 0, -port_height
);
1052 CG_SET_FILL_COLOR_WITH_GC_FOREGROUND (context
, gc
);
1053 err
= ATSUSetLayoutControls (text_layout
,
1054 sizeof (tags
) / sizeof (tags
[0]),
1055 tags
, sizes
, values
);
1058 ATSUDrawText (text_layout
,
1059 kATSUFromTextBeginning
, kATSUToTextEnd
,
1060 Long2Fix (x
), Long2Fix (port_height
- y
));
1062 ATSUDrawText (text_layout
,
1063 kATSUFromTextBeginning
, kATSUToTextEnd
,
1064 Long2Fix (x
+ 1), Long2Fix (port_height
- y
));
1067 mac_end_cg_clip (f
);
1070 CGContextSynchronize (context
);
1071 QDEndCGContext (port
, &context
);
1074 /* This doesn't work on Mac OS X 10.1. */
1075 ATSUClearLayoutControls (text_layout
,
1076 sizeof (tags
) / sizeof (tags
[0]), tags
);
1078 ATSUSetLayoutControls (text_layout
,
1079 sizeof (tags
) / sizeof (tags
[0]),
1080 tags
, sizes
, values
);
1083 #endif /* MAC_OSX */
1085 #endif /* USE_ATSUI */
1089 mac_draw_image_string_qd (f
, gc
, x
, y
, buf
, nchars
, bg_width
,
1090 overstrike_p
, bytes_per_char
)
1095 int nchars
, bg_width
, overstrike_p
, bytes_per_char
;
1097 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1101 mac_begin_clip (f
, gc
);
1102 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1103 if (mac_use_core_graphics
)
1104 savedFlags
= SwapQDTextFlags (kQDUseCGTextRendering
);
1106 RGBForeColor (GC_FORE_COLOR (gc
));
1110 RGBBackColor (GC_BACK_COLOR (gc
));
1116 /* We prefer not to use srcCopy text transfer mode on Mac OS X
1118 - Screen is double-buffered. (In srcCopy mode, a text is drawn
1119 into an offscreen graphics world first. So performance gain
1120 cannot be expected.)
1121 - It lowers rendering quality.
1122 - Some fonts leave garbage on cursor movement. */
1127 RGBBackColor (GC_BACK_COLOR (gc
));
1128 SetRect (&r
, x
, y
- FONT_BASE (GC_FONT (gc
)),
1129 x
+ bg_width
, y
+ FONT_DESCENT (GC_FONT (gc
)));
1134 TextFont (GC_FONT (gc
)->mac_fontnum
);
1135 TextSize (GC_FONT (gc
)->mac_fontsize
);
1136 TextFace (GC_FONT (gc
)->mac_fontface
);
1138 DrawText (buf
, 0, nchars
* bytes_per_char
);
1143 DrawText (buf
, 0, nchars
* bytes_per_char
);
1146 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1149 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1150 if (mac_use_core_graphics
)
1151 SwapQDTextFlags(savedFlags
);
1157 mac_draw_string_common (f
, gc
, x
, y
, buf
, nchars
, bg_width
,
1158 overstrike_p
, bytes_per_char
)
1163 int nchars
, bg_width
, overstrike_p
, bytes_per_char
;
1166 if (GC_FONT (gc
)->mac_style
)
1167 mac_draw_image_string_atsui (f
, gc
, x
, y
, buf
, nchars
, bg_width
,
1168 overstrike_p
, bytes_per_char
);
1170 #endif /* USE_ATSUI */
1171 mac_draw_image_string_qd (f
, gc
, x
, y
, buf
, nchars
, bg_width
,
1172 overstrike_p
, bytes_per_char
);
1176 /* Mac replacement for XDrawImageString. */
1179 mac_draw_image_string (f
, gc
, x
, y
, buf
, nchars
, bg_width
, overstrike_p
)
1184 int nchars
, bg_width
, overstrike_p
;
1186 mac_draw_string_common (f
, gc
, x
, y
, buf
, nchars
, bg_width
,
1191 /* Mac replacement for XDrawImageString16. */
1194 mac_draw_image_string_16 (f
, gc
, x
, y
, buf
, nchars
, bg_width
, overstrike_p
)
1199 int nchars
, bg_width
, overstrike_p
;
1201 mac_draw_string_common (f
, gc
, x
, y
, (char *) buf
, nchars
, bg_width
,
1206 /* Mac replacement for XQueryTextExtents, but takes a character. If
1207 STYLE is NULL, measurement is done by QuickDraw Text routines for
1208 the font of the current graphics port. If CG_GLYPH is not NULL,
1209 *CG_GLYPH is set to the glyph ID or 0 if it cannot be obtained. */
1212 mac_query_char_extents (style
, c
,
1213 font_ascent_return
, font_descent_return
,
1214 overall_return
, cg_glyph
)
1221 int *font_ascent_return
, *font_descent_return
;
1222 XCharStruct
*overall_return
;
1223 #if USE_CG_TEXT_DRAWING
1229 OSStatus err
= noErr
;
1236 ATSUTextLayout text_layout
;
1239 err
= atsu_get_text_layout_with_text_ptr (&ch
, 1, style
, &text_layout
);
1241 && (font_ascent_return
|| font_descent_return
|| overall_return
))
1243 ATSTrapezoid glyph_bounds
;
1245 err
= ATSUGetGlyphBounds (text_layout
, 0, 0,
1246 kATSUFromTextBeginning
, kATSUToTextEnd
,
1247 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1248 kATSUseFractionalOrigins
,
1250 kATSUseDeviceOrigins
,
1252 1, &glyph_bounds
, NULL
);
1255 xassert (glyph_bounds
.lowerRight
.x
- glyph_bounds
.lowerLeft
.x
1256 == glyph_bounds
.upperRight
.x
- glyph_bounds
.upperLeft
.x
);
1258 width
= Fix2Long (glyph_bounds
.upperRight
.x
1259 - glyph_bounds
.upperLeft
.x
);
1260 if (font_ascent_return
)
1261 *font_ascent_return
= -Fix2Long (glyph_bounds
.upperLeft
.y
);
1262 if (font_descent_return
)
1263 *font_descent_return
= Fix2Long (glyph_bounds
.lowerLeft
.y
);
1266 if (err
== noErr
&& overall_return
)
1268 err
= ATSUMeasureTextImage (text_layout
,
1269 kATSUFromTextBeginning
, kATSUToTextEnd
,
1270 0, 0, &char_bounds
);
1272 STORE_XCHARSTRUCT (*overall_return
, width
, char_bounds
);
1273 #if USE_CG_TEXT_DRAWING
1274 if (err
== noErr
&& cg_glyph
)
1277 ATSUGlyphInfoArray glyph_info_array
;
1278 ByteCount count
= sizeof (ATSUGlyphInfoArray
);
1280 err1
= ATSUMatchFontsToText (text_layout
, kATSUFromTextBeginning
,
1281 kATSUToTextEnd
, NULL
, NULL
, NULL
);
1283 err1
= ATSUGetGlyphInfo (text_layout
, kATSUFromTextBeginning
,
1284 kATSUToTextEnd
, &count
,
1287 /* Make sure that we don't have to make layout
1289 && glyph_info_array
.glyphs
[0].deltaY
== 0.0f
1290 && glyph_info_array
.glyphs
[0].idealX
== 0.0f
1291 && glyph_info_array
.glyphs
[0].screenX
== 0)
1293 xassert (glyph_info_array
.glyphs
[0].glyphID
);
1294 *cg_glyph
= glyph_info_array
.glyphs
[0].glyphID
;
1305 if (font_ascent_return
|| font_descent_return
)
1309 GetFontInfo (&font_info
);
1310 if (font_ascent_return
)
1311 *font_ascent_return
= font_info
.ascent
;
1312 if (font_descent_return
)
1313 *font_descent_return
= font_info
.descent
;
1319 width
= CharWidth (ch
);
1320 QDTextBounds (1, &ch
, &char_bounds
);
1321 STORE_XCHARSTRUCT (*overall_return
, width
, char_bounds
);
1329 /* Mac replacement for XTextExtents16. Only sets horizontal metrics. */
1332 mac_text_extents_16 (font_struct
, string
, nchars
, overall_return
)
1333 XFontStruct
*font_struct
;
1336 XCharStruct
*overall_return
;
1339 short width
= 0, lbearing
= 0, rbearing
= 0;
1342 for (i
= 0; i
< nchars
; i
++)
1344 pcm
= mac_per_char_metric (font_struct
, string
, 0);
1346 width
+= FONT_WIDTH (font_struct
);
1349 lbearing
= min (lbearing
, width
+ pcm
->lbearing
);
1350 rbearing
= max (rbearing
, width
+ pcm
->rbearing
);
1351 width
+= pcm
->width
;
1356 overall_return
->lbearing
= lbearing
;
1357 overall_return
->rbearing
= rbearing
;
1358 overall_return
->width
= width
;
1360 /* What's the meaning of the return value of XTextExtents16? */
1364 #if USE_CG_TEXT_DRAWING
1365 static int cg_text_anti_aliasing_threshold
= 8;
1368 init_cg_text_anti_aliasing_threshold ()
1374 CFPreferencesGetAppIntegerValue (CFSTR ("AppleAntiAliasingThreshold"),
1375 kCFPreferencesCurrentApplication
,
1378 cg_text_anti_aliasing_threshold
= threshold
;
1382 mac_draw_image_string_cg (f
, gc
, x
, y
, buf
, nchars
, bg_width
, overstrike_p
)
1387 int nchars
, bg_width
, overstrike_p
;
1389 float port_height
, gx
, gy
;
1391 CGContextRef context
;
1395 if (!mac_use_core_graphics
|| GC_FONT (gc
)->cg_font
== NULL
)
1398 port_height
= FRAME_PIXEL_HEIGHT (f
);
1400 gy
= port_height
- y
;
1401 glyphs
= (CGGlyph
*)buf
;
1402 advances
= alloca (sizeof (CGSize
) * nchars
);
1403 if (advances
== NULL
)
1405 for (i
= 0; i
< nchars
; i
++)
1407 XCharStruct
*pcm
= mac_per_char_metric (GC_FONT (gc
), buf
, 0);
1409 advances
[i
].width
= pcm
->width
;
1410 advances
[i
].height
= 0;
1411 glyphs
[i
] = GC_FONT (gc
)->cg_glyphs
[buf
->byte2
];
1416 context
= mac_begin_cg_clip (f
, gc
);
1418 QDBeginCGContext (GetWindowPort (FRAME_MAC_WINDOW (f
)), &context
);
1419 if (gc
->n_clip_rects
|| bg_width
)
1421 CGContextTranslateCTM (context
, 0, port_height
);
1422 CGContextScaleCTM (context
, 1, -1);
1423 if (gc
->n_clip_rects
)
1424 CGContextClipToRects (context
, gc
->clip_rects
, gc
->n_clip_rects
);
1428 CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context
, gc
);
1431 CGRectMake (gx
, y
- FONT_BASE (GC_FONT (gc
)),
1432 bg_width
, FONT_HEIGHT (GC_FONT (gc
))));
1434 CGContextScaleCTM (context
, 1, -1);
1435 CGContextTranslateCTM (context
, 0, -port_height
);
1439 CG_SET_FILL_COLOR_WITH_GC_FOREGROUND (context
, gc
);
1440 CGContextSetFont (context
, GC_FONT (gc
)->cg_font
);
1441 CGContextSetFontSize (context
, GC_FONT (gc
)->mac_fontsize
);
1442 if (GC_FONT (gc
)->mac_fontsize
<= cg_text_anti_aliasing_threshold
)
1443 CGContextSetShouldAntialias (context
, false);
1444 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
1445 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
1446 if (CGContextShowGlyphsWithAdvances
!= NULL
)
1449 CGContextSetTextPosition (context
, gx
, gy
);
1450 CGContextShowGlyphsWithAdvances (context
, glyphs
, advances
, nchars
);
1453 CGContextSetTextPosition (context
, gx
+ 1.0f
, gy
);
1454 CGContextShowGlyphsWithAdvances (context
, glyphs
, advances
, nchars
);
1457 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
1458 else /* CGContextShowGlyphsWithAdvances == NULL */
1460 #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */
1461 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020
1463 for (i
= 0; i
< nchars
; i
++)
1465 CGContextShowGlyphsAtPoint (context
, gx
, gy
, glyphs
+ i
, 1);
1467 CGContextShowGlyphsAtPoint (context
, gx
+ 1.0f
, gy
, glyphs
+ i
, 1);
1468 gx
+= advances
[i
].width
;
1473 mac_end_cg_clip (f
);
1475 CGContextSynchronize (context
);
1476 QDEndCGContext (GetWindowPort (FRAME_MAC_WINDOW (f
)), &context
);
1485 /* Mac replacement for XCopyArea: dest must be window. */
1488 mac_copy_area (src
, f
, gc
, src_x
, src_y
, width
, height
, dest_x
, dest_y
)
1493 unsigned int width
, height
;
1498 mac_begin_clip (f
, gc
);
1500 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1501 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1503 ForeColor (blackColor
);
1504 BackColor (whiteColor
);
1506 LockPixels (GetGWorldPixMap (src
));
1507 #if TARGET_API_MAC_CARBON
1512 LockPortBits (port
);
1513 CopyBits (GetPortBitMapForCopyBits (src
),
1514 GetPortBitMapForCopyBits (port
),
1515 &src_r
, &dest_r
, srcCopy
, 0);
1516 UnlockPortBits (port
);
1518 #else /* not TARGET_API_MAC_CARBON */
1519 CopyBits (&(((GrafPtr
)src
)->portBits
), &(FRAME_MAC_WINDOW (f
)->portBits
),
1520 &src_r
, &dest_r
, srcCopy
, 0);
1521 #endif /* not TARGET_API_MAC_CARBON */
1522 UnlockPixels (GetGWorldPixMap (src
));
1524 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1531 mac_copy_area_with_mask (src
, mask
, f
, gc
, src_x
, src_y
,
1532 width
, height
, dest_x
, dest_y
)
1537 unsigned int width
, height
;
1542 mac_begin_clip (f
, gc
);
1544 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1545 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1547 ForeColor (blackColor
);
1548 BackColor (whiteColor
);
1550 LockPixels (GetGWorldPixMap (src
));
1551 LockPixels (GetGWorldPixMap (mask
));
1552 #if TARGET_API_MAC_CARBON
1557 LockPortBits (port
);
1558 CopyMask (GetPortBitMapForCopyBits (src
), GetPortBitMapForCopyBits (mask
),
1559 GetPortBitMapForCopyBits (port
),
1560 &src_r
, &src_r
, &dest_r
);
1561 UnlockPortBits (port
);
1563 #else /* not TARGET_API_MAC_CARBON */
1564 CopyMask (&(((GrafPtr
)src
)->portBits
), &(((GrafPtr
)mask
)->portBits
),
1565 &(FRAME_MAC_WINDOW (f
)->portBits
), &src_r
, &src_r
, &dest_r
);
1566 #endif /* not TARGET_API_MAC_CARBON */
1567 UnlockPixels (GetGWorldPixMap (mask
));
1568 UnlockPixels (GetGWorldPixMap (src
));
1570 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1574 #endif /* !USE_CG_DRAWING */
1577 /* Mac replacement for XCopyArea: used only for scrolling. */
1580 mac_scroll_area (f
, gc
, src_x
, src_y
, width
, height
, dest_x
, dest_y
)
1584 unsigned int width
, height
;
1587 #if TARGET_API_MAC_CARBON
1589 RgnHandle dummy
= NewRgn (); /* For avoiding update events. */
1591 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1593 mac_prepare_for_quickdraw (f
);
1595 ScrollWindowRect (FRAME_MAC_WINDOW (f
),
1596 &src_r
, dest_x
- src_x
, dest_y
- src_y
,
1597 kScrollWindowNoOptions
, dummy
);
1599 #else /* not TARGET_API_MAC_CARBON */
1601 WindowRef w
= FRAME_MAC_WINDOW (f
);
1603 mac_begin_clip (f
, gc
);
1605 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1606 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1608 /* In Color QuickDraw, set ForeColor and BackColor as follows to avoid
1609 color mapping in CopyBits. Otherwise, it will be slow. */
1610 ForeColor (blackColor
);
1611 BackColor (whiteColor
);
1612 CopyBits (&(w
->portBits
), &(w
->portBits
), &src_r
, &dest_r
, srcCopy
, 0);
1614 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1617 #endif /* not TARGET_API_MAC_CARBON */
1621 /* Mac replacement for XChangeGC. */
1624 XChangeGC (display
, gc
, mask
, xgcv
)
1630 if (mask
& GCForeground
)
1631 XSetForeground (display
, gc
, xgcv
->foreground
);
1632 if (mask
& GCBackground
)
1633 XSetBackground (display
, gc
, xgcv
->background
);
1635 XSetFont (display
, gc
, xgcv
->font
);
1639 /* Mac replacement for XCreateGC. */
1642 XCreateGC (display
, d
, mask
, xgcv
)
1648 GC gc
= xmalloc (sizeof (*gc
));
1650 bzero (gc
, sizeof (*gc
));
1651 #if USE_CG_DRAWING && MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
1652 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
1653 if (CGColorGetTypeID
!= NULL
)
1656 gc
->cg_fore_color
= gc
->cg_back_color
= mac_cg_color_black
;
1657 CGColorRetain (gc
->cg_fore_color
);
1658 CGColorRetain (gc
->cg_back_color
);
1661 XChangeGC (display
, gc
, mask
, xgcv
);
1667 /* Used in xfaces.c. */
1670 XFreeGC (display
, gc
)
1674 if (gc
->clip_region
)
1675 DisposeRgn (gc
->clip_region
);
1676 #if USE_CG_DRAWING && MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
1677 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
1678 if (CGColorGetTypeID
!= NULL
)
1681 CGColorRelease (gc
->cg_fore_color
);
1682 CGColorRelease (gc
->cg_back_color
);
1689 /* Mac replacement for XGetGCValues. */
1692 XGetGCValues (display
, gc
, mask
, xgcv
)
1698 if (mask
& GCForeground
)
1699 xgcv
->foreground
= gc
->xgcv
.foreground
;
1700 if (mask
& GCBackground
)
1701 xgcv
->background
= gc
->xgcv
.background
;
1703 xgcv
->font
= gc
->xgcv
.font
;
1707 /* Mac replacement for XSetForeground. */
1710 XSetForeground (display
, gc
, color
)
1713 unsigned long color
;
1715 if (gc
->xgcv
.foreground
!= color
)
1717 gc
->xgcv
.foreground
= color
;
1718 gc
->fore_color
.red
= RED16_FROM_ULONG (color
);
1719 gc
->fore_color
.green
= GREEN16_FROM_ULONG (color
);
1720 gc
->fore_color
.blue
= BLUE16_FROM_ULONG (color
);
1721 #if USE_CG_DRAWING && MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
1722 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
1723 if (CGColorGetTypeID
!= NULL
)
1726 CGColorRelease (gc
->cg_fore_color
);
1729 gc
->cg_fore_color
= mac_cg_color_black
;
1730 CGColorRetain (gc
->cg_fore_color
);
1736 rgba
[0] = gc
->fore_color
.red
/ 65535.0f
;
1737 rgba
[1] = gc
->fore_color
.green
/ 65535.0f
;
1738 rgba
[2] = gc
->fore_color
.blue
/ 65535.0f
;
1740 gc
->cg_fore_color
= CGColorCreate (mac_cg_color_space_rgb
, rgba
);
1748 /* Mac replacement for XSetBackground. */
1751 XSetBackground (display
, gc
, color
)
1754 unsigned long color
;
1756 if (gc
->xgcv
.background
!= color
)
1758 gc
->xgcv
.background
= color
;
1759 gc
->back_color
.red
= RED16_FROM_ULONG (color
);
1760 gc
->back_color
.green
= GREEN16_FROM_ULONG (color
);
1761 gc
->back_color
.blue
= BLUE16_FROM_ULONG (color
);
1762 #if USE_CG_DRAWING && MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
1763 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
1764 if (CGColorGetTypeID
!= NULL
)
1767 CGColorRelease (gc
->cg_back_color
);
1770 gc
->cg_back_color
= mac_cg_color_black
;
1771 CGColorRetain (gc
->cg_back_color
);
1777 rgba
[0] = gc
->back_color
.red
/ 65535.0f
;
1778 rgba
[1] = gc
->back_color
.green
/ 65535.0f
;
1779 rgba
[2] = gc
->back_color
.blue
/ 65535.0f
;
1781 gc
->cg_back_color
= CGColorCreate (mac_cg_color_space_rgb
, rgba
);
1789 /* Mac replacement for XSetFont. */
1792 XSetFont (display
, gc
, font
)
1797 gc
->xgcv
.font
= font
;
1801 /* Mac replacement for XSetClipRectangles. */
1804 mac_set_clip_rectangles (display
, gc
, rectangles
, n
)
1812 xassert (n
>= 0 && n
<= MAX_CLIP_RECTS
);
1814 gc
->n_clip_rects
= n
;
1817 if (gc
->clip_region
== NULL
)
1818 gc
->clip_region
= NewRgn ();
1819 RectRgn (gc
->clip_region
, rectangles
);
1822 RgnHandle region
= NewRgn ();
1824 for (i
= 1; i
< n
; i
++)
1826 RectRgn (region
, rectangles
+ i
);
1827 UnionRgn (gc
->clip_region
, region
, gc
->clip_region
);
1829 DisposeRgn (region
);
1832 #if defined (MAC_OSX) && (USE_ATSUI || USE_CG_DRAWING)
1833 for (i
= 0; i
< n
; i
++)
1835 Rect
*rect
= rectangles
+ i
;
1837 gc
->clip_rects
[i
] = CGRectMake (rect
->left
, rect
->top
,
1838 rect
->right
- rect
->left
,
1839 rect
->bottom
- rect
->top
);
1845 /* Mac replacement for XSetClipMask. */
1848 mac_reset_clip_rectangles (display
, gc
)
1852 gc
->n_clip_rects
= 0;
1856 /* Mac replacement for XSetWindowBackground. */
1859 XSetWindowBackground (display
, w
, color
)
1862 unsigned long color
;
1864 #if !TARGET_API_MAC_CARBON
1865 AuxWinHandle aw_handle
;
1866 CTabHandle ctab_handle
;
1867 ColorSpecPtr ct_table
;
1872 bg_color
.red
= RED16_FROM_ULONG (color
);
1873 bg_color
.green
= GREEN16_FROM_ULONG (color
);
1874 bg_color
.blue
= BLUE16_FROM_ULONG (color
);
1876 #if TARGET_API_MAC_CARBON
1877 SetWindowContentColor (w
, &bg_color
);
1879 if (GetAuxWin (w
, &aw_handle
))
1881 ctab_handle
= (*aw_handle
)->awCTable
;
1882 HandToHand ((Handle
*) &ctab_handle
);
1883 ct_table
= (*ctab_handle
)->ctTable
;
1884 ct_size
= (*ctab_handle
)->ctSize
;
1885 while (ct_size
> -1)
1887 if (ct_table
->value
== 0)
1889 ct_table
->rgb
= bg_color
;
1890 CTabChanged (ctab_handle
);
1891 SetWinColor (w
, (WCTabHandle
) ctab_handle
);
1899 /* Flush display of frame F, or of all frames if F is null. */
1905 #if TARGET_API_MAC_CARBON
1908 mac_prepare_for_quickdraw (f
);
1911 QDFlushPortBuffer (GetWindowPort (FRAME_MAC_WINDOW (f
)), NULL
);
1913 QDFlushPortBuffer (GetQDGlobalsThePort (), NULL
);
1919 /* Remove calls to XFlush by defining XFlush to an empty replacement.
1920 Calls to XFlush should be unnecessary because the X output buffer
1921 is flushed automatically as needed by calls to XPending,
1922 XNextEvent, or XWindowEvent according to the XFlush man page.
1923 XTread_socket calls XPending. Removing XFlush improves
1926 #define XFlush(DISPLAY) (void) 0
1930 mac_flush_display_optional (f
)
1934 mac_prepare_for_quickdraw (f
);
1939 /***********************************************************************
1940 Starting and ending an update
1941 ***********************************************************************/
1943 /* Start an update of frame F. This function is installed as a hook
1944 for update_begin, i.e. it is called when update_begin is called.
1945 This function is called prior to calls to x_update_window_begin for
1946 each window being updated. */
1952 #if TARGET_API_MAC_CARBON
1953 /* During update of a frame, availability of input events is
1954 periodically checked with ReceiveNextEvent if
1955 redisplay-dont-pause is nil. That normally flushes window buffer
1956 changes for every check, and thus screen update looks waving even
1957 if no input is available. So we disable screen updates during
1958 update of a frame. */
1960 DisableScreenUpdates ();
1966 /* Start update of window W. Set the global variable updated_window
1967 to the window being updated and set output_cursor to the cursor
1971 x_update_window_begin (w
)
1974 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1975 struct mac_display_info
*display_info
= FRAME_MAC_DISPLAY_INFO (f
);
1978 set_output_cursor (&w
->cursor
);
1982 if (f
== display_info
->mouse_face_mouse_frame
)
1984 /* Don't do highlighting for mouse motion during the update. */
1985 display_info
->mouse_face_defer
= 1;
1987 /* If F needs to be redrawn, simply forget about any prior mouse
1989 if (FRAME_GARBAGED_P (f
))
1990 display_info
->mouse_face_window
= Qnil
;
1992 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
1993 their mouse_face_p flag set, which means that they are always
1994 unequal to rows in a desired matrix which never have that
1995 flag set. So, rows containing mouse-face glyphs are never
1996 scrolled, and we don't have to switch the mouse highlight off
1997 here to prevent it from being scrolled. */
1999 /* Can we tell that this update does not affect the window
2000 where the mouse highlight is? If so, no need to turn off.
2001 Likewise, don't do anything if the frame is garbaged;
2002 in that case, the frame's current matrix that we would use
2003 is all wrong, and we will redisplay that line anyway. */
2004 if (!NILP (display_info
->mouse_face_window
)
2005 && w
== XWINDOW (display_info
->mouse_face_window
))
2009 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
2010 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
2013 if (i
< w
->desired_matrix
->nrows
)
2014 clear_mouse_face (display_info
);
2023 /* Draw a vertical window border from (x,y0) to (x,y1) */
2026 mac_draw_vertical_window_border (w
, x
, y0
, y1
)
2030 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2033 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
2035 XSetForeground (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->normal_gc
,
2038 mac_draw_line (f
, f
->output_data
.mac
->normal_gc
, x
, y0
, x
, y1
);
2041 /* End update of window W (which is equal to updated_window).
2043 Draw vertical borders between horizontally adjacent windows, and
2044 display W's cursor if CURSOR_ON_P is non-zero.
2046 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
2047 glyphs in mouse-face were overwritten. In that case we have to
2048 make sure that the mouse-highlight is properly redrawn.
2050 W may be a menu bar pseudo-window in case we don't have X toolkit
2051 support. Such windows don't have a cursor, so don't display it
2055 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
2057 int cursor_on_p
, mouse_face_overwritten_p
;
2059 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (XFRAME (w
->frame
));
2061 if (!w
->pseudo_window_p
)
2066 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
2068 output_cursor
.x
, output_cursor
.y
);
2070 if (draw_window_fringes (w
, 1))
2071 x_draw_vertical_border (w
);
2076 /* If a row with mouse-face was overwritten, arrange for
2077 XTframe_up_to_date to redisplay the mouse highlight. */
2078 if (mouse_face_overwritten_p
)
2080 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
2081 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
2082 dpyinfo
->mouse_face_window
= Qnil
;
2085 updated_window
= NULL
;
2089 /* End update of frame F. This function is installed as a hook in
2096 /* Mouse highlight may be displayed again. */
2097 FRAME_MAC_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
2100 #if TARGET_API_MAC_CARBON
2101 EnableScreenUpdates ();
2103 XFlush (FRAME_MAC_DISPLAY (f
));
2108 /* This function is called from various places in xdisp.c whenever a
2109 complete update has been performed. The global variable
2110 updated_window is not available here. */
2113 XTframe_up_to_date (f
)
2116 if (FRAME_MAC_P (f
))
2118 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
2120 if (dpyinfo
->mouse_face_deferred_gc
2121 || f
== dpyinfo
->mouse_face_mouse_frame
)
2124 if (dpyinfo
->mouse_face_mouse_frame
)
2125 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
2126 dpyinfo
->mouse_face_mouse_x
,
2127 dpyinfo
->mouse_face_mouse_y
);
2128 dpyinfo
->mouse_face_deferred_gc
= 0;
2135 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
2136 arrow bitmaps, or clear the fringes if no bitmaps are required
2137 before DESIRED_ROW is made current. The window being updated is
2138 found in updated_window. This function is called from
2139 update_window_line only if it is known that there are differences
2140 between bitmaps to be drawn between current row and DESIRED_ROW. */
2143 x_after_update_window_line (desired_row
)
2144 struct glyph_row
*desired_row
;
2146 struct window
*w
= updated_window
;
2152 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
2153 desired_row
->redraw_fringe_bitmaps_p
= 1;
2155 /* When a window has disappeared, make sure that no rest of
2156 full-width rows stays visible in the internal border. Could
2157 check here if updated_window is the leftmost/rightmost window,
2158 but I guess it's not worth doing since vertically split windows
2159 are almost never used, internal border is rarely set, and the
2160 overhead is very small. */
2161 if (windows_or_buffers_changed
2162 && desired_row
->full_width_p
2163 && (f
= XFRAME (w
->frame
),
2164 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
2166 && (height
= desired_row
->visible_height
,
2169 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
2171 /* Internal border is drawn below the tool bar. */
2172 if (WINDOWP (f
->tool_bar_window
)
2173 && w
== XWINDOW (f
->tool_bar_window
))
2177 mac_clear_area (f
, 0, y
, width
, height
);
2178 mac_clear_area (f
, FRAME_PIXEL_WIDTH (f
) - width
, y
, width
, height
);
2184 /* Draw the bitmap WHICH in one of the left or right fringes of
2185 window W. ROW is the glyph row for which to display the bitmap; it
2186 determines the vertical position at which the bitmap has to be
2190 x_draw_fringe_bitmap (w
, row
, p
)
2192 struct glyph_row
*row
;
2193 struct draw_fringe_bitmap_params
*p
;
2195 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2196 Display
*display
= FRAME_MAC_DISPLAY (f
);
2197 struct face
*face
= p
->face
;
2199 int overlay_p
= p
->overlay_p
;
2204 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
2206 #if 0 /* MAC_TODO: stipple */
2207 /* In case the same realized face is used for fringes and
2208 for something displayed in the text (e.g. face `region' on
2209 mono-displays, the fill style may have been changed to
2210 FillSolid in x_draw_glyph_string_background. */
2212 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
2214 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
2217 /* If the fringe is adjacent to the left (right) scroll bar of a
2218 leftmost (rightmost, respectively) window, then extend its
2219 background to the gap between the fringe and the bar. */
2220 if ((WINDOW_LEFTMOST_P (w
)
2221 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
2222 || (WINDOW_RIGHTMOST_P (w
)
2223 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
2225 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
2229 int left
= WINDOW_SCROLL_BAR_AREA_X (w
);
2230 int width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
2231 * FRAME_COLUMN_WIDTH (f
));
2234 && (left
+ width
== p
->x
2235 || p
->x
+ p
->wd
== left
))
2237 /* Bitmap fills the fringe and we need background
2239 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
2243 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
2245 ny
= row
->visible_height
;
2250 if (left
+ width
== bx
)
2252 bx
= left
+ sb_width
;
2253 nx
+= width
- sb_width
;
2255 else if (bx
+ nx
== left
)
2256 nx
+= width
- sb_width
;
2263 mac_erase_rectangle (f
, face
->gc
, bx
, by
, nx
, ny
);
2264 /* The fringe background has already been filled. */
2268 #if 0 /* MAC_TODO: stipple */
2270 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
2273 #endif /* MAC_OSX */
2275 /* Must clip because of partially visible lines. */
2276 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
2279 /* Adjust position of "bottom aligned" bitmap on partially
2280 visible last row. */
2282 int oldVH
= row
->visible_height
;
2283 row
->visible_height
= p
->h
;
2284 row
->y
-= rowY
- p
->y
;
2285 x_clip_to_row (w
, row
, -1, face
->gc
);
2287 row
->visible_height
= oldVH
;
2290 x_clip_to_row (w
, row
, -1, face
->gc
);
2293 if (p
->bx
>= 0 && !p
->overlay_p
)
2295 #if 0 /* MAC_TODO: stipple */
2296 /* In case the same realized face is used for fringes and
2297 for something displayed in the text (e.g. face `region' on
2298 mono-displays, the fill style may have been changed to
2299 FillSolid in x_draw_glyph_string_background. */
2301 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
2303 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
2306 mac_erase_rectangle (f
, face
->gc
, p
->bx
, p
->by
, p
->nx
, p
->ny
);
2308 #if 0 /* MAC_TODO: stipple */
2310 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
2313 #endif /* !MAC_OSX */
2317 && p
->which
< max_fringe_bmp
2323 XGetGCValues (display
, face
->gc
, GCForeground
, &gcv
);
2324 XSetForeground (display
, face
->gc
,
2326 ? (p
->overlay_p
? face
->background
2327 : f
->output_data
.mac
->cursor_pixel
)
2328 : face
->foreground
));
2330 mac_draw_cg_image (fringe_bmp
[p
->which
], f
, face
->gc
, 0, p
->dh
,
2331 p
->wd
, p
->h
, p
->x
, p
->y
, overlay_p
);
2333 mac_draw_bitmap (f
, face
->gc
, p
->x
, p
->y
,
2334 p
->wd
, p
->h
, p
->bits
+ p
->dh
, overlay_p
);
2336 XSetForeground (display
, face
->gc
, gcv
.foreground
);
2339 mac_reset_clip_rectangles (display
, face
->gc
);
2344 mac_define_fringe_bitmap (which
, bits
, h
, wd
)
2346 unsigned short *bits
;
2350 CGDataProviderRef provider
;
2352 if (which
>= max_fringe_bmp
)
2355 max_fringe_bmp
= which
+ 20;
2356 fringe_bmp
= (CGImageRef
*) xrealloc (fringe_bmp
, max_fringe_bmp
* sizeof (CGImageRef
));
2357 while (i
< max_fringe_bmp
)
2358 fringe_bmp
[i
++] = 0;
2361 for (i
= 0; i
< h
; i
++)
2363 provider
= CGDataProviderCreateWithData (NULL
, bits
,
2364 sizeof (unsigned short) * h
, NULL
);
2367 fringe_bmp
[which
] = CGImageMaskCreate (wd
, h
, 1, 1,
2368 sizeof (unsigned short),
2370 CGDataProviderRelease (provider
);
2375 mac_destroy_fringe_bitmap (which
)
2378 if (which
>= max_fringe_bmp
)
2381 if (fringe_bmp
[which
])
2382 CGImageRelease (fringe_bmp
[which
]);
2383 fringe_bmp
[which
] = 0;
2388 /* This is called when starting Emacs and when restarting after
2389 suspend. When starting Emacs, no window is mapped. And nothing
2390 must be done to Emacs's own window if it is suspended (though that
2394 XTset_terminal_modes (struct terminal
*t
)
2398 /* This is called when exiting or suspending Emacs. Exiting will make
2399 the windows go away, and suspending requires no action. */
2402 XTreset_terminal_modes (struct terminal
*t
)
2408 /***********************************************************************
2410 ***********************************************************************/
2412 /* Function prototypes of this page. */
2414 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
2415 static int mac_encode_char
P_ ((int, XChar2b
*, struct font_info
*, int *));
2419 pcm_init (pcm
, count
)
2423 bzero (pcm
, sizeof (XCharStruct
) * count
);
2424 while (--count
>= 0)
2426 pcm
->descent
= PCM_INVALID
;
2431 static enum pcm_status
2432 pcm_get_status (pcm
)
2433 const XCharStruct
*pcm
;
2435 int height
= pcm
->ascent
+ pcm
->descent
;
2437 /* Negative height means some special status. */
2438 return height
>= 0 ? PCM_VALID
: height
;
2441 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
2442 is not contained in the font. */
2444 static INLINE XCharStruct
*
2445 x_per_char_metric (font
, char2b
)
2449 /* The result metric information. */
2450 XCharStruct
*pcm
= NULL
;
2452 xassert (font
&& char2b
);
2455 if (font
->mac_style
)
2457 XCharStruct
**row
= font
->bounds
.rows
+ char2b
->byte1
;
2461 *row
= xmalloc (sizeof (XCharStruct
) * 0x100);
2462 pcm_init (*row
, 0x100);
2464 pcm
= *row
+ char2b
->byte2
;
2465 if (pcm_get_status (pcm
) != PCM_VALID
)
2468 mac_query_char_extents (font
->mac_style
,
2469 (char2b
->byte1
<< 8) + char2b
->byte2
,
2470 NULL
, NULL
, pcm
, NULL
);
2477 if (font
->bounds
.per_char
!= NULL
)
2479 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
2481 /* min_char_or_byte2 specifies the linear character index
2482 corresponding to the first element of the per_char array,
2483 max_char_or_byte2 is the index of the last character. A
2484 character with non-zero CHAR2B->byte1 is not in the font.
2485 A character with byte2 less than min_char_or_byte2 or
2486 greater max_char_or_byte2 is not in the font. */
2487 if (char2b
->byte1
== 0
2488 && char2b
->byte2
>= font
->min_char_or_byte2
2489 && char2b
->byte2
<= font
->max_char_or_byte2
)
2490 pcm
= font
->bounds
.per_char
2491 + (char2b
->byte2
- font
->min_char_or_byte2
);
2495 /* If either min_byte1 or max_byte1 are nonzero, both
2496 min_char_or_byte2 and max_char_or_byte2 are less than
2497 256, and the 2-byte character index values corresponding
2498 to the per_char array element N (counting from 0) are:
2500 byte1 = N/D + min_byte1
2501 byte2 = N\D + min_char_or_byte2
2505 D = max_char_or_byte2 - min_char_or_byte2 + 1
2506 / = integer division
2507 \ = integer modulus */
2508 if (char2b
->byte1
>= font
->min_byte1
2509 && char2b
->byte1
<= font
->max_byte1
2510 && char2b
->byte2
>= font
->min_char_or_byte2
2511 && char2b
->byte2
<= font
->max_char_or_byte2
)
2513 pcm
= (font
->bounds
.per_char
2514 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
2515 * (char2b
->byte1
- font
->min_byte1
))
2516 + (char2b
->byte2
- font
->min_char_or_byte2
));
2522 /* If the per_char pointer is null, all glyphs between the first
2523 and last character indexes inclusive have the same
2524 information, as given by both min_bounds and max_bounds. */
2525 if (char2b
->byte2
>= font
->min_char_or_byte2
2526 && char2b
->byte2
<= font
->max_char_or_byte2
)
2527 pcm
= &font
->max_bounds
;
2533 return ((pcm
== NULL
2535 #if 0 /* Show hollow boxes for zero-width glyphs such as combining diacritics. */
2536 && (pcm
->rbearing
- pcm
->lbearing
) == 0
2545 static XCharStruct
*
2546 mac_per_char_metric (font
, char2b
, font_type
)
2551 return x_per_char_metric (font
, char2b
);
2555 Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
2556 the two-byte form of C. Encoding is returned in *CHAR2B. */
2559 mac_encode_char (c
, char2b
, font_info
, two_byte_p
)
2562 struct font_info
*font_info
;
2565 int charset
= CHAR_CHARSET (c
);
2566 XFontStruct
*font
= font_info
->font
;
2568 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
2569 This may be either a program in a special encoder language or a
2571 if (font_info
->font_encoder
)
2573 /* It's a program. */
2574 struct ccl_program
*ccl
= font_info
->font_encoder
;
2576 check_ccl_update (ccl
);
2577 if (CHARSET_DIMENSION (charset
) == 1)
2579 ccl
->reg
[0] = charset
;
2580 ccl
->reg
[1] = char2b
->byte2
;
2585 ccl
->reg
[0] = charset
;
2586 ccl
->reg
[1] = char2b
->byte1
;
2587 ccl
->reg
[2] = char2b
->byte2
;
2590 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
2592 /* We assume that MSBs are appropriately set/reset by CCL
2594 if (font
->max_byte1
== 0) /* 1-byte font */
2595 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
2597 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
2599 else if (font_info
->encoding
[charset
])
2601 /* Fixed encoding scheme. See fontset.h for the meaning of the
2602 encoding numbers. */
2603 int enc
= font_info
->encoding
[charset
];
2605 if ((enc
== 1 || enc
== 2)
2606 && CHARSET_DIMENSION (charset
) == 2)
2607 char2b
->byte1
|= 0x80;
2609 if (enc
== 1 || enc
== 3)
2610 char2b
->byte2
|= 0x80;
2616 ENCODE_SJIS (char2b
->byte1
, char2b
->byte2
, sjis1
, sjis2
);
2617 char2b
->byte1
= sjis1
;
2618 char2b
->byte2
= sjis2
;
2623 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
2625 return FONT_TYPE_UNKNOWN
;
2630 /***********************************************************************
2632 ***********************************************************************/
2636 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2637 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2638 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2640 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2641 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2642 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2643 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2644 static void mac_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2645 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2646 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2647 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2648 /*static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap,
2649 unsigned long *, double, int));*/
2650 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2651 double, int, unsigned long));
2652 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2653 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2654 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2655 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2656 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2658 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2659 int, int, int, int, int, int,
2661 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2662 int, int, int, Rect
*));
2665 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2669 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2674 struct glyph_string
*s
;
2676 if (s
->font
== FRAME_FONT (s
->f
)
2677 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2678 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2680 s
->gc
= s
->f
->output_data
.mac
->cursor_gc
;
2683 /* Cursor on non-default face: must merge. */
2687 xgcv
.background
= s
->f
->output_data
.mac
->cursor_pixel
;
2688 xgcv
.foreground
= s
->face
->background
;
2690 /* If the glyph would be invisible, try a different foreground. */
2691 if (xgcv
.foreground
== xgcv
.background
)
2692 xgcv
.foreground
= s
->face
->foreground
;
2693 if (xgcv
.foreground
== xgcv
.background
)
2694 xgcv
.foreground
= s
->f
->output_data
.mac
->cursor_foreground_pixel
;
2695 if (xgcv
.foreground
== xgcv
.background
)
2696 xgcv
.foreground
= s
->face
->foreground
;
2698 /* Make sure the cursor is distinct from text in this face. */
2699 if (xgcv
.background
== s
->face
->background
2700 && xgcv
.foreground
== s
->face
->foreground
)
2702 xgcv
.background
= s
->face
->foreground
;
2703 xgcv
.foreground
= s
->face
->background
;
2706 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2707 xgcv
.font
= s
->font
;
2708 mask
= GCForeground
| GCBackground
| GCFont
;
2710 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2711 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2714 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2715 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2717 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2722 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2725 x_set_mouse_face_gc (s
)
2726 struct glyph_string
*s
;
2731 /* What face has to be used last for the mouse face? */
2732 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2733 face
= FACE_FROM_ID (s
->f
, face_id
);
2735 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2737 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2738 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2740 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2741 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2742 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2744 /* If font in this face is same as S->font, use it. */
2745 if (s
->font
== s
->face
->font
)
2746 s
->gc
= s
->face
->gc
;
2749 /* Otherwise construct scratch_cursor_gc with values from FACE
2754 xgcv
.background
= s
->face
->background
;
2755 xgcv
.foreground
= s
->face
->foreground
;
2756 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2757 xgcv
.font
= s
->font
;
2758 mask
= GCForeground
| GCBackground
| GCFont
;
2760 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2761 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2764 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2765 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2767 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2770 xassert (s
->gc
!= 0);
2774 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2775 Faces to use in the mode line have already been computed when the
2776 matrix was built, so there isn't much to do, here. */
2779 x_set_mode_line_face_gc (s
)
2780 struct glyph_string
*s
;
2782 s
->gc
= s
->face
->gc
;
2786 /* Set S->gc of glyph string S for drawing that glyph string. Set
2787 S->stippled_p to a non-zero value if the face of S has a stipple
2791 x_set_glyph_string_gc (s
)
2792 struct glyph_string
*s
;
2794 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2796 if (s
->hl
== DRAW_NORMAL_TEXT
)
2798 s
->gc
= s
->face
->gc
;
2799 s
->stippled_p
= s
->face
->stipple
!= 0;
2801 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2803 x_set_mode_line_face_gc (s
);
2804 s
->stippled_p
= s
->face
->stipple
!= 0;
2806 else if (s
->hl
== DRAW_CURSOR
)
2808 x_set_cursor_gc (s
);
2811 else if (s
->hl
== DRAW_MOUSE_FACE
)
2813 x_set_mouse_face_gc (s
);
2814 s
->stippled_p
= s
->face
->stipple
!= 0;
2816 else if (s
->hl
== DRAW_IMAGE_RAISED
2817 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2819 s
->gc
= s
->face
->gc
;
2820 s
->stippled_p
= s
->face
->stipple
!= 0;
2824 s
->gc
= s
->face
->gc
;
2825 s
->stippled_p
= s
->face
->stipple
!= 0;
2828 /* GC must have been set. */
2829 xassert (s
->gc
!= 0);
2833 /* Set clipping for output of glyph string S. S may be part of a mode
2834 line or menu if we don't have X toolkit support. */
2837 x_set_glyph_string_clipping (s
)
2838 struct glyph_string
*s
;
2840 Rect rects
[MAX_CLIP_RECTS
];
2843 n
= get_glyph_string_clip_rects (s
, rects
, MAX_CLIP_RECTS
);
2844 mac_set_clip_rectangles (s
->display
, s
->gc
, rects
, n
);
2849 Compute left and right overhang of glyph string S. If S is a glyph
2850 string for a composition, assume overhangs don't exist. */
2853 mac_compute_glyph_string_overhangs (s
)
2854 struct glyph_string
*s
;
2856 if (!(s
->cmp
== NULL
2857 && s
->first_glyph
->type
== CHAR_GLYPH
))
2862 || s
->font
->mac_style
2868 mac_text_extents_16 (s
->font
, s
->char2b
, s
->nchars
, &cs
);
2869 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2870 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2875 MacFontStruct
*font
= s
->font
;
2878 mac_prepare_for_quickdraw (s
->f
);
2880 SetPortWindowPort (FRAME_MAC_WINDOW (s
->f
));
2882 TextFont (font
->mac_fontnum
);
2883 TextSize (font
->mac_fontsize
);
2884 TextFace (font
->mac_fontface
);
2886 QDTextBounds (s
->nchars
* 2, (char *)s
->char2b
, &r
);
2888 s
->right_overhang
= r
.right
> s
->width
? r
.right
- s
->width
: 0;
2889 s
->left_overhang
= r
.left
< 0 ? -r
.left
: 0;
2894 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
2897 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
2898 struct glyph_string
*s
;
2901 mac_erase_rectangle (s
->f
, s
->gc
, x
, y
, w
, h
);
2905 /* Draw the background of glyph_string S. If S->background_filled_p
2906 is non-zero don't draw it. FORCE_P non-zero means draw the
2907 background even if it wouldn't be drawn normally. This is used
2908 when a string preceding S draws into the background of S, or S
2909 contains the first component of a composition. */
2912 x_draw_glyph_string_background (s
, force_p
)
2913 struct glyph_string
*s
;
2916 /* Nothing to do if background has already been drawn or if it
2917 shouldn't be drawn in the first place. */
2918 if (!s
->background_filled_p
)
2920 int box_line_width
= max (s
->face
->box_line_width
, 0);
2922 #if 0 /* MAC_TODO: stipple */
2925 /* Fill background with a stipple pattern. */
2926 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2927 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
2928 s
->y
+ box_line_width
,
2929 s
->background_width
,
2930 s
->height
- 2 * box_line_width
);
2931 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2932 s
->background_filled_p
= 1;
2936 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
2937 || s
->font_not_found_p
2938 || s
->extends_to_end_of_line_p
2941 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
2942 s
->background_width
,
2943 s
->height
- 2 * box_line_width
);
2944 s
->background_filled_p
= 1;
2950 /* Draw the foreground of glyph string S. */
2953 x_draw_glyph_string_foreground (s
)
2954 struct glyph_string
*s
;
2958 /* If first glyph of S has a left box line, start drawing the text
2959 of S to the right of that box line. */
2960 if (s
->face
->box
!= FACE_NO_BOX
2961 && s
->first_glyph
->left_box_line_p
)
2962 x
= s
->x
+ abs (s
->face
->box_line_width
);
2966 /* Draw characters of S as rectangles if S's font could not be
2968 if (s
->font_not_found_p
)
2970 for (i
= 0; i
< s
->nchars
; ++i
)
2972 struct glyph
*g
= s
->first_glyph
+ i
;
2973 mac_draw_rectangle (s
->f
, s
->gc
, x
, s
->y
,
2974 g
->pixel_width
- 1, s
->height
- 1);
2975 x
+= g
->pixel_width
;
2980 char *char1b
= (char *) s
->char2b
;
2981 int boff
= s
->font_info
->baseline_offset
;
2983 if (s
->font_info
->vertical_centering
)
2984 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
2986 /* If we can use 8-bit functions, condense S->char2b. */
2989 && GC_FONT (s
->gc
)->mac_style
== NULL
2992 for (i
= 0; i
< s
->nchars
; ++i
)
2993 char1b
[i
] = s
->char2b
[i
].byte2
;
2995 /* Draw text with XDrawString if background has already been
2996 filled. Otherwise, use XDrawImageString. (Note that
2997 XDrawImageString is usually faster than XDrawString.) Always
2998 use XDrawImageString when drawing the cursor so that there is
2999 no chance that characters under a box cursor are invisible. */
3001 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3002 bg_width
= 0; /* Corresponds to XDrawString. */
3004 bg_width
= s
->background_width
; /* Corresponds to XDrawImageString. */
3008 || GC_FONT (s
->gc
)->mac_style
3011 #if USE_CG_TEXT_DRAWING
3013 && mac_draw_image_string_cg (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
3014 s
->char2b
, s
->nchars
, bg_width
,
3015 s
->face
->overstrike
))
3019 mac_draw_image_string_16 (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
3020 s
->char2b
, s
->nchars
, bg_width
,
3021 s
->face
->overstrike
);
3023 mac_draw_image_string (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
3024 char1b
, s
->nchars
, bg_width
,
3025 s
->face
->overstrike
);
3029 /* Draw the foreground of composite glyph string S. */
3032 x_draw_composite_glyph_string_foreground (s
)
3033 struct glyph_string
*s
;
3037 /* If first glyph of S has a left box line, start drawing the text
3038 of S to the right of that box line. */
3039 if (s
->face
->box
!= FACE_NO_BOX
3040 && s
->first_glyph
->left_box_line_p
)
3041 x
= s
->x
+ abs (s
->face
->box_line_width
);
3045 /* S is a glyph string for a composition. S->gidx is the index of
3046 the first character drawn for glyphs of this composition.
3047 S->gidx == 0 means we are drawing the very first character of
3048 this composition. */
3050 /* Draw a rectangle for the composition if the font for the very
3051 first character of the composition could not be loaded. */
3052 if (s
->font_not_found_p
)
3055 mac_draw_rectangle (s
->f
, s
->gc
, x
, s
->y
,
3056 s
->width
- 1, s
->height
- 1);
3060 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3061 if (mac_per_char_metric (GC_FONT (s
->gc
), s
->char2b
+ i
, 0) == NULL
)
3062 /* This is a nonexistent or zero-width glyph such as a
3063 combining diacritic. Draw a rectangle. */
3064 mac_draw_rectangle (s
->f
, s
->gc
,
3065 x
+ s
->cmp
->offsets
[s
->gidx
* 2], s
->y
,
3066 FONT_WIDTH (GC_FONT (s
->gc
)) - 1, s
->height
- 1);
3068 mac_draw_image_string_16 (s
->f
, s
->gc
,
3069 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3070 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3071 s
->char2b
+ i
, 1, 0, s
->face
->overstrike
);
3076 #ifdef USE_X_TOOLKIT
3078 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3081 /* Return the frame on which widget WIDGET is used.. Abort if frame
3082 cannot be determined. */
3084 static struct frame
*
3085 x_frame_of_widget (widget
)
3088 struct x_display_info
*dpyinfo
;
3092 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3094 /* Find the top-level shell of the widget. Note that this function
3095 can be called when the widget is not yet realized, so XtWindow
3096 (widget) == 0. That's the reason we can't simply use
3097 x_any_window_to_frame. */
3098 while (!XtIsTopLevelShell (widget
))
3099 widget
= XtParent (widget
);
3101 /* Look for a frame with that top-level widget. Allocate the color
3102 on that frame to get the right gamma correction value. */
3103 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3104 if (GC_FRAMEP (XCAR (tail
))
3105 && (f
= XFRAME (XCAR (tail
)),
3106 (f
->output_data
.nothing
!= 1
3107 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3108 && f
->output_data
.x
->widget
== widget
)
3115 /* Allocate the color COLOR->pixel on the screen and display of
3116 widget WIDGET in colormap CMAP. If an exact match cannot be
3117 allocated, try the nearest color available. Value is non-zero
3118 if successful. This is called from lwlib. */
3121 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3126 struct frame
*f
= x_frame_of_widget (widget
);
3127 return x_alloc_nearest_color (f
, cmap
, color
);
3131 #endif /* USE_X_TOOLKIT */
3133 #if 0 /* MAC_TODO */
3135 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
3136 CMAP. If an exact match can't be allocated, try the nearest color
3137 available. Value is non-zero if successful. Set *COLOR to the
3141 x_alloc_nearest_color (f
, cmap
, color
)
3146 Display
*display
= FRAME_X_DISPLAY (f
);
3147 Screen
*screen
= FRAME_X_SCREEN (f
);
3150 gamma_correct (f
, color
);
3151 rc
= XAllocColor (display
, cmap
, color
);
3154 /* If we got to this point, the colormap is full, so we're going
3155 to try to get the next closest color. The algorithm used is
3156 a least-squares matching, which is what X uses for closest
3157 color matching with StaticColor visuals. */
3159 unsigned long nearest_delta
= ~0;
3160 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3161 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
3163 for (i
= 0; i
< ncells
; ++i
)
3165 XQueryColors (display
, cmap
, cells
, ncells
);
3167 for (nearest
= i
= 0; i
< ncells
; ++i
)
3169 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3170 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3171 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3172 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3174 if (delta
< nearest_delta
)
3177 nearest_delta
= delta
;
3181 color
->red
= cells
[nearest
].red
;
3182 color
->green
= cells
[nearest
].green
;
3183 color
->blue
= cells
[nearest
].blue
;
3184 rc
= XAllocColor (display
, cmap
, color
);
3187 #ifdef DEBUG_X_COLORS
3189 register_color (color
->pixel
);
3190 #endif /* DEBUG_X_COLORS */
3196 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3197 It's necessary to do this instead of just using PIXEL directly to
3198 get color reference counts right. */
3201 x_copy_color (f
, pixel
)
3203 unsigned long pixel
;
3207 color
.pixel
= pixel
;
3209 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3210 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3212 #ifdef DEBUG_X_COLORS
3213 register_color (pixel
);
3219 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3220 It's necessary to do this instead of just using PIXEL directly to
3221 get color reference counts right. */
3224 x_copy_dpy_color (dpy
, cmap
, pixel
)
3227 unsigned long pixel
;
3231 color
.pixel
= pixel
;
3233 XQueryColor (dpy
, cmap
, &color
);
3234 XAllocColor (dpy
, cmap
, &color
);
3236 #ifdef DEBUG_X_COLORS
3237 register_color (pixel
);
3242 #endif /* MAC_TODO */
3245 /* Brightness beyond which a color won't have its highlight brightness
3248 Nominally, highlight colors for `3d' faces are calculated by
3249 brightening an object's color by a constant scale factor, but this
3250 doesn't yield good results for dark colors, so for colors who's
3251 brightness is less than this value (on a scale of 0-255) have to
3252 use an additional additive factor.
3254 The value here is set so that the default menu-bar/mode-line color
3255 (grey75) will not have its highlights changed at all. */
3256 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
3259 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
3260 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3261 If this produces the same color as COLOR, try a color where all RGB
3262 values have DELTA added. Return the allocated color in *COLOR.
3263 DISPLAY is the X display, CMAP is the colormap to operate on.
3264 Value is non-zero if successful. */
3267 mac_alloc_lighter_color (f
, color
, factor
, delta
)
3269 unsigned long *color
;
3276 /* On Mac, RGB values are 0-255, not 0-65535, so scale delta. */
3279 /* Change RGB values by specified FACTOR. Avoid overflow! */
3280 xassert (factor
>= 0);
3281 new = RGB_TO_ULONG (min (0xff, (int) (factor
* RED_FROM_ULONG (*color
))),
3282 min (0xff, (int) (factor
* GREEN_FROM_ULONG (*color
))),
3283 min (0xff, (int) (factor
* BLUE_FROM_ULONG (*color
))));
3285 /* Calculate brightness of COLOR. */
3286 bright
= (2 * RED_FROM_ULONG (*color
) + 3 * GREEN_FROM_ULONG (*color
)
3287 + BLUE_FROM_ULONG (*color
)) / 6;
3289 /* We only boost colors that are darker than
3290 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3291 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3292 /* Make an additive adjustment to NEW, because it's dark enough so
3293 that scaling by FACTOR alone isn't enough. */
3295 /* How far below the limit this color is (0 - 1, 1 being darker). */
3296 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3297 /* The additive adjustment. */
3298 int min_delta
= delta
* dimness
* factor
/ 2;
3301 new = RGB_TO_ULONG (max (0, min (0xff, (int) (RED_FROM_ULONG (*color
)) - min_delta
)),
3302 max (0, min (0xff, (int) (GREEN_FROM_ULONG (*color
)) - min_delta
)),
3303 max (0, min (0xff, (int) (BLUE_FROM_ULONG (*color
)) - min_delta
)));
3305 new = RGB_TO_ULONG (max (0, min (0xff, (int) (min_delta
+ RED_FROM_ULONG (*color
)))),
3306 max (0, min (0xff, (int) (min_delta
+ GREEN_FROM_ULONG (*color
)))),
3307 max (0, min (0xff, (int) (min_delta
+ BLUE_FROM_ULONG (*color
)))));
3311 new = RGB_TO_ULONG (max (0, min (0xff, (int) (delta
+ RED_FROM_ULONG (*color
)))),
3312 max (0, min (0xff, (int) (delta
+ GREEN_FROM_ULONG (*color
)))),
3313 max (0, min (0xff, (int) (delta
+ BLUE_FROM_ULONG (*color
)))));
3315 /* MAC_TODO: Map to palette and retry with delta if same? */
3316 /* MAC_TODO: Free colors (if using palette)? */
3327 /* Set up the foreground color for drawing relief lines of glyph
3328 string S. RELIEF is a pointer to a struct relief containing the GC
3329 with which lines will be drawn. Use a color that is FACTOR or
3330 DELTA lighter or darker than the relief's background which is found
3331 in S->f->output_data.x->relief_background. If such a color cannot
3332 be allocated, use DEFAULT_PIXEL, instead. */
3335 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3337 struct relief
*relief
;
3340 unsigned long default_pixel
;
3343 struct mac_output
*di
= f
->output_data
.mac
;
3344 unsigned long mask
= GCForeground
;
3345 unsigned long pixel
;
3346 unsigned long background
= di
->relief_background
;
3347 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
3349 /* MAC_TODO: Free colors (if using palette)? */
3351 /* Allocate new color. */
3352 xgcv
.foreground
= default_pixel
;
3354 if (dpyinfo
->n_planes
!= 1
3355 && mac_alloc_lighter_color (f
, &pixel
, factor
, delta
))
3357 relief
->allocated_p
= 1;
3358 xgcv
.foreground
= relief
->pixel
= pixel
;
3361 if (relief
->gc
== 0)
3363 #if 0 /* MAC_TODO: stipple */
3364 xgcv
.stipple
= dpyinfo
->gray
;
3367 relief
->gc
= XCreateGC (NULL
, FRAME_MAC_WINDOW (f
), mask
, &xgcv
);
3370 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
3374 /* Set up colors for the relief lines around glyph string S. */
3377 x_setup_relief_colors (s
)
3378 struct glyph_string
*s
;
3380 struct mac_output
*di
= s
->f
->output_data
.mac
;
3381 unsigned long color
;
3383 if (s
->face
->use_box_color_for_shadows_p
)
3384 color
= s
->face
->box_color
;
3385 else if (s
->first_glyph
->type
== IMAGE_GLYPH
3387 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
3388 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
3393 /* Get the background color of the face. */
3394 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3395 color
= xgcv
.background
;
3398 if (di
->white_relief
.gc
== 0
3399 || color
!= di
->relief_background
)
3401 di
->relief_background
= color
;
3402 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3403 WHITE_PIX_DEFAULT (s
->f
));
3404 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3405 BLACK_PIX_DEFAULT (s
->f
));
3410 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3411 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3412 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3413 relief. LEFT_P non-zero means draw a relief on the left side of
3414 the rectangle. RIGHT_P non-zero means draw a relief on the right
3415 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3419 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3420 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
3422 int left_x
, top_y
, right_x
, bottom_y
, width
;
3423 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
3426 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
3431 gc
= f
->output_data
.mac
->white_relief
.gc
;
3433 gc
= f
->output_data
.mac
->black_relief
.gc
;
3434 mac_set_clip_rectangles (dpy
, gc
, clip_rect
, 1);
3438 for (i
= 0; i
< width
; ++i
)
3439 mac_draw_line (f
, gc
,
3440 left_x
+ i
* left_p
, top_y
+ i
,
3441 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3445 for (i
= 0; i
< width
; ++i
)
3446 mac_draw_line (f
, gc
,
3447 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
3449 mac_reset_clip_rectangles (dpy
, gc
);
3451 gc
= f
->output_data
.mac
->black_relief
.gc
;
3453 gc
= f
->output_data
.mac
->white_relief
.gc
;
3454 mac_set_clip_rectangles (dpy
, gc
, clip_rect
, 1);
3458 for (i
= 0; i
< width
; ++i
)
3459 mac_draw_line (f
, gc
,
3460 left_x
+ i
* left_p
, bottom_y
- i
,
3461 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3465 for (i
= 0; i
< width
; ++i
)
3466 mac_draw_line (f
, gc
,
3467 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3469 mac_reset_clip_rectangles (dpy
, gc
);
3473 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3474 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3475 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3476 left side of the rectangle. RIGHT_P non-zero means draw a line
3477 on the right side of the rectangle. CLIP_RECT is the clipping
3478 rectangle to use when drawing. */
3481 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3482 left_p
, right_p
, clip_rect
)
3483 struct glyph_string
*s
;
3484 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
3489 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3490 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3491 mac_set_clip_rectangles (s
->display
, s
->gc
, clip_rect
, 1);
3494 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, top_y
,
3495 right_x
- left_x
+ 1, width
);
3499 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, top_y
,
3500 width
, bottom_y
- top_y
+ 1);
3503 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, bottom_y
- width
+ 1,
3504 right_x
- left_x
+ 1, width
);
3508 mac_fill_rectangle (s
->f
, s
->gc
, right_x
- width
+ 1,
3509 top_y
, width
, bottom_y
- top_y
+ 1);
3511 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3512 mac_reset_clip_rectangles (s
->display
, s
->gc
);
3516 /* Draw a box around glyph string S. */
3519 x_draw_glyph_string_box (s
)
3520 struct glyph_string
*s
;
3522 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3523 int left_p
, right_p
;
3524 struct glyph
*last_glyph
;
3527 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
3528 ? WINDOW_RIGHT_EDGE_X (s
->w
)
3529 : window_box_right (s
->w
, s
->area
));
3531 /* The glyph that may have a right box line. */
3532 last_glyph
= (s
->cmp
|| s
->img
3534 : s
->first_glyph
+ s
->nchars
- 1);
3536 width
= abs (s
->face
->box_line_width
);
3537 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3539 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
3541 : min (last_x
, s
->x
+ s
->background_width
) - 1);
3543 bottom_y
= top_y
+ s
->height
- 1;
3545 left_p
= (s
->first_glyph
->left_box_line_p
3546 || (s
->hl
== DRAW_MOUSE_FACE
3548 || s
->prev
->hl
!= s
->hl
)));
3549 right_p
= (last_glyph
->right_box_line_p
3550 || (s
->hl
== DRAW_MOUSE_FACE
3552 || s
->next
->hl
!= s
->hl
)));
3554 get_glyph_string_clip_rect (s
, &clip_rect
);
3556 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3557 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3558 left_p
, right_p
, &clip_rect
);
3561 x_setup_relief_colors (s
);
3562 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3563 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
3568 /* Draw foreground of image glyph string S. */
3571 x_draw_image_foreground (s
)
3572 struct glyph_string
*s
;
3575 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
3577 /* If first glyph of S has a left box line, start drawing it to the
3578 right of that line. */
3579 if (s
->face
->box
!= FACE_NO_BOX
3580 && s
->first_glyph
->left_box_line_p
3582 x
+= abs (s
->face
->box_line_width
);
3584 /* If there is a margin around the image, adjust x- and y-position
3586 if (s
->slice
.x
== 0)
3587 x
+= s
->img
->hmargin
;
3588 if (s
->slice
.y
== 0)
3589 y
+= s
->img
->vmargin
;
3593 x_set_glyph_string_clipping (s
);
3596 mac_draw_cg_image (s
->img
->data
.ptr_val
,
3597 s
->f
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
3598 s
->slice
.width
, s
->slice
.height
, x
, y
, 1);
3602 mac_copy_area_with_mask (s
->img
->pixmap
, s
->img
->mask
,
3603 s
->f
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
3604 s
->slice
.width
, s
->slice
.height
, x
, y
);
3611 mac_copy_area (s
->img
->pixmap
,
3612 s
->f
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
3613 s
->slice
.width
, s
->slice
.height
, x
, y
);
3616 /* When the image has a mask, we can expect that at
3617 least part of a mouse highlight or a block cursor will
3618 be visible. If the image doesn't have a mask, make
3619 a block cursor visible by drawing a rectangle around
3620 the image. I believe it's looking better if we do
3621 nothing here for mouse-face. */
3622 if (s
->hl
== DRAW_CURSOR
)
3624 int r
= s
->img
->relief
;
3626 mac_draw_rectangle (s
->f
, s
->gc
, x
- r
, y
- r
,
3627 s
->slice
.width
+ r
*2 - 1,
3628 s
->slice
.height
+ r
*2 - 1);
3633 /* Draw a rectangle if image could not be loaded. */
3634 mac_draw_rectangle (s
->f
, s
->gc
, x
, y
,
3635 s
->slice
.width
- 1, s
->slice
.height
- 1);
3639 /* Draw a relief around the image glyph string S. */
3642 x_draw_image_relief (s
)
3643 struct glyph_string
*s
;
3645 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3648 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
3650 /* If first glyph of S has a left box line, start drawing it to the
3651 right of that line. */
3652 if (s
->face
->box
!= FACE_NO_BOX
3653 && s
->first_glyph
->left_box_line_p
3655 x
+= abs (s
->face
->box_line_width
);
3657 /* If there is a margin around the image, adjust x- and y-position
3659 if (s
->slice
.x
== 0)
3660 x
+= s
->img
->hmargin
;
3661 if (s
->slice
.y
== 0)
3662 y
+= s
->img
->vmargin
;
3664 if (s
->hl
== DRAW_IMAGE_SUNKEN
3665 || s
->hl
== DRAW_IMAGE_RAISED
)
3667 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3668 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3672 thick
= abs (s
->img
->relief
);
3673 raised_p
= s
->img
->relief
> 0;
3678 x1
= x
+ s
->slice
.width
+ thick
- 1;
3679 y1
= y
+ s
->slice
.height
+ thick
- 1;
3681 x_setup_relief_colors (s
);
3682 get_glyph_string_clip_rect (s
, &r
);
3683 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
3685 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
3687 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
3692 /* Draw part of the background of glyph string S. X, Y, W, and H
3693 give the rectangle to draw. */
3696 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3697 struct glyph_string
*s
;
3700 #if 0 /* MAC_TODO: stipple */
3703 /* Fill background with a stipple pattern. */
3704 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3705 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3706 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3709 #endif /* MAC_TODO */
3710 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3714 /* Draw image glyph string S.
3717 s->x +-------------------------
3720 | +-------------------------
3723 | | +-------------------
3729 x_draw_image_glyph_string (s
)
3730 struct glyph_string
*s
;
3733 int box_line_hwidth
= abs (s
->face
->box_line_width
);
3734 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
3737 height
= s
->height
- 2 * box_line_vwidth
;
3740 /* Fill background with face under the image. Do it only if row is
3741 taller than image or if image has a clip mask to reduce
3743 s
->stippled_p
= s
->face
->stipple
!= 0;
3744 if (height
> s
->slice
.height
3748 || s
->img
->pixmap
== 0
3749 || s
->width
!= s
->background_width
)
3752 if (s
->first_glyph
->left_box_line_p
3754 x
+= box_line_hwidth
;
3757 if (s
->slice
.y
== 0)
3758 y
+= box_line_vwidth
;
3760 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
3762 s
->background_filled_p
= 1;
3765 /* Draw the foreground. */
3766 x_draw_image_foreground (s
);
3768 /* If we must draw a relief around the image, do it. */
3770 || s
->hl
== DRAW_IMAGE_RAISED
3771 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3772 x_draw_image_relief (s
);
3776 /* Draw stretch glyph string S. */
3779 x_draw_stretch_glyph_string (s
)
3780 struct glyph_string
*s
;
3782 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
3783 s
->stippled_p
= s
->face
->stipple
!= 0;
3785 if (s
->hl
== DRAW_CURSOR
3786 && !x_stretch_cursor_p
)
3788 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
3789 as wide as the stretch glyph. */
3790 int width
, background_width
= s
->background_width
;
3791 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
3795 background_width
-= left_x
- x
;
3798 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
3801 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
3803 /* Clear rest using the GC of the original non-cursor face. */
3804 if (width
< background_width
)
3807 int w
= background_width
- width
, h
= s
->height
;
3812 if (s
->row
->mouse_face_p
3813 && cursor_in_mouse_face_p (s
->w
))
3815 x_set_mouse_face_gc (s
);
3821 get_glyph_string_clip_rect (s
, &r
);
3822 mac_set_clip_rectangles (s
->display
, gc
, &r
, 1);
3824 #if 0 /* MAC_TODO: stipple */
3825 if (s
->face
->stipple
)
3827 /* Fill background with a stipple pattern. */
3828 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
3829 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3830 XSetFillStyle (s
->display
, gc
, FillSolid
);
3833 #endif /* MAC_TODO */
3834 mac_erase_rectangle (s
->f
, gc
, x
, y
, w
, h
);
3837 else if (!s
->background_filled_p
)
3839 int background_width
= s
->background_width
;
3840 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
3842 /* Don't draw into left margin, fringe or scrollbar area
3843 except for header line and mode line. */
3844 if (x
< left_x
&& !s
->row
->mode_line_p
)
3846 background_width
-= left_x
- x
;
3849 if (background_width
> 0)
3850 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
3853 s
->background_filled_p
= 1;
3857 /* Draw glyph string S. */
3860 x_draw_glyph_string (s
)
3861 struct glyph_string
*s
;
3863 int relief_drawn_p
= 0;
3865 /* If S draws into the background of its successor that does not
3866 draw a cursor, draw the background of the successor first so that
3867 S can draw into it. This makes S->next use XDrawString instead
3868 of XDrawImageString. */
3869 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
3870 && s
->next
->hl
!= DRAW_CURSOR
)
3872 xassert (s
->next
->img
== NULL
);
3873 x_set_glyph_string_gc (s
->next
);
3874 x_set_glyph_string_clipping (s
->next
);
3875 x_draw_glyph_string_background (s
->next
, 1);
3878 /* Set up S->gc, set clipping and draw S. */
3879 x_set_glyph_string_gc (s
);
3881 /* Draw relief (if any) in advance for char/composition so that the
3882 glyph string can be drawn over it. */
3883 if (!s
->for_overlaps
3884 && s
->face
->box
!= FACE_NO_BOX
3885 && (s
->first_glyph
->type
== CHAR_GLYPH
3886 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
3889 x_set_glyph_string_clipping (s
);
3890 x_draw_glyph_string_background (s
, 1);
3891 x_draw_glyph_string_box (s
);
3892 x_set_glyph_string_clipping (s
);
3896 x_set_glyph_string_clipping (s
);
3898 switch (s
->first_glyph
->type
)
3901 x_draw_image_glyph_string (s
);
3905 x_draw_stretch_glyph_string (s
);
3909 if (s
->for_overlaps
)
3910 s
->background_filled_p
= 1;
3912 x_draw_glyph_string_background (s
, 0);
3913 x_draw_glyph_string_foreground (s
);
3916 case COMPOSITE_GLYPH
:
3917 if (s
->for_overlaps
|| s
->gidx
> 0)
3918 s
->background_filled_p
= 1;
3920 x_draw_glyph_string_background (s
, 1);
3921 x_draw_composite_glyph_string_foreground (s
);
3928 if (!s
->for_overlaps
)
3930 /* Draw underline. */
3931 if (s
->face
->underline_p
)
3933 unsigned long tem
, h
;
3937 /* Get the underline thickness. Default is 1 pixel. */
3938 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
3942 y
= s
->y
+ s
->height
- h
;
3943 if (!x_underline_at_descent_line
)
3945 /* Get the underline position. This is the recommended
3946 vertical offset in pixels from the baseline to the top of
3947 the underline. This is a signed value according to the
3948 specs, and its default is
3950 ROUND ((maximum descent) / 2), with
3951 ROUND(x) = floor (x + 0.5) */
3954 if (x_use_underline_position_properties
3955 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
3956 y
= s
->ybase
+ (long) tem
;
3960 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
3963 if (s
->face
->underline_defaulted_p
)
3964 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, y
,
3965 s
->background_width
, h
);
3969 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3970 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
3971 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, y
,
3972 s
->background_width
, h
);
3973 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3977 /* Draw overline. */
3978 if (s
->face
->overline_p
)
3980 unsigned long dy
= 0, h
= 1;
3982 if (s
->face
->overline_color_defaulted_p
)
3983 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3984 s
->background_width
, h
);
3988 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3989 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
3990 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3991 s
->background_width
, h
);
3992 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3996 /* Draw strike-through. */
3997 if (s
->face
->strike_through_p
)
3999 unsigned long h
= 1;
4000 unsigned long dy
= (s
->height
- h
) / 2;
4002 if (s
->face
->strike_through_color_defaulted_p
)
4003 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
4008 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4009 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4010 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
4012 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4016 /* Draw relief if not yet drawn. */
4017 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4018 x_draw_glyph_string_box (s
);
4021 /* Reset clipping. */
4022 mac_reset_clip_rectangles (s
->display
, s
->gc
);
4025 /* Shift display to make room for inserted glyphs. */
4028 mac_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
4030 int x
, y
, width
, height
, shift_by
;
4032 mac_scroll_area (f
, f
->output_data
.mac
->normal_gc
,
4033 x
, y
, width
, height
,
4037 /* Delete N glyphs at the nominal cursor position. Not implemented
4048 /* Clear entire frame. If updating_frame is non-null, clear that
4049 frame. Otherwise clear the selected frame. */
4052 x_clear_frame (struct frame
*f
)
4054 /* Clearing the frame will erase any cursor, so mark them all as no
4056 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4057 output_cursor
.hpos
= output_cursor
.vpos
= 0;
4058 output_cursor
.x
= -1;
4060 /* We don't set the output cursor here because there will always
4061 follow an explicit cursor_to. */
4063 mac_clear_window (f
);
4065 /* We have to clear the scroll bars, too. If we have changed
4066 colors or something like that, then they should be notified. */
4067 x_scroll_bar_clear (f
);
4069 XFlush (FRAME_MAC_DISPLAY (f
));
4075 /* Invert the middle quarter of the frame for .15 sec. */
4077 /* We use the select system call to do the waiting, so we have to make
4078 sure it's available. If it isn't, we just won't do visual bells. */
4080 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
4083 /* Subtract the `struct timeval' values X and Y, storing the result in
4084 *RESULT. Return 1 if the difference is negative, otherwise 0. */
4087 timeval_subtract (result
, x
, y
)
4088 struct timeval
*result
, x
, y
;
4090 /* Perform the carry for the later subtraction by updating y. This
4091 is safer because on some systems the tv_sec member is unsigned. */
4092 if (x
.tv_usec
< y
.tv_usec
)
4094 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
4095 y
.tv_usec
-= 1000000 * nsec
;
4099 if (x
.tv_usec
- y
.tv_usec
> 1000000)
4101 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
4102 y
.tv_usec
+= 1000000 * nsec
;
4106 /* Compute the time remaining to wait. tv_usec is certainly
4108 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
4109 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
4111 /* Return indication of whether the result should be considered
4113 return x
.tv_sec
< y
.tv_sec
;
4120 /* Get the height not including a menu bar widget. */
4121 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
4122 /* Height of each line to flash. */
4123 int flash_height
= FRAME_LINE_HEIGHT (f
);
4124 /* These will be the left and right margins of the rectangles. */
4125 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
4126 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
4130 /* Don't flash the area between a scroll bar and the frame
4131 edge it is next to. */
4132 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
4134 case vertical_scroll_bar_left
:
4135 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
4138 case vertical_scroll_bar_right
:
4139 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
4146 width
= flash_right
- flash_left
;
4150 /* If window is tall, flash top and bottom line. */
4151 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
4153 mac_invert_rectangle (f
, flash_left
,
4154 (FRAME_INTERNAL_BORDER_WIDTH (f
)
4155 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
4156 width
, flash_height
);
4157 mac_invert_rectangle (f
, flash_left
,
4158 (height
- flash_height
4159 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
4160 width
, flash_height
);
4163 /* If it is short, flash it all. */
4164 mac_invert_rectangle (f
, flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
4165 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
4170 struct timeval wakeup
;
4172 EMACS_GET_TIME (wakeup
);
4174 /* Compute time to wait until, propagating carry from usecs. */
4175 wakeup
.tv_usec
+= 150000;
4176 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
4177 wakeup
.tv_usec
%= 1000000;
4179 /* Keep waiting until past the time wakeup or any input gets
4181 while (! detect_input_pending ())
4183 struct timeval current
;
4184 struct timeval timeout
;
4186 EMACS_GET_TIME (current
);
4188 /* Break if result would be negative. */
4189 if (timeval_subtract (¤t
, wakeup
, current
))
4192 /* How long `select' should wait. */
4194 timeout
.tv_usec
= 10000;
4196 /* Try to wait that long--but we might wake up sooner. */
4197 select (0, NULL
, NULL
, NULL
, &timeout
);
4201 /* If window is tall, flash top and bottom line. */
4202 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
4204 mac_invert_rectangle (f
, flash_left
,
4205 (FRAME_INTERNAL_BORDER_WIDTH (f
)
4206 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
4207 width
, flash_height
);
4208 mac_invert_rectangle (f
, flash_left
,
4209 (height
- flash_height
4210 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
4211 width
, flash_height
);
4214 /* If it is short, flash it all. */
4215 mac_invert_rectangle (f
, flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
4216 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
4223 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
4226 /* Make audible bell. */
4231 struct frame
*f
= SELECTED_FRAME ();
4233 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
4241 XFlush (FRAME_MAC_DISPLAY (f
));
4247 /* Specify how many text lines, from the top of the window,
4248 should be affected by insert-lines and delete-lines operations.
4249 This, and those operations, are used only within an update
4250 that is bounded by calls to x_update_begin and x_update_end. */
4253 XTset_terminal_window (n
)
4256 /* This function intentionally left blank. */
4261 /***********************************************************************
4263 ***********************************************************************/
4265 /* Perform an insert-lines or delete-lines operation, inserting N
4266 lines or deleting -N lines at vertical position VPOS. */
4269 x_ins_del_lines (vpos
, n
)
4276 /* Scroll part of the display as described by RUN. */
4279 x_scroll_run (w
, run
)
4283 struct frame
*f
= XFRAME (w
->frame
);
4284 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
4286 /* Get frame-relative bounding box of the text display area of W,
4287 without mode lines. Include in this box the left and right
4289 window_box (w
, -1, &x
, &y
, &width
, &height
);
4291 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
4292 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
4293 bottom_y
= y
+ height
;
4297 /* Scrolling up. Make sure we don't copy part of the mode
4298 line at the bottom. */
4299 if (from_y
+ run
->height
> bottom_y
)
4300 height
= bottom_y
- from_y
;
4302 height
= run
->height
;
4306 /* Scolling down. Make sure we don't copy over the mode line.
4308 if (to_y
+ run
->height
> bottom_y
)
4309 height
= bottom_y
- to_y
;
4311 height
= run
->height
;
4316 /* Cursor off. Will be switched on again in x_update_window_end. */
4320 mac_scroll_area (f
, f
->output_data
.mac
->normal_gc
,
4330 /***********************************************************************
4332 ***********************************************************************/
4339 x_update_cursor (f
, 1);
4343 frame_unhighlight (f
)
4346 x_update_cursor (f
, 1);
4349 /* The focus has changed. Update the frames as necessary to reflect
4350 the new situation. Note that we can't change the selected frame
4351 here, because the Lisp code we are interrupting might become confused.
4352 Each event gets marked with the frame in which it occurred, so the
4353 Lisp code can tell when the switch took place by examining the events. */
4356 x_new_focus_frame (dpyinfo
, frame
)
4357 struct x_display_info
*dpyinfo
;
4358 struct frame
*frame
;
4360 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
4362 if (frame
!= dpyinfo
->x_focus_frame
)
4364 /* Set this before calling other routines, so that they see
4365 the correct value of x_focus_frame. */
4366 dpyinfo
->x_focus_frame
= frame
;
4368 if (old_focus
&& old_focus
->auto_lower
)
4369 x_lower_frame (old_focus
);
4372 selected_frame
= frame
;
4373 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
4375 Fselect_window (selected_frame
->selected_window
, Qnil
);
4376 choose_minibuf_frame ();
4379 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
4380 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
4382 pending_autoraise_frame
= 0;
4384 #if USE_MAC_FONT_PANEL
4386 mac_set_font_info_for_selection (frame
, DEFAULT_FACE_ID
, 0);
4390 x_frame_rehighlight (dpyinfo
);
4393 /* Handle FocusIn and FocusOut state changes for FRAME.
4394 If FRAME has focus and there exists more than one frame, puts
4395 a FOCUS_IN_EVENT into *BUFP. */
4398 mac_focus_changed (type
, dpyinfo
, frame
, bufp
)
4400 struct mac_display_info
*dpyinfo
;
4401 struct frame
*frame
;
4402 struct input_event
*bufp
;
4404 if (type
== activeFlag
)
4406 if (dpyinfo
->x_focus_event_frame
!= frame
)
4408 x_new_focus_frame (dpyinfo
, frame
);
4409 dpyinfo
->x_focus_event_frame
= frame
;
4411 /* Don't stop displaying the initial startup message
4412 for a switch-frame event we don't need. */
4413 if (GC_NILP (Vterminal_frame
)
4414 && GC_CONSP (Vframe_list
)
4415 && !GC_NILP (XCDR (Vframe_list
)))
4417 bufp
->kind
= FOCUS_IN_EVENT
;
4418 XSETFRAME (bufp
->frame_or_window
, frame
);
4424 if (dpyinfo
->x_focus_event_frame
== frame
)
4426 dpyinfo
->x_focus_event_frame
= 0;
4427 x_new_focus_frame (dpyinfo
, 0);
4432 /* The focus may have changed. Figure out if it is a real focus change,
4433 by checking both FocusIn/Out and Enter/LeaveNotify events.
4435 Returns FOCUS_IN_EVENT event in *BUFP. */
4438 x_detect_focus_change (dpyinfo
, event
, bufp
)
4439 struct mac_display_info
*dpyinfo
;
4440 const EventRecord
*event
;
4441 struct input_event
*bufp
;
4443 struct frame
*frame
;
4445 frame
= mac_window_to_frame ((WindowRef
) event
->message
);
4449 /* On Mac, this is only called from focus events, so no switch needed. */
4450 mac_focus_changed ((event
->modifiers
& activeFlag
),
4451 dpyinfo
, frame
, bufp
);
4455 /* Handle an event saying the mouse has moved out of an Emacs frame. */
4458 x_mouse_leave (dpyinfo
)
4459 struct x_display_info
*dpyinfo
;
4461 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
4464 /* The focus has changed, or we have redirected a frame's focus to
4465 another frame (this happens when a frame uses a surrogate
4466 mini-buffer frame). Shift the highlight as appropriate.
4468 The FRAME argument doesn't necessarily have anything to do with which
4469 frame is being highlighted or un-highlighted; we only use it to find
4470 the appropriate X display info. */
4473 XTframe_rehighlight (frame
)
4474 struct frame
*frame
;
4476 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
4480 x_frame_rehighlight (dpyinfo
)
4481 struct x_display_info
*dpyinfo
;
4483 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
4485 if (dpyinfo
->x_focus_frame
)
4487 dpyinfo
->x_highlight_frame
4488 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
4489 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
4490 : dpyinfo
->x_focus_frame
);
4491 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
4493 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
4494 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
4498 dpyinfo
->x_highlight_frame
= 0;
4500 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
4503 frame_unhighlight (old_highlight
);
4504 if (dpyinfo
->x_highlight_frame
)
4505 frame_highlight (dpyinfo
->x_highlight_frame
);
4511 /* Convert a keysym to its name. */
4514 x_get_keysym_name (keysym
)
4521 value
= XKeysymToString (keysym
);
4532 /* Function to report a mouse movement to the mainstream Emacs code.
4533 The input handler calls this.
4535 We have received a mouse movement event, which is given in *event.
4536 If the mouse is over a different glyph than it was last time, tell
4537 the mainstream emacs code by setting mouse_moved. If not, ask for
4538 another motion event, so we can check again the next time it moves. */
4540 static Point last_mouse_motion_position
;
4541 static Lisp_Object last_mouse_motion_frame
;
4544 note_mouse_movement (frame
, pos
)
4548 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (frame
);
4549 #if TARGET_API_MAC_CARBON
4553 last_mouse_movement_time
= TickCount () * (1000 / 60); /* to milliseconds */
4554 last_mouse_motion_position
= *pos
;
4555 XSETFRAME (last_mouse_motion_frame
, frame
);
4557 if (frame
== dpyinfo
->mouse_face_mouse_frame
4558 #if TARGET_API_MAC_CARBON
4559 && !PtInRect (*pos
, GetWindowPortBounds (FRAME_MAC_WINDOW (frame
), &r
))
4561 && !PtInRect (*pos
, &FRAME_MAC_WINDOW (frame
)->portRect
)
4565 /* This case corresponds to LeaveNotify in X11. If we move
4566 outside the frame, then we're certainly no longer on any text
4568 clear_mouse_face (dpyinfo
);
4569 dpyinfo
->mouse_face_mouse_frame
= 0;
4570 if (!dpyinfo
->grabbed
)
4571 FRAME_RIF (frame
)->define_frame_cursor (frame
,
4572 frame
->output_data
.mac
->nontext_cursor
);
4575 /* Has the mouse moved off the glyph it was on at the last sighting? */
4576 if (frame
!= last_mouse_glyph_frame
4577 || !PtInRect (*pos
, &last_mouse_glyph
))
4579 frame
->mouse_moved
= 1;
4580 last_mouse_scroll_bar
= Qnil
;
4581 note_mouse_highlight (frame
, pos
->h
, pos
->v
);
4582 /* Remember which glyph we're now on. */
4583 remember_mouse_glyph (frame
, pos
->h
, pos
->v
, &last_mouse_glyph
);
4584 last_mouse_glyph_frame
= frame
;
4592 /************************************************************************
4594 ************************************************************************/
4596 /* MAC TODO: This should be called from somewhere (or removed) ++KFS */
4599 redo_mouse_highlight ()
4601 if (!NILP (last_mouse_motion_frame
)
4602 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
4603 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
4604 last_mouse_motion_position
.h
,
4605 last_mouse_motion_position
.v
);
4609 static struct frame
*
4610 mac_focus_frame (dpyinfo
)
4611 struct mac_display_info
*dpyinfo
;
4613 if (dpyinfo
->x_focus_frame
)
4614 return dpyinfo
->x_focus_frame
;
4616 /* Mac version may get events, such as a menu bar click, even when
4617 all the frames are invisible. In this case, we regard the
4618 event came to the selected frame. */
4619 return SELECTED_FRAME ();
4623 /* Return the current position of the mouse.
4624 *FP should be a frame which indicates which display to ask about.
4626 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
4627 and *PART to the frame, window, and scroll bar part that the mouse
4628 is over. Set *X and *Y to the portion and whole of the mouse's
4629 position on the scroll bar.
4631 If the mouse movement started elsewhere, set *FP to the frame the
4632 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
4635 Set *TIME to the server time-stamp for the time at which the mouse
4636 was at this position.
4638 Don't store anything if we don't have a valid set of values to report.
4640 This clears the mouse_moved flag, so we can wait for the next mouse
4644 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
4647 Lisp_Object
*bar_window
;
4648 enum scroll_bar_part
*part
;
4650 unsigned long *time
;
4656 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
4657 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
4660 Lisp_Object frame
, tail
;
4662 /* Clear the mouse-moved flag for every frame on this display. */
4663 FOR_EACH_FRAME (tail
, frame
)
4664 XFRAME (frame
)->mouse_moved
= 0;
4666 last_mouse_scroll_bar
= Qnil
;
4668 if (FRAME_MAC_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
4669 && FRAME_LIVE_P (last_mouse_frame
))
4670 f1
= last_mouse_frame
;
4672 f1
= mac_focus_frame (FRAME_MAC_DISPLAY_INFO (*fp
));
4676 /* Ok, we found a frame. Store all the values.
4677 last_mouse_glyph is a rectangle used to reduce the
4678 generation of mouse events. To not miss any motion
4679 events, we must divide the frame into rectangles of the
4680 size of the smallest character that could be displayed
4681 on it, i.e. into the same rectangles that matrices on
4682 the frame are divided into. */
4685 #if TARGET_API_MAC_CARBON
4686 GetGlobalMouse (&mouse_pos
);
4687 mouse_pos
.h
-= f1
->left_pos
+ FRAME_OUTER_TO_INNER_DIFF_X (f1
);
4688 mouse_pos
.v
-= f1
->top_pos
+ FRAME_OUTER_TO_INNER_DIFF_Y (f1
);
4690 SetPortWindowPort (FRAME_MAC_WINDOW (f1
));
4691 GetMouse (&mouse_pos
);
4693 remember_mouse_glyph (f1
, mouse_pos
.h
, mouse_pos
.v
,
4695 last_mouse_glyph_frame
= f1
;
4700 XSETINT (*x
, mouse_pos
.h
);
4701 XSETINT (*y
, mouse_pos
.v
);
4702 *time
= last_mouse_movement_time
;
4710 /************************************************************************
4712 ************************************************************************/
4714 #ifdef USE_TOOLKIT_SCROLL_BARS
4716 static pascal void scroll_bar_timer_callback
P_ ((EventLoopTimerRef
, void *));
4717 static OSStatus install_scroll_bar_timer
P_ ((void));
4718 static OSStatus set_scroll_bar_timer
P_ ((EventTimerInterval
));
4719 static int control_part_code_to_scroll_bar_part
P_ ((ControlPartCode
));
4720 static void construct_scroll_bar_click
P_ ((struct scroll_bar
*, int,
4721 struct input_event
*));
4722 static OSStatus get_control_part_bounds
P_ ((ControlRef
, ControlPartCode
,
4724 static void x_scroll_bar_handle_press
P_ ((struct scroll_bar
*,
4725 ControlPartCode
, Point
,
4726 struct input_event
*));
4727 static void x_scroll_bar_handle_release
P_ ((struct scroll_bar
*,
4728 struct input_event
*));
4729 static void x_scroll_bar_handle_drag
P_ ((WindowRef
, struct scroll_bar
*,
4730 Point
, struct input_event
*));
4731 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
4734 /* Last scroll bar part sent in x_scroll_bar_handle_*. */
4736 static int last_scroll_bar_part
;
4738 static EventLoopTimerRef scroll_bar_timer
;
4740 static int scroll_bar_timer_event_posted_p
;
4742 #define SCROLL_BAR_FIRST_DELAY 0.5
4743 #define SCROLL_BAR_CONTINUOUS_DELAY (1.0 / 15)
4746 scroll_bar_timer_callback (timer
, data
)
4747 EventLoopTimerRef timer
;
4752 err
= mac_post_mouse_moved_event ();
4754 scroll_bar_timer_event_posted_p
= 1;
4758 install_scroll_bar_timer ()
4760 static EventLoopTimerUPP scroll_bar_timer_callbackUPP
= NULL
;
4762 if (scroll_bar_timer_callbackUPP
== NULL
)
4763 scroll_bar_timer_callbackUPP
=
4764 NewEventLoopTimerUPP (scroll_bar_timer_callback
);
4766 if (scroll_bar_timer
== NULL
)
4767 /* Mac OS X and CarbonLib 1.5 and later allow us to specify
4768 kEventDurationForever as delays. */
4770 InstallEventLoopTimer (GetCurrentEventLoop (),
4771 kEventDurationForever
, kEventDurationForever
,
4772 scroll_bar_timer_callbackUPP
, NULL
,
4777 set_scroll_bar_timer (delay
)
4778 EventTimerInterval delay
;
4780 if (scroll_bar_timer
== NULL
)
4781 install_scroll_bar_timer ();
4783 scroll_bar_timer_event_posted_p
= 0;
4785 return SetEventLoopTimerNextFireTime (scroll_bar_timer
, delay
);
4789 control_part_code_to_scroll_bar_part (part_code
)
4790 ControlPartCode part_code
;
4794 case kControlUpButtonPart
: return scroll_bar_up_arrow
;
4795 case kControlDownButtonPart
: return scroll_bar_down_arrow
;
4796 case kControlPageUpPart
: return scroll_bar_above_handle
;
4797 case kControlPageDownPart
: return scroll_bar_below_handle
;
4798 case kControlIndicatorPart
: return scroll_bar_handle
;
4805 construct_scroll_bar_click (bar
, part
, bufp
)
4806 struct scroll_bar
*bar
;
4808 struct input_event
*bufp
;
4810 bufp
->kind
= SCROLL_BAR_CLICK_EVENT
;
4811 bufp
->frame_or_window
= bar
->window
;
4815 XSETINT (bufp
->x
, 0);
4816 XSETINT (bufp
->y
, 0);
4817 bufp
->modifiers
= 0;
4821 get_control_part_bounds (ch
, part_code
, rect
)
4823 ControlPartCode part_code
;
4826 RgnHandle region
= NewRgn ();
4829 err
= GetControlRegion (ch
, part_code
, region
);
4831 GetRegionBounds (region
, rect
);
4832 DisposeRgn (region
);
4838 x_scroll_bar_handle_press (bar
, part_code
, mouse_pos
, bufp
)
4839 struct scroll_bar
*bar
;
4840 ControlPartCode part_code
;
4842 struct input_event
*bufp
;
4844 int part
= control_part_code_to_scroll_bar_part (part_code
);
4849 if (part
!= scroll_bar_handle
)
4851 construct_scroll_bar_click (bar
, part
, bufp
);
4852 HiliteControl (SCROLL_BAR_CONTROL_REF (bar
), part_code
);
4853 set_scroll_bar_timer (SCROLL_BAR_FIRST_DELAY
);
4854 bar
->dragging
= Qnil
;
4860 get_control_part_bounds (SCROLL_BAR_CONTROL_REF (bar
),
4861 kControlIndicatorPart
, &r
);
4862 XSETINT (bar
->dragging
, - (mouse_pos
.v
- r
.top
) - 1);
4865 last_scroll_bar_part
= part
;
4866 tracked_scroll_bar
= bar
;
4870 x_scroll_bar_handle_release (bar
, bufp
)
4871 struct scroll_bar
*bar
;
4872 struct input_event
*bufp
;
4874 if (last_scroll_bar_part
!= scroll_bar_handle
4875 || (INTEGERP (bar
->dragging
) && XINT (bar
->dragging
) >= 0))
4876 construct_scroll_bar_click (bar
, scroll_bar_end_scroll
, bufp
);
4878 HiliteControl (SCROLL_BAR_CONTROL_REF (bar
), 0);
4879 set_scroll_bar_timer (kEventDurationForever
);
4881 last_scroll_bar_part
= -1;
4882 bar
->dragging
= Qnil
;
4883 tracked_scroll_bar
= NULL
;
4887 x_scroll_bar_handle_drag (win
, bar
, mouse_pos
, bufp
)
4889 struct scroll_bar
*bar
;
4891 struct input_event
*bufp
;
4893 ControlRef ch
= SCROLL_BAR_CONTROL_REF (bar
);
4895 if (last_scroll_bar_part
== scroll_bar_handle
)
4900 get_control_part_bounds (SCROLL_BAR_CONTROL_REF (bar
),
4901 kControlIndicatorPart
, &r
);
4903 if (INTEGERP (bar
->dragging
) && XINT (bar
->dragging
) < 0)
4904 XSETINT (bar
->dragging
, - (XINT (bar
->dragging
) + 1));
4906 top
= mouse_pos
.v
- XINT (bar
->dragging
) - XINT (bar
->track_top
);
4907 top_range
= XINT (bar
->track_height
) - XINT (bar
->min_handle
);
4911 if (top
> top_range
)
4914 construct_scroll_bar_click (bar
, scroll_bar_handle
, bufp
);
4915 XSETINT (bufp
->x
, top
);
4916 XSETINT (bufp
->y
, top_range
);
4920 ControlPartCode part_code
;
4921 int unhilite_p
= 0, part
;
4923 if (ch
!= FindControlUnderMouse (mouse_pos
, win
, &part_code
))
4927 part
= control_part_code_to_scroll_bar_part (part_code
);
4929 switch (last_scroll_bar_part
)
4931 case scroll_bar_above_handle
:
4932 case scroll_bar_below_handle
:
4933 if (part
!= scroll_bar_above_handle
4934 && part
!= scroll_bar_below_handle
)
4938 case scroll_bar_up_arrow
:
4939 case scroll_bar_down_arrow
:
4940 if (part
!= scroll_bar_up_arrow
4941 && part
!= scroll_bar_down_arrow
)
4948 HiliteControl (SCROLL_BAR_CONTROL_REF (bar
), 0);
4949 else if (part
!= last_scroll_bar_part
4950 || scroll_bar_timer_event_posted_p
)
4952 construct_scroll_bar_click (bar
, part
, bufp
);
4953 last_scroll_bar_part
= part
;
4954 HiliteControl (SCROLL_BAR_CONTROL_REF (bar
), part_code
);
4955 set_scroll_bar_timer (SCROLL_BAR_CONTINUOUS_DELAY
);
4960 /* Set the thumb size and position of scroll bar BAR. We are currently
4961 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4964 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4965 struct scroll_bar
*bar
;
4966 int portion
, position
, whole
;
4968 ControlRef ch
= SCROLL_BAR_CONTROL_REF (bar
);
4969 int value
, viewsize
, maximum
;
4971 if (XINT (bar
->track_height
) == 0)
4974 if (whole
<= portion
)
4975 value
= 0, viewsize
= 1, maximum
= 0;
4980 maximum
= XINT (bar
->track_height
) - XINT (bar
->min_handle
);
4981 scale
= (float) maximum
/ (whole
- portion
);
4982 value
= position
* scale
+ 0.5f
;
4983 viewsize
= (int) (portion
* scale
+ 0.5f
) + XINT (bar
->min_handle
);
4988 if (GetControlViewSize (ch
) != viewsize
4989 || GetControl32BitValue (ch
) != value
4990 || GetControl32BitMaximum (ch
) != maximum
)
4992 /* Temporarily hide the scroll bar to avoid multiple redraws. */
4993 SetControlVisibility (ch
, false, false);
4995 SetControl32BitMaximum (ch
, maximum
);
4996 SetControl32BitValue (ch
, value
);
4997 SetControlViewSize (ch
, viewsize
);
4999 SetControlVisibility (ch
, true, true);
5005 #endif /* USE_TOOLKIT_SCROLL_BARS */
5009 /************************************************************************
5010 Scroll bars, general
5011 ************************************************************************/
5013 /* Create a scroll bar and return the scroll bar vector for it. W is
5014 the Emacs window on which to create the scroll bar. TOP, LEFT,
5015 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
5018 static struct scroll_bar
*
5019 x_scroll_bar_create (w
, top
, left
, width
, height
, disp_top
, disp_height
)
5021 int top
, left
, width
, height
, disp_top
, disp_height
;
5023 struct frame
*f
= XFRAME (w
->frame
);
5024 struct scroll_bar
*bar
5025 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
5033 r
.right
= left
+ width
;
5034 r
.bottom
= disp_top
+ disp_height
;
5037 mac_prepare_for_quickdraw (f
);
5039 #if TARGET_API_MAC_CARBON
5040 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p",
5041 #ifdef USE_TOOLKIT_SCROLL_BARS
5044 width
< disp_height
,
5046 0, 0, 0, kControlScrollBarProc
, (long) bar
);
5048 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p", width
< disp_height
,
5049 0, 0, 0, scrollBarProc
, (long) bar
);
5051 SET_SCROLL_BAR_CONTROL_REF (bar
, ch
);
5053 XSETWINDOW (bar
->window
, w
);
5054 XSETINT (bar
->top
, top
);
5055 XSETINT (bar
->left
, left
);
5056 XSETINT (bar
->width
, width
);
5057 XSETINT (bar
->height
, height
);
5058 XSETINT (bar
->start
, 0);
5059 XSETINT (bar
->end
, 0);
5060 bar
->dragging
= Qnil
;
5062 bar
->fringe_extended_p
= Qnil
;
5064 #ifdef USE_TOOLKIT_SCROLL_BARS
5065 bar
->track_top
= Qnil
;
5066 bar
->track_height
= Qnil
;
5067 bar
->min_handle
= Qnil
;
5070 /* Add bar to its frame's list of scroll bars. */
5071 bar
->next
= FRAME_SCROLL_BARS (f
);
5073 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5074 if (!NILP (bar
->next
))
5075 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5082 /* Draw BAR's handle in the proper position.
5084 If the handle is already drawn from START to END, don't bother
5085 redrawing it, unless REBUILD is non-zero; in that case, always
5086 redraw it. (REBUILD is handy for drawing the handle after expose
5089 Normally, we want to constrain the start and end of the handle to
5090 fit inside its rectangle, but if the user is dragging the scroll
5091 bar handle, we want to let them drag it down all the way, so that
5092 the bar's top is as far down as it goes; otherwise, there's no way
5093 to move to the very end of the buffer. */
5095 #ifndef USE_TOOLKIT_SCROLL_BARS
5098 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
5099 struct scroll_bar
*bar
;
5103 int dragging
= ! NILP (bar
->dragging
);
5104 ControlRef ch
= SCROLL_BAR_CONTROL_REF (bar
);
5105 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5106 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
5107 int length
= end
- start
;
5109 /* If the display is already accurate, do nothing. */
5111 && start
== XINT (bar
->start
)
5112 && end
== XINT (bar
->end
))
5117 /* Make sure the values are reasonable, and try to preserve the
5118 distance between start and end. */
5121 else if (start
> top_range
)
5123 end
= start
+ length
;
5127 else if (end
> top_range
&& ! dragging
)
5130 /* Store the adjusted setting in the scroll bar. */
5131 XSETINT (bar
->start
, start
);
5132 XSETINT (bar
->end
, end
);
5134 /* Clip the end position, just for display. */
5135 if (end
> top_range
)
5138 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
5139 top positions, to make sure the handle is always at least that
5140 many pixels tall. */
5141 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
5143 SetControlMinimum (ch
, 0);
5144 /* Don't inadvertently activate deactivated scroll bars */
5145 if (GetControlMaximum (ch
) != -1)
5146 SetControlMaximum (ch
, top_range
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
5148 SetControlValue (ch
, start
);
5149 #if TARGET_API_MAC_CARBON
5150 SetControlViewSize (ch
, end
- start
);
5156 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5158 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
5162 x_scroll_bar_remove (bar
)
5163 struct scroll_bar
*bar
;
5165 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5170 mac_prepare_for_quickdraw (f
);
5172 /* Destroy the Mac scroll bar control */
5173 DisposeControl (SCROLL_BAR_CONTROL_REF (bar
));
5175 /* Disassociate this scroll bar from its window. */
5176 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
5182 /* Set the handle of the vertical scroll bar for WINDOW to indicate
5183 that we are displaying PORTION characters out of a total of WHOLE
5184 characters, starting at POSITION. If WINDOW has no scroll bar,
5188 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
5190 int portion
, whole
, position
;
5192 struct frame
*f
= XFRAME (w
->frame
);
5193 struct scroll_bar
*bar
;
5194 int top
, height
, left
, sb_left
, width
, sb_width
, disp_top
, disp_height
;
5195 int window_y
, window_height
;
5197 int fringe_extended_p
;
5200 /* Get window dimensions. */
5201 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
5203 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5204 height
= window_height
;
5206 /* Compute the left edge of the scroll bar area. */
5207 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
5209 /* Compute the width of the scroll bar which might be less than
5210 the width of the area reserved for the scroll bar. */
5211 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
5212 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5216 /* Compute the left edge of the scroll bar. */
5217 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5218 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
5220 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
5222 /* Adjustments according to Inside Macintosh to make it look nice */
5224 disp_height
= height
;
5231 else if (disp_top
== FRAME_PIXEL_HEIGHT (f
) - 16)
5237 if (sb_left
+ sb_width
== FRAME_PIXEL_WIDTH (f
))
5242 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5243 fringe_extended_p
= (WINDOW_LEFTMOST_P (w
)
5244 && WINDOW_LEFT_FRINGE_WIDTH (w
)
5245 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5246 || WINDOW_LEFT_MARGIN_COLS (w
) == 0));
5248 fringe_extended_p
= (WINDOW_RIGHTMOST_P (w
)
5249 && WINDOW_RIGHT_FRINGE_WIDTH (w
)
5250 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5251 || WINDOW_RIGHT_MARGIN_COLS (w
) == 0));
5254 /* Does the scroll bar exist yet? */
5255 if (NILP (w
->vertical_scroll_bar
))
5259 if (fringe_extended_p
)
5260 mac_clear_area (f
, sb_left
, top
, sb_width
, height
);
5263 mac_clear_area (f
, left
, top
, width
, height
);
5265 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
, disp_top
,
5267 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
5271 /* It may just need to be moved and resized. */
5274 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5275 ch
= SCROLL_BAR_CONTROL_REF (bar
);
5279 /* If already correctly positioned, do nothing. */
5280 if (!(XINT (bar
->left
) == sb_left
5281 && XINT (bar
->top
) == top
5282 && XINT (bar
->width
) == sb_width
5283 && XINT (bar
->height
) == height
5285 && !NILP (bar
->fringe_extended_p
) == fringe_extended_p
5289 /* Since toolkit scroll bars are smaller than the space reserved
5290 for them on the frame, we have to clear "under" them. */
5292 if (fringe_extended_p
)
5293 mac_clear_area (f
, sb_left
, top
, sb_width
, height
);
5296 mac_clear_area (f
, left
, top
, width
, height
);
5299 mac_prepare_for_quickdraw (f
);
5302 MoveControl (ch
, sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
, disp_top
);
5303 SizeControl (ch
, sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5305 #ifndef USE_TOOLKIT_SCROLL_BARS
5306 if (sb_width
< disp_height
)
5310 /* Remember new settings. */
5311 XSETINT (bar
->left
, sb_left
);
5312 XSETINT (bar
->top
, top
);
5313 XSETINT (bar
->width
, sb_width
);
5314 XSETINT (bar
->height
, height
);
5315 #ifdef USE_TOOLKIT_SCROLL_BARS
5316 bar
->track_top
= Qnil
;
5317 bar
->track_height
= Qnil
;
5318 bar
->min_handle
= Qnil
;
5326 bar
->fringe_extended_p
= fringe_extended_p
? Qt
: Qnil
;
5329 #ifdef USE_TOOLKIT_SCROLL_BARS
5330 if (NILP (bar
->track_top
))
5332 if (sb_width
>= disp_height
5334 || sb_width
< MAC_AQUA_SMALL_VERTICAL_SCROLL_BAR_WIDTH
5338 XSETINT (bar
->track_top
, 0);
5339 XSETINT (bar
->track_height
, 0);
5340 XSETINT (bar
->min_handle
, 0);
5344 ControlRef ch
= SCROLL_BAR_CONTROL_REF (bar
);
5349 SetControl32BitMinimum (ch
, 0);
5350 SetControl32BitMaximum (ch
, 1 << 30);
5351 SetControlViewSize (ch
, 1);
5353 /* Move the scroll bar thumb to the top. */
5354 SetControl32BitValue (ch
, 0);
5355 get_control_part_bounds (ch
, kControlIndicatorPart
, &r0
);
5357 /* Move the scroll bar thumb to the bottom. */
5358 SetControl32BitValue (ch
, 1 << 30);
5359 get_control_part_bounds (ch
, kControlIndicatorPart
, &r1
);
5361 UnionRect (&r0
, &r1
, &r0
);
5362 XSETINT (bar
->track_top
, r0
.top
);
5363 XSETINT (bar
->track_height
, r0
.bottom
- r0
.top
);
5364 XSETINT (bar
->min_handle
, r1
.bottom
- r1
.top
);
5366 /* Don't show the scroll bar if its height is not enough to
5367 display the scroll bar thumb. */
5368 if (r0
.bottom
- r0
.top
> 0)
5375 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5376 #else /* not USE_TOOLKIT_SCROLL_BARS */
5377 /* Set the scroll bar's current state, unless we're currently being
5379 if (NILP (bar
->dragging
))
5381 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5384 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5387 int start
= ((double) position
* top_range
) / whole
;
5388 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5389 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5392 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5396 /* The following three hooks are used when we're doing a thorough
5397 redisplay of the frame. We don't explicitly know which scroll bars
5398 are going to be deleted, because keeping track of when windows go
5399 away is a real pain - "Can you say set-window-configuration, boys
5400 and girls?" Instead, we just assert at the beginning of redisplay
5401 that *all* scroll bars are to be removed, and then save a scroll bar
5402 from the fiery pit when we actually redisplay its window. */
5404 /* Arrange for all scroll bars on FRAME to be removed at the next call
5405 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5406 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5409 XTcondemn_scroll_bars (frame
)
5412 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5413 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5416 bar
= FRAME_SCROLL_BARS (frame
);
5417 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5418 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5419 XSCROLL_BAR (bar
)->prev
= Qnil
;
5420 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5421 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5422 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5427 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5428 Note that WINDOW isn't necessarily condemned at all. */
5431 XTredeem_scroll_bar (window
)
5432 struct window
*window
;
5434 struct scroll_bar
*bar
;
5437 /* We can't redeem this window's scroll bar if it doesn't have one. */
5438 if (NILP (window
->vertical_scroll_bar
))
5441 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5443 /* Unlink it from the condemned list. */
5444 f
= XFRAME (WINDOW_FRAME (window
));
5445 if (NILP (bar
->prev
))
5447 /* If the prev pointer is nil, it must be the first in one of
5449 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5450 /* It's not condemned. Everything's fine. */
5452 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5453 window
->vertical_scroll_bar
))
5454 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5456 /* If its prev pointer is nil, it must be at the front of
5457 one or the other! */
5461 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5463 if (! NILP (bar
->next
))
5464 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5466 bar
->next
= FRAME_SCROLL_BARS (f
);
5468 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5469 if (! NILP (bar
->next
))
5470 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5473 /* Remove all scroll bars on FRAME that haven't been saved since the
5474 last call to `*condemn_scroll_bars_hook'. */
5477 XTjudge_scroll_bars (f
)
5480 Lisp_Object bar
, next
;
5482 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5484 /* Clear out the condemned list now so we won't try to process any
5485 more events on the hapless scroll bars. */
5486 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5488 for (; ! NILP (bar
); bar
= next
)
5490 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5492 x_scroll_bar_remove (b
);
5495 b
->next
= b
->prev
= Qnil
;
5498 /* Now there should be no references to the condemned scroll bars,
5499 and they should get garbage-collected. */
5503 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5504 is set to something other than NO_EVENT, it is enqueued.
5506 This may be called from a signal handler, so we have to ignore GC
5510 x_scroll_bar_handle_click (bar
, part_code
, er
, bufp
)
5511 struct scroll_bar
*bar
;
5512 ControlPartCode part_code
;
5513 const EventRecord
*er
;
5514 struct input_event
*bufp
;
5516 int win_y
, top_range
;
5518 if (! GC_WINDOWP (bar
->window
))
5521 bufp
->kind
= SCROLL_BAR_CLICK_EVENT
;
5522 bufp
->frame_or_window
= bar
->window
;
5525 bar
->dragging
= Qnil
;
5529 case kControlUpButtonPart
:
5530 bufp
->part
= scroll_bar_up_arrow
;
5532 case kControlDownButtonPart
:
5533 bufp
->part
= scroll_bar_down_arrow
;
5535 case kControlPageUpPart
:
5536 bufp
->part
= scroll_bar_above_handle
;
5538 case kControlPageDownPart
:
5539 bufp
->part
= scroll_bar_below_handle
;
5541 #if TARGET_API_MAC_CARBON
5544 case kControlIndicatorPart
:
5546 if (er
->what
== mouseDown
)
5547 bar
->dragging
= make_number (0);
5548 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5549 bufp
->part
= scroll_bar_handle
;
5553 win_y
= XINT (bufp
->y
) - XINT (bar
->top
);
5554 top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (0/*dummy*/, XINT (bar
->height
));
5556 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5560 if (! NILP (bar
->dragging
))
5561 win_y
-= XINT (bar
->dragging
);
5565 if (win_y
> top_range
)
5568 XSETINT (bufp
->x
, win_y
);
5569 XSETINT (bufp
->y
, top_range
);
5572 #ifndef USE_TOOLKIT_SCROLL_BARS
5574 /* Handle some mouse motion while someone is dragging the scroll bar.
5576 This may be called from a signal handler, so we have to ignore GC
5580 x_scroll_bar_note_movement (bar
, y_pos
, t
)
5581 struct scroll_bar
*bar
;
5585 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5587 last_mouse_movement_time
= t
;
5590 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5592 /* If we're dragging the bar, display it. */
5593 if (! GC_NILP (bar
->dragging
))
5595 /* Where should the handle be now? */
5596 int new_start
= y_pos
- 24;
5598 if (new_start
!= XINT (bar
->start
))
5600 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
5602 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5607 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5609 /* Return information to the user about the current position of the mouse
5610 on the scroll bar. */
5613 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
5615 Lisp_Object
*bar_window
;
5616 enum scroll_bar_part
*part
;
5618 unsigned long *time
;
5620 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5621 ControlRef ch
= SCROLL_BAR_CONTROL_REF (bar
);
5622 #if TARGET_API_MAC_CARBON
5623 WindowRef wp
= GetControlOwner (ch
);
5625 WindowRef wp
= (*ch
)->contrlOwner
;
5628 struct frame
*f
= mac_window_to_frame (wp
);
5629 int win_y
, top_range
;
5631 #if TARGET_API_MAC_CARBON
5632 GetGlobalMouse (&mouse_pos
);
5633 mouse_pos
.h
-= f
->left_pos
+ FRAME_OUTER_TO_INNER_DIFF_X (f
);
5634 mouse_pos
.v
-= f
->top_pos
+ FRAME_OUTER_TO_INNER_DIFF_Y (f
);
5636 SetPortWindowPort (wp
);
5637 GetMouse (&mouse_pos
);
5640 win_y
= mouse_pos
.v
- XINT (bar
->top
);
5641 top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
5643 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5647 if (! NILP (bar
->dragging
))
5648 win_y
-= XINT (bar
->dragging
);
5652 if (win_y
> top_range
)
5656 *bar_window
= bar
->window
;
5658 if (! NILP (bar
->dragging
))
5659 *part
= scroll_bar_handle
;
5660 else if (win_y
< XINT (bar
->start
))
5661 *part
= scroll_bar_above_handle
;
5662 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5663 *part
= scroll_bar_handle
;
5665 *part
= scroll_bar_below_handle
;
5667 XSETINT (*x
, win_y
);
5668 XSETINT (*y
, top_range
);
5671 last_mouse_scroll_bar
= Qnil
;
5673 *time
= last_mouse_movement_time
;
5677 /* The screen has been cleared so we may have changed foreground or
5678 background colors, and the scroll bars may need to be redrawn.
5679 Clear out the scroll bars, and ask for expose events, so we can
5683 x_scroll_bar_clear (f
)
5686 XTcondemn_scroll_bars (f
);
5687 XTjudge_scroll_bars (f
);
5691 /***********************************************************************
5693 ***********************************************************************/
5696 /* In identifiers such as function/variable names, Emacs tool bar is
5697 referred to as `tool_bar', and Carbon HIToolbar as `toolbar'. */
5699 #define TOOLBAR_IDENTIFIER (CFSTR ("org.gnu.Emacs.toolbar"))
5700 #define TOOLBAR_ICON_ITEM_IDENTIFIER (CFSTR ("org.gnu.Emacs.toolbar.icon"))
5702 #define TOOLBAR_ITEM_COMMAND_ID_OFFSET 'Tb\0\0'
5703 #define TOOLBAR_ITEM_COMMAND_ID_P(id) \
5704 (((id) & ~0xffff) == TOOLBAR_ITEM_COMMAND_ID_OFFSET)
5705 #define TOOLBAR_ITEM_COMMAND_ID_VALUE(id) \
5706 ((id) - TOOLBAR_ITEM_COMMAND_ID_OFFSET)
5707 #define TOOLBAR_ITEM_MAKE_COMMAND_ID(value) \
5708 ((value) + TOOLBAR_ITEM_COMMAND_ID_OFFSET)
5710 static int mac_event_to_emacs_modifiers
P_ ((EventRef
));
5711 static void mac_handle_origin_change
P_ ((struct frame
*));
5712 static OSStatus mac_handle_toolbar_command_event
P_ ((EventHandlerCallRef
,
5716 mac_move_window_with_gravity (f
, win_gravity
, left
, top
)
5723 mac_get_window_bounds (f
, &inner
, &outer
);
5725 switch (win_gravity
)
5727 case NorthWestGravity
:
5729 case SouthWestGravity
:
5730 left
+= inner
.left
- outer
.left
;
5736 left
+= ((inner
.left
- outer
.left
) + (inner
.right
- outer
.right
)) / 2;
5739 case NorthEastGravity
:
5741 case SouthEastGravity
:
5742 left
+= inner
.right
- outer
.right
;
5746 switch (win_gravity
)
5748 case NorthWestGravity
:
5750 case NorthEastGravity
:
5751 top
+= inner
.top
- outer
.top
;
5757 top
+= ((inner
.top
- outer
.top
) + (inner
.bottom
- outer
.bottom
)) / 2;
5760 case SouthWestGravity
:
5762 case SouthEastGravity
:
5763 top
+= inner
.bottom
- outer
.bottom
;
5767 MoveWindow (FRAME_MAC_WINDOW (f
), left
, top
, false);
5771 mac_get_window_origin_with_gravity (f
, win_gravity
, left
, top
)
5778 mac_get_window_bounds (f
, &inner
, &outer
);
5780 switch (win_gravity
)
5782 case NorthWestGravity
:
5784 case SouthWestGravity
:
5791 *left
= outer
.left
+ ((outer
.right
- outer
.left
)
5792 - (inner
.right
- inner
.left
)) / 2;
5795 case NorthEastGravity
:
5797 case SouthEastGravity
:
5798 *left
= outer
.right
- (inner
.right
- inner
.left
);
5802 switch (win_gravity
)
5804 case NorthWestGravity
:
5806 case NorthEastGravity
:
5813 *top
= outer
.top
+ ((outer
.bottom
- outer
.top
)
5814 - (inner
.bottom
- inner
.top
)) / 2;
5817 case SouthWestGravity
:
5819 case SouthEastGravity
:
5820 *top
= outer
.bottom
- (inner
.bottom
- inner
.top
);
5826 mac_handle_toolbar_event (next_handler
, event
, data
)
5827 EventHandlerCallRef next_handler
;
5831 OSStatus err
, result
= eventNotHandledErr
;
5833 switch (GetEventKind (event
))
5835 case kEventToolbarGetDefaultIdentifiers
:
5839 case kEventToolbarGetAllowedIdentifiers
:
5841 CFMutableArrayRef array
;
5843 GetEventParameter (event
, kEventParamMutableArray
,
5844 typeCFMutableArrayRef
, NULL
,
5845 sizeof (CFMutableArrayRef
), NULL
, &array
);
5846 CFArrayAppendValue (array
, TOOLBAR_ICON_ITEM_IDENTIFIER
);
5851 case kEventToolbarCreateItemWithIdentifier
:
5853 CFStringRef identifier
;
5854 HIToolbarItemRef item
= NULL
;
5856 GetEventParameter (event
, kEventParamToolbarItemIdentifier
,
5857 typeCFStringRef
, NULL
,
5858 sizeof (CFStringRef
), NULL
, &identifier
);
5860 if (CFStringCompare (identifier
, TOOLBAR_ICON_ITEM_IDENTIFIER
, 0)
5861 == kCFCompareEqualTo
)
5862 HIToolbarItemCreate (identifier
,
5863 kHIToolbarItemAllowDuplicates
5864 | kHIToolbarItemCantBeRemoved
, &item
);
5868 SetEventParameter (event
, kEventParamToolbarItem
,
5869 typeHIToolbarItemRef
,
5870 sizeof (HIToolbarItemRef
), &item
);
5884 mac_image_spec_to_cg_image (f
, image
)
5888 if (!valid_image_p (image
))
5892 int img_id
= lookup_image (f
, image
);
5893 struct image
*img
= IMAGE_FROM_ID (f
, img_id
);
5895 prepare_image_for_display (f
, img
);
5897 return img
->data
.ptr_val
;
5901 /* Create a tool bar for frame F. */
5904 mac_create_frame_tool_bar (f
)
5908 HIToolbarRef toolbar
;
5910 err
= HIToolbarCreate (TOOLBAR_IDENTIFIER
, kHIToolbarNoAttributes
,
5914 static const EventTypeSpec specs
[] =
5915 {{kEventClassToolbar
, kEventToolbarGetDefaultIdentifiers
},
5916 {kEventClassToolbar
, kEventToolbarGetAllowedIdentifiers
},
5917 {kEventClassToolbar
, kEventToolbarCreateItemWithIdentifier
}};
5919 err
= InstallEventHandler (HIObjectGetEventTarget (toolbar
),
5920 mac_handle_toolbar_event
,
5921 GetEventTypeCount (specs
), specs
,
5926 err
= HIToolbarSetDisplayMode (toolbar
, kHIToolbarDisplayModeIconOnly
);
5929 static const EventTypeSpec specs
[] =
5930 {{kEventClassCommand
, kEventCommandProcess
}};
5932 err
= InstallWindowEventHandler (FRAME_MAC_WINDOW (f
),
5933 mac_handle_toolbar_command_event
,
5934 GetEventTypeCount (specs
),
5938 err
= SetWindowToolbar (FRAME_MAC_WINDOW (f
), toolbar
);
5941 CFRelease (toolbar
);
5946 /* Update the tool bar for frame F. Add new buttons and remove old. */
5949 update_frame_tool_bar (f
)
5952 HIToolbarRef toolbar
= NULL
;
5954 CFArrayRef old_items
= NULL
;
5956 int i
, pos
, win_gravity
= f
->output_data
.mac
->toolbar_win_gravity
;
5957 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
5961 GetWindowToolbar (FRAME_MAC_WINDOW (f
), &toolbar
);
5962 if (toolbar
== NULL
)
5964 mac_create_frame_tool_bar (f
);
5965 GetWindowToolbar (FRAME_MAC_WINDOW (f
), &toolbar
);
5966 if (toolbar
== NULL
)
5968 if (win_gravity
>= NorthWestGravity
&& win_gravity
<= SouthEastGravity
)
5969 mac_get_window_origin_with_gravity (f
, win_gravity
, &left
, &top
);
5972 HIToolbarCopyItems (toolbar
, &old_items
);
5973 if (old_items
== NULL
)
5976 old_count
= CFArrayGetCount (old_items
);
5978 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
5980 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
5982 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
5983 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
5986 CGImageRef cg_image
;
5988 HIToolbarItemRef item
;
5990 /* If image is a vector, choose the image according to the
5992 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
5993 if (VECTORP (image
))
5997 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
5998 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
6001 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
6002 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
6004 xassert (ASIZE (image
) >= idx
);
6005 image
= AREF (image
, idx
);
6010 cg_image
= mac_image_spec_to_cg_image (f
, image
);
6011 /* Ignore invalid image specifications. */
6012 if (cg_image
== NULL
)
6015 label
= cfstring_create_with_string (PROP (TOOL_BAR_ITEM_CAPTION
));
6019 if (pos
< old_count
)
6021 CGImageRef old_cg_image
= NULL
;
6022 CFStringRef old_label
= NULL
;
6023 Boolean old_enabled_p
;
6025 item
= (HIToolbarItemRef
) CFArrayGetValueAtIndex (old_items
, pos
);
6027 HIToolbarItemCopyImage (item
, &old_cg_image
);
6028 if (cg_image
!= old_cg_image
)
6029 HIToolbarItemSetImage (item
, cg_image
);
6030 CGImageRelease (old_cg_image
);
6032 HIToolbarItemCopyLabel (item
, &old_label
);
6033 if (CFStringCompare (label
, old_label
, 0) != kCFCompareEqualTo
)
6034 HIToolbarItemSetLabel (item
, label
);
6035 CFRelease (old_label
);
6037 old_enabled_p
= HIToolbarItemIsEnabled (item
);
6038 if ((enabled_p
|| idx
>= 0) != old_enabled_p
)
6039 HIToolbarItemSetEnabled (item
, (enabled_p
|| idx
>= 0));
6044 HIToolbarCreateItemWithIdentifier (toolbar
,
6045 TOOLBAR_ICON_ITEM_IDENTIFIER
,
6049 HIToolbarItemSetImage (item
, cg_image
);
6050 HIToolbarItemSetLabel (item
, label
);
6051 HIToolbarItemSetEnabled (item
, (enabled_p
|| idx
>= 0));
6052 HIToolbarAppendItem (toolbar
, item
);
6060 HIToolbarItemSetCommandID (item
, TOOLBAR_ITEM_MAKE_COMMAND_ID (i
));
6065 CFRelease (old_items
);
6067 while (pos
< old_count
)
6068 HIToolbarRemoveItemAtIndex (toolbar
, --old_count
);
6070 ShowHideWindowToolbar (FRAME_MAC_WINDOW (f
), true,
6071 !win_gravity
&& f
== mac_focus_frame (dpyinfo
));
6072 /* Mac OS X 10.3 does not issue kEventWindowBoundsChanged events on
6073 toolbar visibility change. */
6074 mac_handle_origin_change (f
);
6075 if (win_gravity
>= NorthWestGravity
&& win_gravity
<= SouthEastGravity
)
6077 mac_move_window_with_gravity (f
, win_gravity
, left
, top
);
6078 /* If the title bar is completely outside the screen, adjust the
6080 ConstrainWindowToScreen (FRAME_MAC_WINDOW (f
), kWindowTitleBarRgn
,
6081 kWindowConstrainMoveRegardlessOfFit
6082 | kWindowConstrainAllowPartial
, NULL
, NULL
);
6083 f
->output_data
.mac
->toolbar_win_gravity
= 0;
6090 /* Hide the tool bar on frame F. Unlike the counterpart on GTK+, it
6091 doesn't deallocate the resources. */
6094 free_frame_tool_bar (f
)
6097 if (IsWindowToolbarVisible (FRAME_MAC_WINDOW (f
)))
6099 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6102 ShowHideWindowToolbar (FRAME_MAC_WINDOW (f
), false,
6103 (NILP (Fsymbol_value
6104 (intern ("frame-notice-user-settings")))
6105 && f
== mac_focus_frame (dpyinfo
)));
6106 /* Mac OS X 10.3 does not issue kEventWindowBoundsChanged events
6107 on toolbar visibility change. */
6108 mac_handle_origin_change (f
);
6114 mac_tool_bar_note_mouse_movement (f
, event
)
6119 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6121 HIViewRef item_view
;
6124 mouse_down_p
= (dpyinfo
->grabbed
6125 && f
== last_mouse_frame
6126 && FRAME_LIVE_P (f
));
6130 err
= HIViewGetViewForMouseEvent (HIViewGetRoot (FRAME_MAC_WINDOW (f
)),
6132 /* This doesn't work on Mac OS X 10.2. On Mac OS X 10.3 and 10.4, a
6133 toolbar item view seems to have the same command ID with that of
6134 the toolbar item. */
6136 err
= GetControlCommandID (item_view
, &command_id
);
6137 if (err
== noErr
&& TOOLBAR_ITEM_COMMAND_ID_P (command_id
))
6139 int i
= TOOLBAR_ITEM_COMMAND_ID_VALUE (command_id
);
6141 if (i
< f
->n_tool_bar_items
)
6144 HIViewRef content_view
;
6146 err
= HIViewGetBounds (item_view
, &bounds
);
6148 err
= HIViewFindByID (HIViewGetRoot (FRAME_MAC_WINDOW (f
)),
6149 kHIViewWindowContentID
, &content_view
);
6151 err
= HIViewConvertRect (&bounds
, item_view
, content_view
);
6153 SetRect (&last_mouse_glyph
,
6154 CGRectGetMinX (bounds
), CGRectGetMinY (bounds
),
6155 CGRectGetMaxX (bounds
), CGRectGetMaxY (bounds
));
6157 help_echo_object
= help_echo_window
= Qnil
;
6159 help_echo_string
= PROP (TOOL_BAR_ITEM_HELP
);
6160 if (NILP (help_echo_string
))
6161 help_echo_string
= PROP (TOOL_BAR_ITEM_CAPTION
);
6167 mac_handle_toolbar_command_event (next_handler
, event
, data
)
6168 EventHandlerCallRef next_handler
;
6172 OSStatus err
, result
= eventNotHandledErr
;
6173 struct frame
*f
= (struct frame
*) data
;
6176 err
= GetEventParameter (event
, kEventParamDirectObject
,
6177 typeHICommand
, NULL
,
6178 sizeof (HICommand
), NULL
, &command
);
6182 switch (GetEventKind (event
))
6184 case kEventCommandProcess
:
6185 if (!TOOLBAR_ITEM_COMMAND_ID_P (command
.commandID
))
6186 result
= CallNextEventHandler (next_handler
, event
);
6189 int i
= TOOLBAR_ITEM_COMMAND_ID_VALUE (command
.commandID
);
6191 if (i
< f
->n_tool_bar_items
6192 && !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
)))
6195 struct input_event buf
;
6199 XSETFRAME (frame
, f
);
6200 buf
.kind
= TOOL_BAR_EVENT
;
6201 buf
.frame_or_window
= frame
;
6203 kbd_buffer_store_event (&buf
);
6205 buf
.kind
= TOOL_BAR_EVENT
;
6206 buf
.frame_or_window
= frame
;
6207 buf
.arg
= PROP (TOOL_BAR_ITEM_KEY
);
6208 buf
.modifiers
= mac_event_to_emacs_modifiers (event
);
6209 kbd_buffer_store_event (&buf
);
6223 #endif /* USE_MAC_TOOLBAR */
6226 /***********************************************************************
6228 ***********************************************************************/
6230 /* Set clipping for output in glyph row ROW. W is the window in which
6231 we operate. GC is the graphics context to set clipping in.
6233 ROW may be a text row or, e.g., a mode line. Text rows must be
6234 clipped to the interior of the window dedicated to text display,
6235 mode lines must be clipped to the whole window. */
6238 x_clip_to_row (w
, row
, area
, gc
)
6240 struct glyph_row
*row
;
6244 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6246 int window_x
, window_y
, window_width
;
6248 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
6250 clip_rect
.left
= window_x
;
6251 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
6252 clip_rect
.top
= max (clip_rect
.top
, window_y
);
6253 clip_rect
.right
= clip_rect
.left
+ window_width
;
6254 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
6256 mac_set_clip_rectangles (FRAME_MAC_DISPLAY (f
), gc
, &clip_rect
, 1);
6260 /* Draw a hollow box cursor on window W in glyph row ROW. */
6263 x_draw_hollow_cursor (w
, row
)
6265 struct glyph_row
*row
;
6267 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6268 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6269 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
6272 struct glyph
*cursor_glyph
;
6275 /* Get the glyph the cursor is on. If we can't tell because
6276 the current matrix is invalid or such, give up. */
6277 cursor_glyph
= get_phys_cursor_glyph (w
);
6278 if (cursor_glyph
== NULL
)
6281 /* Compute frame-relative coordinates for phys cursor. */
6282 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
6283 wd
= w
->phys_cursor_width
;
6285 /* The foreground of cursor_gc is typically the same as the normal
6286 background color, which can cause the cursor box to be invisible. */
6287 xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
6288 if (dpyinfo
->scratch_cursor_gc
)
6289 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
6291 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_MAC_WINDOW (f
),
6292 GCForeground
, &xgcv
);
6293 gc
= dpyinfo
->scratch_cursor_gc
;
6295 /* Set clipping, draw the rectangle, and reset clipping again. */
6296 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
6297 mac_draw_rectangle (f
, gc
, x
, y
, wd
, h
- 1);
6298 mac_reset_clip_rectangles (dpy
, gc
);
6302 /* Draw a bar cursor on window W in glyph row ROW.
6304 Implementation note: One would like to draw a bar cursor with an
6305 angle equal to the one given by the font property XA_ITALIC_ANGLE.
6306 Unfortunately, I didn't find a font yet that has this property set.
6310 x_draw_bar_cursor (w
, row
, width
, kind
)
6312 struct glyph_row
*row
;
6314 enum text_cursor_kinds kind
;
6316 struct frame
*f
= XFRAME (w
->frame
);
6317 struct glyph
*cursor_glyph
;
6319 /* If cursor is out of bounds, don't draw garbage. This can happen
6320 in mini-buffer windows when switching between echo area glyphs
6322 cursor_glyph
= get_phys_cursor_glyph (w
);
6323 if (cursor_glyph
== NULL
)
6326 /* If on an image, draw like a normal cursor. That's usually better
6327 visible than drawing a bar, esp. if the image is large so that
6328 the bar might not be in the window. */
6329 if (cursor_glyph
->type
== IMAGE_GLYPH
)
6331 struct glyph_row
*row
;
6332 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
6333 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
6337 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
6338 Window window
= FRAME_MAC_WINDOW (f
);
6339 GC gc
= FRAME_MAC_DISPLAY_INFO (f
)->scratch_cursor_gc
;
6340 unsigned long mask
= GCForeground
| GCBackground
;
6341 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
6344 /* If the glyph's background equals the color we normally draw
6345 the bar cursor in, the bar cursor in its normal color is
6346 invisible. Use the glyph's foreground color instead in this
6347 case, on the assumption that the glyph's colors are chosen so
6348 that the glyph is legible. */
6349 if (face
->background
== f
->output_data
.mac
->cursor_pixel
)
6350 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
6352 xgcv
.background
= xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
6355 XChangeGC (dpy
, gc
, mask
, &xgcv
);
6358 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
6359 FRAME_MAC_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
6363 width
= FRAME_CURSOR_WIDTH (f
);
6364 width
= min (cursor_glyph
->pixel_width
, width
);
6366 w
->phys_cursor_width
= width
;
6367 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
6369 if (kind
== BAR_CURSOR
)
6370 mac_fill_rectangle (f
, gc
,
6371 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
6372 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
6373 width
, row
->height
);
6375 mac_fill_rectangle (f
, gc
,
6376 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
6377 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
6378 row
->height
- width
),
6379 cursor_glyph
->pixel_width
,
6382 mac_reset_clip_rectangles (dpy
, gc
);
6387 /* RIF: Define cursor CURSOR on frame F. */
6390 mac_define_frame_cursor (f
, cursor
)
6394 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6396 if (dpyinfo
->x_focus_frame
== f
)
6397 SetThemeCursor (cursor
);
6401 /* RIF: Clear area on frame F. */
6404 mac_clear_frame_area (f
, x
, y
, width
, height
)
6406 int x
, y
, width
, height
;
6408 mac_clear_area (f
, x
, y
, width
, height
);
6412 /* RIF: Draw cursor on window W. */
6415 mac_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
6417 struct glyph_row
*glyph_row
;
6419 int cursor_type
, cursor_width
;
6424 w
->phys_cursor_type
= cursor_type
;
6425 w
->phys_cursor_on_p
= 1;
6427 if (glyph_row
->exact_window_width_line_p
6428 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
6430 glyph_row
->cursor_in_fringe_p
= 1;
6431 draw_fringe_bitmap (w
, glyph_row
, 0);
6434 switch (cursor_type
)
6436 case HOLLOW_BOX_CURSOR
:
6437 x_draw_hollow_cursor (w
, glyph_row
);
6440 case FILLED_BOX_CURSOR
:
6441 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
6445 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
6449 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
6453 w
->phys_cursor_width
= 0;
6465 #if 0 /* MAC_TODO: no icon support yet. */
6467 x_bitmap_icon (f
, icon
)
6473 if (FRAME_W32_WINDOW (f
) == 0)
6477 hicon
= LoadIcon (hinst
, EMACS_CLASS
);
6478 else if (STRINGP (icon
))
6479 hicon
= LoadImage (NULL
, (LPCTSTR
) SDATA (icon
), IMAGE_ICON
, 0, 0,
6480 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
6481 else if (SYMBOLP (icon
))
6485 if (EQ (icon
, intern ("application")))
6486 name
= (LPCTSTR
) IDI_APPLICATION
;
6487 else if (EQ (icon
, intern ("hand")))
6488 name
= (LPCTSTR
) IDI_HAND
;
6489 else if (EQ (icon
, intern ("question")))
6490 name
= (LPCTSTR
) IDI_QUESTION
;
6491 else if (EQ (icon
, intern ("exclamation")))
6492 name
= (LPCTSTR
) IDI_EXCLAMATION
;
6493 else if (EQ (icon
, intern ("asterisk")))
6494 name
= (LPCTSTR
) IDI_ASTERISK
;
6495 else if (EQ (icon
, intern ("winlogo")))
6496 name
= (LPCTSTR
) IDI_WINLOGO
;
6500 hicon
= LoadIcon (NULL
, name
);
6508 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
6513 #endif /* MAC_TODO */
6515 /************************************************************************
6517 ************************************************************************/
6519 /* Display Error Handling functions not used on W32. Listing them here
6520 helps diff stay in step when comparing w32term.c with xterm.c.
6522 x_error_catcher (display, error)
6523 x_catch_errors (dpy)
6524 x_catch_errors_unwind (old_val)
6525 x_check_errors (dpy, format)
6526 x_had_errors_p (dpy)
6527 x_clear_errors (dpy)
6528 x_uncatch_errors (dpy, count)
6530 x_connection_signal (signalnum)
6531 x_connection_closed (dpy, error_message)
6532 x_error_quitter (display, error)
6533 x_error_handler (display, error)
6534 x_io_error_quitter (display)
6539 /* Changing the font of the frame. */
6541 /* Give frame F the font named FONTNAME as its default font, and
6542 return the full name of that font. FONTNAME may be a wildcard
6543 pattern; in that case, we choose some font that fits the pattern.
6544 The return value shows which font we chose. */
6547 x_new_font (f
, fontname
)
6549 register char *fontname
;
6551 struct font_info
*fontp
6552 = FS_LOAD_FONT (f
, 0, fontname
, -1);
6557 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
6558 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
6559 FRAME_FONTSET (f
) = -1;
6561 FRAME_COLUMN_WIDTH (f
) = fontp
->average_width
;
6562 FRAME_SPACE_WIDTH (f
) = fontp
->space_width
;
6563 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (FRAME_FONT (f
));
6565 compute_fringe_widths (f
, 1);
6567 /* Compute the scroll bar width in character columns. */
6568 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
6570 int wid
= FRAME_COLUMN_WIDTH (f
);
6571 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
6572 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
6576 int wid
= FRAME_COLUMN_WIDTH (f
);
6577 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
6580 /* Now make the frame display the given font. */
6581 if (FRAME_MAC_WINDOW (f
) != 0)
6583 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->normal_gc
,
6585 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->reverse_gc
,
6587 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->cursor_gc
,
6590 /* Don't change the size of a tip frame; there's no point in
6591 doing it because it's done in Fx_show_tip, and it leads to
6592 problems because the tip frame has no widget. */
6593 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
6594 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
6597 return build_string (fontp
->full_name
);
6600 /* Give frame F the fontset named FONTSETNAME as its default font, and
6601 return the full name of that fontset. FONTSETNAME may be a wildcard
6602 pattern; in that case, we choose some fontset that fits the pattern.
6603 The return value shows which fontset we chose. */
6606 x_new_fontset (f
, fontsetname
)
6610 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
6616 if (FRAME_FONTSET (f
) == fontset
)
6617 /* This fontset is already set in frame F. There's nothing more
6619 return fontset_name (fontset
);
6621 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
6623 if (!STRINGP (result
))
6624 /* Can't load ASCII font. */
6627 /* Since x_new_font doesn't update any fontset information, do it now. */
6628 FRAME_FONTSET (f
) = fontset
;
6630 return build_string (fontsetname
);
6634 /***********************************************************************
6635 TODO: W32 Input Methods
6636 ***********************************************************************/
6637 /* Listing missing functions from xterm.c helps diff stay in step.
6639 xim_destroy_callback (xim, client_data, call_data)
6640 xim_open_dpy (dpyinfo, resource_name)
6642 xim_instantiate_callback (display, client_data, call_data)
6643 xim_initialize (dpyinfo, resource_name)
6644 xim_close_dpy (dpyinfo)
6650 mac_get_window_bounds (f
, inner
, outer
)
6652 Rect
*inner
, *outer
;
6654 #if TARGET_API_MAC_CARBON
6655 GetWindowBounds (FRAME_MAC_WINDOW (f
), kWindowContentRgn
, inner
);
6656 GetWindowBounds (FRAME_MAC_WINDOW (f
), kWindowStructureRgn
, outer
);
6657 #else /* not TARGET_API_MAC_CARBON */
6658 RgnHandle region
= NewRgn ();
6660 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowContentRgn
, region
);
6661 *inner
= (*region
)->rgnBBox
;
6662 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowStructureRgn
, region
);
6663 *outer
= (*region
)->rgnBBox
;
6664 DisposeRgn (region
);
6665 #endif /* not TARGET_API_MAC_CARBON */
6669 mac_handle_origin_change (f
)
6672 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6676 mac_handle_size_change (f
, pixelwidth
, pixelheight
)
6678 int pixelwidth
, pixelheight
;
6682 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, pixelwidth
);
6683 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, pixelheight
);
6685 if (cols
!= FRAME_COLS (f
)
6686 || rows
!= FRAME_LINES (f
)
6687 || pixelwidth
!= FRAME_PIXEL_WIDTH (f
)
6688 || pixelheight
!= FRAME_PIXEL_HEIGHT (f
))
6690 /* We pass 1 for DELAY since we can't run Lisp code inside of
6692 change_frame_size (f
, rows
, cols
, 0, 1, 0);
6693 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
6694 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
6695 SET_FRAME_GARBAGED (f
);
6697 /* If cursor was outside the new size, mark it as off. */
6698 mark_window_cursors_off (XWINDOW (f
->root_window
));
6700 /* Clear out any recollection of where the mouse highlighting
6701 was, since it might be in a place that's outside the new
6702 frame size. Actually checking whether it is outside is a
6703 pain in the neck, so don't try--just let the highlighting be
6704 done afresh with new size. */
6705 cancel_mouse_face (f
);
6707 #if TARGET_API_MAC_CARBON
6708 if (f
->output_data
.mac
->hourglass_control
)
6711 mac_prepare_for_quickdraw (f
);
6713 MoveControl (f
->output_data
.mac
->hourglass_control
,
6714 pixelwidth
- HOURGLASS_WIDTH
, 0);
6721 /* Calculate the absolute position in frame F
6722 from its current recorded position values and gravity. */
6725 x_calc_absolute_position (f
)
6728 int width_diff
= 0, height_diff
= 0;
6729 int flags
= f
->size_hint_flags
;
6732 /* We have nothing to do if the current position
6733 is already for the top-left corner. */
6734 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
6737 /* Find the offsets of the outside upper-left corner of
6738 the inner window, with respect to the outer window. */
6740 mac_get_window_bounds (f
, &inner
, &outer
);
6743 width_diff
= (outer
.right
- outer
.left
) - (inner
.right
- inner
.left
);
6744 height_diff
= (outer
.bottom
- outer
.top
) - (inner
.bottom
- inner
.top
);
6746 /* Treat negative positions as relative to the leftmost bottommost
6747 position that fits on the screen. */
6748 if (flags
& XNegative
)
6749 f
->left_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->width
6751 - FRAME_PIXEL_WIDTH (f
)
6754 if (flags
& YNegative
)
6755 f
->top_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->height
6757 - FRAME_PIXEL_HEIGHT (f
)
6760 /* The left_pos and top_pos
6761 are now relative to the top and left screen edges,
6762 so the flags should correspond. */
6763 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
6766 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
6767 to really change the position, and 0 when calling from
6768 x_make_frame_visible (in that case, XOFF and YOFF are the current
6769 position values). It is -1 when calling from x_set_frame_parameters,
6770 which means, do adjust for borders but don't change the gravity. */
6773 x_set_offset (f
, xoff
, yoff
, change_gravity
)
6775 register int xoff
, yoff
;
6778 if (change_gravity
> 0)
6782 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
6784 f
->size_hint_flags
|= XNegative
;
6786 f
->size_hint_flags
|= YNegative
;
6787 f
->win_gravity
= NorthWestGravity
;
6789 x_calc_absolute_position (f
);
6792 x_wm_set_size_hint (f
, (long) 0, 0);
6794 #if TARGET_API_MAC_CARBON
6795 MoveWindowStructure (FRAME_MAC_WINDOW (f
), f
->left_pos
, f
->top_pos
);
6796 /* If the title bar is completely outside the screen, adjust the
6798 ConstrainWindowToScreen (FRAME_MAC_WINDOW (f
), kWindowTitleBarRgn
,
6799 kWindowConstrainMoveRegardlessOfFit
6800 | kWindowConstrainAllowPartial
, NULL
, NULL
);
6801 if (!NILP (tip_frame
) && XFRAME (tip_frame
) == f
)
6802 mac_handle_origin_change (f
);
6805 Rect inner
, outer
, screen_rect
, dummy
;
6806 RgnHandle region
= NewRgn ();
6808 mac_get_window_bounds (f
, &inner
, &outer
);
6809 f
->x_pixels_diff
= inner
.left
- outer
.left
;
6810 f
->y_pixels_diff
= inner
.top
- outer
.top
;
6811 MoveWindow (FRAME_MAC_WINDOW (f
), f
->left_pos
+ f
->x_pixels_diff
,
6812 f
->top_pos
+ f
->y_pixels_diff
, false);
6814 /* If the title bar is completely outside the screen, adjust the
6815 position. The variable `outer' holds the title bar rectangle.
6816 The variable `inner' holds slightly smaller one than `outer',
6817 so that the calculation of overlapping may not become too
6819 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowTitleBarRgn
, region
);
6820 outer
= (*region
)->rgnBBox
;
6821 DisposeRgn (region
);
6823 InsetRect (&inner
, 8, 8);
6824 screen_rect
= qd
.screenBits
.bounds
;
6825 screen_rect
.top
+= GetMBarHeight ();
6827 if (!SectRect (&inner
, &screen_rect
, &dummy
))
6829 if (inner
.right
<= screen_rect
.left
)
6830 f
->left_pos
= screen_rect
.left
;
6831 else if (inner
.left
>= screen_rect
.right
)
6832 f
->left_pos
= screen_rect
.right
- (outer
.right
- outer
.left
);
6834 if (inner
.bottom
<= screen_rect
.top
)
6835 f
->top_pos
= screen_rect
.top
;
6836 else if (inner
.top
>= screen_rect
.bottom
)
6837 f
->top_pos
= screen_rect
.bottom
- (outer
.bottom
- outer
.top
);
6839 MoveWindow (FRAME_MAC_WINDOW (f
), f
->left_pos
+ f
->x_pixels_diff
,
6840 f
->top_pos
+ f
->y_pixels_diff
, false);
6848 /* Call this to change the size of frame F's x-window.
6849 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
6850 for this size change and subsequent size changes.
6851 Otherwise we leave the window gravity unchanged. */
6854 x_set_window_size (f
, change_gravity
, cols
, rows
)
6859 int pixelwidth
, pixelheight
;
6863 check_frame_size (f
, &rows
, &cols
);
6864 f
->scroll_bar_actual_width
6865 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
6867 compute_fringe_widths (f
, 0);
6869 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
6870 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
6872 f
->win_gravity
= NorthWestGravity
;
6873 x_wm_set_size_hint (f
, (long) 0, 0);
6875 SizeWindow (FRAME_MAC_WINDOW (f
), pixelwidth
, pixelheight
, 0);
6877 #if TARGET_API_MAC_CARBON
6878 if (!NILP (tip_frame
) && f
== XFRAME (tip_frame
))
6880 mac_handle_size_change (f
, pixelwidth
, pixelheight
);
6882 if (f
->output_data
.mac
->internal_border_width
6883 != FRAME_INTERNAL_BORDER_WIDTH (f
))
6885 mac_clear_window (f
);
6886 f
->output_data
.mac
->internal_border_width
6887 = FRAME_INTERNAL_BORDER_WIDTH (f
);
6890 SET_FRAME_GARBAGED (f
);
6895 /* Mouse warping. */
6897 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
6900 x_set_mouse_position (f
, x
, y
)
6906 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
6907 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
6909 if (pix_x
< 0) pix_x
= 0;
6910 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
6912 if (pix_y
< 0) pix_y
= 0;
6913 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
6915 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
6919 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
6924 pix_x
+= f
->left_pos
+ FRAME_OUTER_TO_INNER_DIFF_X (f
);
6925 pix_y
+= f
->top_pos
+ FRAME_OUTER_TO_INNER_DIFF_Y (f
);
6928 CGWarpMouseCursorPosition (CGPointMake (pix_x
, pix_y
));
6931 #if 0 /* MAC_TODO: LMSetMouseLocation and CursorDeviceMoveTo are non-Carbon */
6934 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
6935 0, 0, 0, 0, pix_x
, pix_y
);
6941 /* focus shifting, raising and lowering. */
6944 x_focus_on_frame (f
)
6947 #if 0 /* This proves to be unpleasant. */
6951 /* I don't think that the ICCCM allows programs to do things like this
6952 without the interaction of the window manager. Whatever you end up
6953 doing with this code, do it to x_unfocus_frame too. */
6954 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6955 RevertToPointerRoot
, CurrentTime
);
6965 /* Raise frame F. */
6971 if (f
->async_visible
)
6974 BringToFront (FRAME_MAC_WINDOW (f
));
6979 /* Lower frame F. */
6985 if (f
->async_visible
)
6988 SendBehind (FRAME_MAC_WINDOW (f
), NULL
);
6994 XTframe_raise_lower (f
, raise_flag
)
7004 /* Change of visibility. */
7007 mac_handle_visibility_change (f
)
7010 WindowRef wp
= FRAME_MAC_WINDOW (f
);
7011 int visible
= 0, iconified
= 0;
7012 struct input_event buf
;
7014 if (IsWindowVisible (wp
))
7016 if (IsWindowCollapsed (wp
))
7022 if (!f
->async_visible
&& visible
)
7026 /* wait_reading_process_output will notice this and update
7027 the frame's display structures. If we were made
7028 invisible, we should not set garbaged, because that stops
7029 redrawing on Update events. */
7030 SET_FRAME_GARBAGED (f
);
7033 buf
.kind
= DEICONIFY_EVENT
;
7034 XSETFRAME (buf
.frame_or_window
, f
);
7036 kbd_buffer_store_event (&buf
);
7038 else if (! NILP (Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
7039 /* Force a redisplay sooner or later to update the
7040 frame titles in case this is the second frame. */
7041 record_asynch_buffer_change ();
7043 else if (f
->async_visible
&& !visible
)
7047 buf
.kind
= ICONIFY_EVENT
;
7048 XSETFRAME (buf
.frame_or_window
, f
);
7050 kbd_buffer_store_event (&buf
);
7053 f
->async_visible
= visible
;
7054 f
->async_iconified
= iconified
;
7057 /* This tries to wait until the frame is really visible.
7058 However, if the window manager asks the user where to position
7059 the frame, this will return before the user finishes doing that.
7060 The frame will not actually be visible at that time,
7061 but it will become visible later when the window manager
7062 finishes with it. */
7065 x_make_frame_visible (f
)
7070 if (! FRAME_VISIBLE_P (f
))
7072 /* We test FRAME_GARBAGED_P here to make sure we don't
7073 call x_set_offset a second time
7074 if we get to x_make_frame_visible a second time
7075 before the window gets really visible. */
7076 if (! FRAME_ICONIFIED_P (f
)
7077 && ! f
->output_data
.mac
->asked_for_visible
)
7078 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
7080 f
->output_data
.mac
->asked_for_visible
= 1;
7082 CollapseWindow (FRAME_MAC_WINDOW (f
), false);
7083 ShowWindow (FRAME_MAC_WINDOW (f
));
7086 XFlush (FRAME_MAC_DISPLAY (f
));
7088 /* Synchronize to ensure Emacs knows the frame is visible
7089 before we do anything else. We do this loop with input not blocked
7090 so that incoming events are handled. */
7095 /* This must come after we set COUNT. */
7098 XSETFRAME (frame
, f
);
7100 /* Wait until the frame is visible. Process X events until a
7101 MapNotify event has been seen, or until we think we won't get a
7102 MapNotify at all.. */
7103 for (count
= input_signal_count
+ 10;
7104 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
7106 /* Force processing of queued events. */
7109 /* Machines that do polling rather than SIGIO have been
7110 observed to go into a busy-wait here. So we'll fake an
7111 alarm signal to let the handler know that there's something
7112 to be read. We used to raise a real alarm, but it seems
7113 that the handler isn't always enabled here. This is
7115 if (input_polling_used ())
7117 /* It could be confusing if a real alarm arrives while
7118 processing the fake one. Turn it off and let the
7119 handler reset it. */
7120 extern void poll_for_input_1
P_ ((void));
7121 int old_poll_suppress_count
= poll_suppress_count
;
7122 poll_suppress_count
= 1;
7123 poll_for_input_1 ();
7124 poll_suppress_count
= old_poll_suppress_count
;
7127 /* See if a MapNotify event has been processed. */
7128 FRAME_SAMPLE_VISIBILITY (f
);
7133 /* Change from mapped state to withdrawn state. */
7135 /* Make the frame visible (mapped and not iconified). */
7138 x_make_frame_invisible (f
)
7141 /* A deactivate event does not occur when the last visible frame is
7142 made invisible. So if we clear the highlight here, it will not
7143 be rehighlighted when it is made visible. */
7145 /* Don't keep the highlight on an invisible frame. */
7146 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
7147 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
7152 #if !TARGET_API_MAC_CARBON
7153 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
7154 that the current position of the window is user-specified, rather than
7155 program-specified, so that when the window is mapped again, it will be
7156 placed at the same location, without forcing the user to position it
7157 by hand again (they have already done that once for this window.) */
7158 x_wm_set_size_hint (f
, (long) 0, 1);
7161 HideWindow (FRAME_MAC_WINDOW (f
));
7165 #if !TARGET_API_MAC_CARBON
7166 mac_handle_visibility_change (f
);
7170 /* Change window state from mapped to iconified. */
7178 /* A deactivate event does not occur when the last visible frame is
7179 iconified. So if we clear the highlight here, it will not be
7180 rehighlighted when it is deiconified. */
7182 /* Don't keep the highlight on an invisible frame. */
7183 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
7184 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
7187 if (f
->async_iconified
)
7192 FRAME_SAMPLE_VISIBILITY (f
);
7194 if (! FRAME_VISIBLE_P (f
))
7195 ShowWindow (FRAME_MAC_WINDOW (f
));
7197 err
= CollapseWindow (FRAME_MAC_WINDOW (f
), true);
7202 error ("Can't notify window manager of iconification");
7204 #if !TARGET_API_MAC_CARBON
7205 mac_handle_visibility_change (f
);
7210 /* Free X resources of frame F. */
7213 x_free_frame_resources (f
)
7216 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7217 WindowRef wp
= FRAME_MAC_WINDOW (f
);
7221 if (wp
!= tip_window
)
7222 remove_window_handler (wp
);
7225 mac_prepare_for_quickdraw (f
);
7228 if (wp
== tip_window
)
7229 /* Neither WaitNextEvent nor ReceiveNextEvent receives `window
7230 closed' event. So we reset tip_window here. */
7233 free_frame_menubar (f
);
7235 if (FRAME_FACE_CACHE (f
))
7236 free_frame_faces (f
);
7240 if (FRAME_SIZE_HINTS (f
))
7241 xfree (FRAME_SIZE_HINTS (f
));
7243 xfree (f
->output_data
.mac
);
7244 f
->output_data
.mac
= NULL
;
7246 if (f
== dpyinfo
->x_focus_frame
)
7248 dpyinfo
->x_focus_frame
= 0;
7249 #if USE_MAC_FONT_PANEL
7250 mac_set_font_info_for_selection (NULL
, DEFAULT_FACE_ID
, 0);
7253 if (f
== dpyinfo
->x_focus_event_frame
)
7254 dpyinfo
->x_focus_event_frame
= 0;
7255 if (f
== dpyinfo
->x_highlight_frame
)
7256 dpyinfo
->x_highlight_frame
= 0;
7258 if (f
== dpyinfo
->mouse_face_mouse_frame
)
7260 dpyinfo
->mouse_face_beg_row
7261 = dpyinfo
->mouse_face_beg_col
= -1;
7262 dpyinfo
->mouse_face_end_row
7263 = dpyinfo
->mouse_face_end_col
= -1;
7264 dpyinfo
->mouse_face_window
= Qnil
;
7265 dpyinfo
->mouse_face_deferred_gc
= 0;
7266 dpyinfo
->mouse_face_mouse_frame
= 0;
7273 /* Destroy the X window of frame F. */
7276 x_destroy_window (f
)
7279 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7281 x_free_frame_resources (f
);
7283 dpyinfo
->reference_count
--;
7287 /* Setting window manager hints. */
7289 /* Set the normal size hints for the window manager, for frame F.
7290 FLAGS is the flags word to use--or 0 meaning preserve the flags
7291 that the window now has.
7292 If USER_POSITION is nonzero, we set the USPosition
7293 flag (this is useful when FLAGS is 0). */
7295 x_wm_set_size_hint (f
, flags
, user_position
)
7300 int base_width
, base_height
, width_inc
, height_inc
;
7301 int min_rows
= 0, min_cols
= 0;
7302 XSizeHints
*size_hints
;
7304 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
7305 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
7306 width_inc
= FRAME_COLUMN_WIDTH (f
);
7307 height_inc
= FRAME_LINE_HEIGHT (f
);
7309 check_frame_size (f
, &min_rows
, &min_cols
);
7311 size_hints
= FRAME_SIZE_HINTS (f
);
7312 if (size_hints
== NULL
)
7314 size_hints
= FRAME_SIZE_HINTS (f
) = xmalloc (sizeof (XSizeHints
));
7315 bzero (size_hints
, sizeof (XSizeHints
));
7318 size_hints
->flags
|= PResizeInc
| PMinSize
| PBaseSize
;
7319 size_hints
->width_inc
= width_inc
;
7320 size_hints
->height_inc
= height_inc
;
7321 size_hints
->min_width
= base_width
+ min_cols
* width_inc
;
7322 size_hints
->min_height
= base_height
+ min_rows
* height_inc
;
7323 size_hints
->base_width
= base_width
;
7324 size_hints
->base_height
= base_height
;
7327 size_hints
->flags
= flags
;
7328 else if (user_position
)
7330 size_hints
->flags
&= ~ PPosition
;
7331 size_hints
->flags
|= USPosition
;
7335 #if 0 /* MAC_TODO: hide application instead of iconify? */
7336 /* Used for IconicState or NormalState */
7339 x_wm_set_window_state (f
, state
)
7343 #ifdef USE_X_TOOLKIT
7346 XtSetArg (al
[0], XtNinitialState
, state
);
7347 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
7348 #else /* not USE_X_TOOLKIT */
7349 Window window
= FRAME_X_WINDOW (f
);
7351 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
7352 f
->output_data
.x
->wm_hints
.initial_state
= state
;
7354 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
7355 #endif /* not USE_X_TOOLKIT */
7359 x_wm_set_icon_pixmap (f
, pixmap_id
)
7365 #ifndef USE_X_TOOLKIT
7366 Window window
= FRAME_X_WINDOW (f
);
7371 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
7372 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
7376 /* It seems there is no way to turn off use of an icon pixmap.
7377 The following line does it, only if no icon has yet been created,
7378 for some window managers. But with mwm it crashes.
7379 Some people say it should clear the IconPixmapHint bit in this case,
7380 but that doesn't work, and the X consortium said it isn't the
7381 right thing at all. Since there is no way to win,
7382 best to explicitly give up. */
7384 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
7390 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
7394 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
7395 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
7398 #else /* not USE_X_TOOLKIT */
7400 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
7401 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
7403 #endif /* not USE_X_TOOLKIT */
7406 #endif /* MAC_TODO */
7409 x_wm_set_icon_position (f
, icon_x
, icon_y
)
7413 #if 0 /* MAC_TODO: no icons on Mac */
7414 #ifdef USE_X_TOOLKIT
7415 Window window
= XtWindow (f
->output_data
.x
->widget
);
7417 Window window
= FRAME_X_WINDOW (f
);
7420 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
7421 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
7422 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
7424 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
7425 #endif /* MAC_TODO */
7429 /***********************************************************************
7431 ***********************************************************************/
7433 /* An XLFD pattern is divided into blocks delimited by '*'. This
7434 structure holds information for each block. */
7435 struct xlfdpat_block
7437 /* Length of the pattern string in this block. Non-zero except for
7438 the first and the last blocks. */
7441 /* Pattern string except the last character in this block. The last
7442 character is replaced with NUL in order to use it as a
7444 unsigned char *pattern
;
7446 /* Last character of the pattern string. Must not be '?'. */
7447 unsigned char last_char
;
7449 /* One of the tables for the Boyer-Moore string search. It
7450 specifies the number of positions to proceed for each character
7451 with which the match fails. */
7454 /* The skip value for the last character in the above `skip' is
7455 assigned to `infinity' in order to simplify a loop condition.
7456 The original value is saved here. */
7462 /* Normalized pattern string. "Normalized" means that capital
7463 letters are lowered, blocks are not empty except the first and
7464 the last ones, and trailing '?'s in a block that is not the last
7465 one are moved to the next one. The last character in each block
7466 is replaced with NUL. */
7469 /* Number of characters except '*'s and trailing '?'s in the
7470 normalized pattern string. */
7473 /* Number of trailing '?'s in the normalized pattern string. */
7474 int trailing_anychars
;
7476 /* Number of blocks and information for each block. The latter is
7477 NULL if the pattern is exact (no '*' or '?' in it). */
7479 struct xlfdpat_block
*blocks
;
7483 xlfdpat_destroy (pat
)
7484 struct xlfdpat
*pat
;
7491 xfree (pat
->blocks
);
7498 static struct xlfdpat
*
7499 xlfdpat_create (pattern
)
7500 const char *pattern
;
7502 struct xlfdpat
*pat
;
7503 int nblocks
, i
, skip
;
7504 unsigned char last_char
, *p
, *q
, *anychar_head
;
7505 const unsigned char *ptr
;
7506 struct xlfdpat_block
*blk
;
7508 pat
= xmalloc (sizeof (struct xlfdpat
));
7509 pat
->buf
= xmalloc (strlen (pattern
) + 1);
7511 /* Normalize the pattern string and store it to `pat->buf'. */
7513 anychar_head
= NULL
;
7516 for (ptr
= pattern
; *ptr
; ptr
++)
7518 unsigned char c
= *ptr
;
7521 if (last_char
== '*')
7522 /* ...a** -> ...a* */
7526 if (last_char
== '?')
7528 if (anychar_head
> pat
->buf
&& *(anychar_head
- 1) == '*')
7529 /* ...*??* -> ...*?? */
7532 /* ...a??* -> ...a*?? */
7534 *anychar_head
++ = '*';
7542 if (last_char
!= '?')
7546 /* On Mac OS X 10.3, tolower also converts non-ASCII
7547 characters for some locales. */
7551 *q
++ = last_char
= c
;
7555 pat
->nblocks
= nblocks
;
7556 if (last_char
!= '?')
7557 pat
->trailing_anychars
= 0;
7560 pat
->trailing_anychars
= q
- anychar_head
;
7563 pat
->nchars
= q
- pat
->buf
- (nblocks
- 1);
7565 if (anychar_head
== NULL
&& nblocks
== 1)
7567 /* The pattern is exact. */
7572 pat
->blocks
= xmalloc (sizeof (struct xlfdpat_block
) * nblocks
);
7574 /* Divide the normalized pattern into blocks. */
7576 for (blk
= pat
->blocks
; blk
< pat
->blocks
+ nblocks
- 1; blk
++)
7581 blk
->len
= p
- blk
->pattern
;
7585 blk
->len
= q
- blk
->pattern
;
7587 /* Setup a table for the Boyer-Moore string search. */
7588 for (blk
= pat
->blocks
; blk
< pat
->blocks
+ nblocks
; blk
++)
7591 blk
->last_char
= blk
->pattern
[blk
->len
- 1];
7592 blk
->pattern
[blk
->len
- 1] = '\0';
7594 for (skip
= 1; skip
< blk
->len
; skip
++)
7595 if (blk
->pattern
[blk
->len
- skip
- 1] == '?')
7598 for (i
= 0; i
< 256; i
++)
7599 blk
->skip
[i
] = skip
;
7601 p
= blk
->pattern
+ (blk
->len
- skip
);
7603 blk
->skip
[*p
++] = skip
;
7605 blk
->last_char_skip
= blk
->skip
[blk
->last_char
];
7612 xlfdpat_exact_p (pat
)
7613 struct xlfdpat
*pat
;
7615 return pat
->blocks
== NULL
;
7618 /* Return the first string in STRING + 0, ..., STRING + START_MAX such
7619 that the pattern in *BLK matches with its prefix. Return NULL
7620 there is no such strings. STRING must be lowered in advance. */
7623 xlfdpat_block_match_1 (blk
, string
, start_max
)
7624 struct xlfdpat_block
*blk
;
7625 const unsigned char *string
;
7628 int start
, infinity
;
7630 const unsigned char *s
;
7632 xassert (blk
->len
> 0);
7633 xassert (start_max
+ blk
->len
<= strlen (string
));
7634 xassert (blk
->last_char
!= '?');
7636 /* See the comments in the function `boyer_moore' (search.c) for the
7637 use of `infinity'. */
7638 infinity
= start_max
+ blk
->len
+ 1;
7639 blk
->skip
[blk
->last_char
] = infinity
;
7644 /* Check the last character of the pattern. */
7645 s
= string
+ blk
->len
- 1;
7648 start
+= blk
->skip
[*(s
+ start
)];
7650 while (start
<= start_max
);
7652 if (start
< infinity
)
7653 /* Couldn't find the last character. */
7656 /* No less than `infinity' means we could find the last
7657 character at `s[start - infinity]'. */
7660 /* Check the remaining characters. We prefer making no-'?'
7661 cases faster because the use of '?' is really rare. */
7666 while (*p
++ == *s
++)
7669 while (*(p
- 1) == '?');
7671 if (*(p
- 1) == '\0')
7673 return string
+ start
;
7676 start
+= blk
->last_char_skip
;
7678 while (start
<= start_max
);
7683 #define xlfdpat_block_match(b, s, m) \
7684 ((b)->len == 1 ? memchr ((s), (b)->last_char, (m) + 1) \
7685 : xlfdpat_block_match_1 (b, s, m))
7687 /* Check if XLFD pattern PAT, which is generated by `xlfdpat_create',
7688 matches with STRING. STRING must be lowered in advance. */
7691 xlfdpat_match (pat
, string
)
7692 struct xlfdpat
*pat
;
7693 const unsigned char *string
;
7695 int str_len
, nblocks
, i
, start_max
;
7696 struct xlfdpat_block
*blk
;
7697 const unsigned char *s
;
7699 xassert (pat
->nblocks
> 0);
7701 if (xlfdpat_exact_p (pat
))
7702 return strcmp (pat
->buf
, string
) == 0;
7704 /* The number of the characters in the string must not be smaller
7705 than that in the pattern. */
7706 str_len
= strlen (string
);
7707 if (str_len
< pat
->nchars
+ pat
->trailing_anychars
)
7710 /* Chop off the trailing '?'s. */
7711 str_len
-= pat
->trailing_anychars
;
7713 /* The last block. When it is non-empty, it must match at the end
7715 nblocks
= pat
->nblocks
;
7716 blk
= pat
->blocks
+ (nblocks
- 1);
7718 /* The last block is also the first one. */
7719 return (str_len
== blk
->len
7720 && (blk
->len
== 0 || xlfdpat_block_match (blk
, string
, 0)));
7721 else if (blk
->len
!= 0)
7722 if (!xlfdpat_block_match (blk
, string
+ (str_len
- blk
->len
), 0))
7725 /* The first block. When it is non-empty, it must match at the
7726 beginning of the string. */
7730 s
= xlfdpat_block_match (blk
, string
, 0);
7733 string
= s
+ blk
->len
;
7736 /* The rest of the blocks. */
7737 start_max
= str_len
- pat
->nchars
;
7738 for (i
= 1, blk
++; i
< nblocks
- 1; i
++, blk
++)
7740 s
= xlfdpat_block_match (blk
, string
, start_max
);
7743 start_max
-= s
- string
;
7744 string
= s
+ blk
->len
;
7751 /***********************************************************************
7753 ***********************************************************************/
7755 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
7758 x_get_font_info (f
, font_idx
)
7762 return (FRAME_MAC_FONT_TABLE (f
) + font_idx
);
7765 /* the global font name table */
7766 static char **font_name_table
= NULL
;
7767 static int font_name_table_size
= 0;
7768 static int font_name_count
= 0;
7770 /* Alist linking font family names to Font Manager font family
7771 references (which can also be used as QuickDraw font IDs). We use
7772 an alist because hash tables are not ready when the terminal frame
7773 for Mac OS Classic is created. */
7774 static Lisp_Object fm_font_family_alist
;
7776 /* Hash table linking font family names to ATSU font IDs. */
7777 static Lisp_Object atsu_font_id_hash
;
7778 /* Alist linking Font Manager style to face attributes. */
7779 static Lisp_Object fm_style_face_attributes_alist
;
7780 extern Lisp_Object QCfamily
, QCweight
, QCslant
, Qnormal
, Qbold
, Qitalic
;
7783 /* Alist linking character set strings to Mac text encoding and Emacs
7785 static Lisp_Object Vmac_charset_info_alist
;
7788 create_text_encoding_info_alist ()
7790 Lisp_Object result
= Qnil
, rest
;
7792 for (rest
= Vmac_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
7794 Lisp_Object charset_info
= XCAR (rest
);
7795 Lisp_Object charset
, coding_system
, text_encoding
;
7796 Lisp_Object existing_info
;
7798 if (!(CONSP (charset_info
)
7799 && (charset
= XCAR (charset_info
),
7801 && CONSP (XCDR (charset_info
))
7802 && (text_encoding
= XCAR (XCDR (charset_info
)),
7803 INTEGERP (text_encoding
))
7804 && CONSP (XCDR (XCDR (charset_info
)))
7805 && (coding_system
= XCAR (XCDR (XCDR (charset_info
))),
7806 SYMBOLP (coding_system
))))
7809 existing_info
= assq_no_quit (text_encoding
, result
);
7810 if (NILP (existing_info
))
7811 result
= Fcons (list3 (text_encoding
, coding_system
, charset
),
7814 if (NILP (Fmember (charset
, XCDR (XCDR (existing_info
)))))
7815 XSETCDR (XCDR (existing_info
),
7816 Fcons (charset
, XCDR (XCDR (existing_info
))));
7824 decode_mac_font_name (name
, size
, coding_system
)
7827 Lisp_Object coding_system
;
7829 struct coding_system coding
;
7832 if (!NILP (coding_system
) && !NILP (Fcoding_system_p (coding_system
)))
7834 for (p
= name
; *p
; p
++)
7835 if (!isascii (*p
) || iscntrl (*p
))
7840 setup_coding_system (coding_system
, &coding
);
7841 coding
.src_multibyte
= 0;
7842 coding
.dst_multibyte
= 1;
7843 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
7844 coding
.composing
= COMPOSITION_DISABLED
;
7845 buf
= (char *) alloca (size
);
7847 decode_coding (&coding
, name
, buf
, strlen (name
), size
- 1);
7848 bcopy (buf
, name
, coding
.produced
);
7849 name
[coding
.produced
] = '\0';
7853 /* If there's just one occurrence of '-' in the family name, it is
7854 replaced with '_'. (More than one occurrence of '-' means a
7855 "FOUNDRY-FAMILY-CHARSET"-style name.) */
7856 p
= strchr (name
, '-');
7857 if (p
&& strchr (p
+ 1, '-') == NULL
)
7860 for (p
= name
; *p
; p
++)
7861 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
7862 for some locales. */
7869 mac_to_x_fontname (name
, size
, style
, charset
)
7877 char xf
[256], *result
;
7880 if (sscanf (name
, "%31[^-]-%255[^-]-%31s", foundry
, family
, cs
) == 3)
7884 strcpy(foundry
, "Apple");
7885 strcpy(family
, name
);
7888 sprintf (xf
, "%s-%c-normal--%d-%d-%d-%d-m-%d-%s",
7889 style
& bold
? "bold" : "medium", style
& italic
? 'i' : 'r',
7890 size
, size
* 10, size
? 72 : 0, size
? 72 : 0, size
* 10, charset
);
7892 result
= xmalloc (strlen (foundry
) + strlen (family
) + strlen (xf
) + 3 + 1);
7893 sprintf (result
, "-%s-%s-%s", foundry
, family
, xf
);
7894 for (p
= result
; *p
; p
++)
7895 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
7896 for some locales. */
7903 /* Parse fully-specified and instantiated X11 font spec XF, and store
7904 the results to FAMILY, *SIZE, *STYLE, and CHARSET. Return 1 if the
7905 parsing succeeded, and 0 otherwise. For FAMILY and CHARSET, the
7906 caller must allocate at least 256 and 32 bytes respectively. For
7907 ordinary Mac fonts, the value stored to FAMILY should just be their
7908 names, like "monaco", "Taipei", etc. Fonts converted from the GNU
7909 intlfonts collection contain their charset designation in their
7910 names, like "ETL-Fixed-iso8859-1", "ETL-Fixed-koi8-r", etc. Both
7911 types of font names are handled accordingly. */
7913 const int kDefaultFontSize
= 12;
7916 parse_x_font_name (xf
, family
, size
, style
, charset
)
7923 Str31 foundry
, weight
;
7924 int point_size
, avgwidth
;
7927 if (sscanf (xf
, "-%31[^-]-%255[^-]-%31[^-]-%1[^-]-%*[^-]-%*[^-]-%d-%d-%*[^-]-%*[^-]-%*c-%d-%31s",
7928 foundry
, family
, weight
, slant
, size
,
7929 &point_size
, &avgwidth
, charset
) != 8
7930 && sscanf (xf
, "-%31[^-]-%255[^-]-%31[^-]-%1[^-]-%*[^-]--%d-%d-%*[^-]-%*[^-]-%*c-%d-%31s",
7931 foundry
, family
, weight
, slant
, size
,
7932 &point_size
, &avgwidth
, charset
) != 8)
7938 *size
= point_size
/ 10;
7939 else if (avgwidth
> 0)
7940 *size
= avgwidth
/ 10;
7943 *size
= kDefaultFontSize
;
7946 if (strcmp (weight
, "bold") == 0)
7951 if (NILP (Fassoc (build_string (charset
), Vmac_charset_info_alist
)))
7953 int foundry_len
= strlen (foundry
), family_len
= strlen (family
);
7955 if (foundry_len
+ family_len
+ strlen (charset
) + 2 < sizeof (Str255
))
7957 /* Like sprintf (family, "%s-%s-%s", foundry, family, charset),
7958 but take overlap into account. */
7959 memmove (family
+ foundry_len
+ 1, family
, family_len
);
7960 memcpy (family
, foundry
, foundry_len
);
7961 family
[foundry_len
] = '-';
7962 family
[foundry_len
+ 1 + family_len
] = '-';
7963 strcpy (family
+ foundry_len
+ 1 + family_len
+ 1, charset
);
7969 for (p
= family
; *p
; p
++)
7970 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
7971 for some locales. */
7980 add_font_name_table_entry (char *font_name
)
7982 if (font_name_table_size
== 0)
7984 font_name_table_size
= 256;
7985 font_name_table
= (char **)
7986 xmalloc (font_name_table_size
* sizeof (char *));
7988 else if (font_name_count
+ 1 >= font_name_table_size
)
7990 font_name_table_size
*= 2;
7991 font_name_table
= (char **)
7992 xrealloc (font_name_table
,
7993 font_name_table_size
* sizeof (char *));
7996 font_name_table
[font_name_count
++] = font_name
;
8000 add_mac_font_name (name
, size
, style
, charset
)
8004 const char *charset
;
8007 add_font_name_table_entry (mac_to_x_fontname (name
, size
, style
, charset
));
8010 add_font_name_table_entry (mac_to_x_fontname (name
, 0, style
, charset
));
8011 add_font_name_table_entry (mac_to_x_fontname (name
, 0, italic
, charset
));
8012 add_font_name_table_entry (mac_to_x_fontname (name
, 0, bold
, charset
));
8013 add_font_name_table_entry (mac_to_x_fontname (name
, 0, italic
| bold
,
8020 fm_get_style_from_font (font
)
8024 FMFontStyle style
= normal
;
8027 FMFontFamily font_family
;
8028 #define FONT_HEADER_MAC_STYLE_OFFSET (4*4 + 2*2 + 8*2 + 2*4)
8030 /* FMGetFontFamilyInstanceFromFont returns `normal' as the style of
8031 some font (e.g., Optima) even if it is `bold'. */
8032 err
= FMGetFontTable (font
, 'head', FONT_HEADER_MAC_STYLE_OFFSET
,
8033 sizeof (mac_style
), &mac_style
, &len
);
8035 && len
>= FONT_HEADER_MAC_STYLE_OFFSET
+ sizeof (mac_style
))
8036 style
= EndianU16_BtoN (mac_style
);
8038 FMGetFontFamilyInstanceFromFont (font
, &font_family
, &style
);
8044 atsu_find_font_from_family_name (family
)
8047 struct Lisp_Hash_Table
*h
= XHASH_TABLE (atsu_font_id_hash
);
8050 Lisp_Object rest
, best
;
8051 FMFontStyle min_style
, style
;
8053 i
= hash_lookup (h
, make_unibyte_string (family
, strlen (family
)),
8056 return kATSUInvalidFontID
;
8058 rest
= HASH_VALUE (h
, i
);
8059 if (INTEGERP (rest
) || (CONSP (rest
) && INTEGERP (XCDR (rest
))))
8060 return cons_to_long (rest
);
8062 rest
= Fnreverse (rest
);
8066 && (min_style
= fm_get_style_from_font (cons_to_long (best
))) != normal
)
8069 style
= fm_get_style_from_font (cons_to_long (XCAR (rest
)));
8070 if (style
< min_style
)
8073 if (style
== normal
)
8080 while (!NILP (rest
));
8082 HASH_VALUE (h
, i
) = best
;
8083 return cons_to_long (best
);
8087 fm_style_to_face_attributes (fm_style
)
8088 FMFontStyle fm_style
;
8092 fm_style
&= (bold
| italic
);
8093 tem
= assq_no_quit (make_number (fm_style
),
8094 fm_style_face_attributes_alist
);
8098 tem
= list4 (QCweight
, fm_style
& bold
? Qbold
: Qnormal
,
8099 QCslant
, fm_style
& italic
? Qitalic
: Qnormal
);
8100 fm_style_face_attributes_alist
=
8101 Fcons (Fcons (make_number (fm_style
), tem
),
8102 fm_style_face_attributes_alist
);
8108 atsu_find_font_family_name (font_id
)
8113 Lisp_Object family
= Qnil
;
8115 err
= ATSUFindFontName (font_id
, kFontFamilyName
,
8116 kFontMacintoshPlatform
, kFontNoScript
,
8117 kFontNoLanguage
, 0, NULL
, &len
, NULL
);
8120 family
= make_uninit_string (len
);
8121 err
= ATSUFindFontName (font_id
, kFontFamilyName
,
8122 kFontMacintoshPlatform
, kFontNoScript
,
8123 kFontNoLanguage
, len
, SDATA (family
),
8127 decode_mac_font_name (SDATA (family
), len
+ 1, Qnil
);
8133 mac_atsu_font_face_attributes (font_id
)
8136 Lisp_Object family
, style_attrs
;
8138 family
= atsu_find_font_family_name (font_id
);
8141 style_attrs
= fm_style_to_face_attributes (fm_get_style_from_font (font_id
));
8142 return Fcons (QCfamily
, Fcons (family
, style_attrs
));
8146 /* Sets up the table font_name_table to contain the list of all fonts
8147 in the system the first time the table is used so that the Resource
8148 Manager need not be accessed every time this information is
8152 init_font_name_table ()
8154 #if TARGET_API_MAC_CARBON
8155 FMFontFamilyIterator ffi
;
8156 FMFontFamilyInstanceIterator ffii
;
8158 Lisp_Object text_encoding_info_alist
;
8159 struct gcpro gcpro1
;
8161 text_encoding_info_alist
= create_text_encoding_info_alist ();
8164 #if USE_CG_TEXT_DRAWING
8165 init_cg_text_anti_aliasing_threshold ();
8167 if (!NILP (assq_no_quit (make_number (kTextEncodingMacUnicode
),
8168 text_encoding_info_alist
)))
8171 struct Lisp_Hash_Table
*h
;
8173 ItemCount nfonts
, i
;
8174 ATSUFontID
*font_ids
= NULL
;
8175 Lisp_Object prev_family
= Qnil
;
8179 make_hash_table (Qequal
, make_number (DEFAULT_HASH_SIZE
),
8180 make_float (DEFAULT_REHASH_SIZE
),
8181 make_float (DEFAULT_REHASH_THRESHOLD
),
8183 h
= XHASH_TABLE (atsu_font_id_hash
);
8185 err
= ATSUFontCount (&nfonts
);
8188 font_ids
= xmalloc (sizeof (ATSUFontID
) * nfonts
);
8189 err
= ATSUGetFontIDs (font_ids
, nfonts
, NULL
);
8192 for (i
= 0; i
< nfonts
; i
++)
8196 family
= atsu_find_font_family_name (font_ids
[i
]);
8197 if (NILP (family
) || SREF (family
, 0) == '.')
8199 if (!NILP (Fequal (prev_family
, family
)))
8200 family
= prev_family
;
8202 j
= hash_lookup (h
, family
, &hash_code
);
8205 add_mac_font_name (SDATA (family
), 0, normal
, "iso10646-1");
8206 j
= hash_put (h
, family
, Fcons (long_to_cons (font_ids
[i
]),
8209 else if (EQ (prev_family
, family
))
8210 HASH_VALUE (h
, j
) = Fcons (long_to_cons (font_ids
[i
]),
8212 prev_family
= family
;
8219 /* Create a dummy instance iterator here to avoid creating and
8220 destroying it in the loop. */
8221 if (FMCreateFontFamilyInstanceIterator (0, &ffii
) != noErr
)
8223 /* Create an iterator to enumerate the font families. */
8224 if (FMCreateFontFamilyIterator (NULL
, NULL
, kFMDefaultOptions
, &ffi
)
8227 FMDisposeFontFamilyInstanceIterator (&ffii
);
8231 GCPRO1 (text_encoding_info_alist
);
8233 while (FMGetNextFontFamily (&ffi
, &ff
) == noErr
)
8239 TextEncoding encoding
;
8240 TextEncodingBase sc
;
8241 Lisp_Object text_encoding_info
, family
;
8243 if (FMGetFontFamilyName (ff
, name
) != noErr
)
8249 if (FMGetFontFamilyTextEncoding (ff
, &encoding
) != noErr
)
8251 sc
= GetTextEncodingBase (encoding
);
8252 text_encoding_info
= assq_no_quit (make_number (sc
),
8253 text_encoding_info_alist
);
8254 if (NILP (text_encoding_info
))
8255 text_encoding_info
= assq_no_quit (make_number (kTextEncodingMacRoman
),
8256 text_encoding_info_alist
);
8257 decode_mac_font_name (name
, sizeof (name
),
8258 XCAR (XCDR (text_encoding_info
)));
8259 family
= build_string (name
);
8260 if (!NILP (Fassoc (family
, fm_font_family_alist
)))
8262 fm_font_family_alist
= Fcons (Fcons (family
, make_number (ff
)),
8263 fm_font_family_alist
);
8265 /* Point the instance iterator at the current font family. */
8266 if (FMResetFontFamilyInstanceIterator (ff
, &ffii
) != noErr
)
8269 while (FMGetNextFontFamilyInstance (&ffii
, &font
, &style
, &size
)
8272 Lisp_Object rest
= XCDR (XCDR (text_encoding_info
));
8274 if (size
> 0 || style
== normal
)
8275 for (; !NILP (rest
); rest
= XCDR (rest
))
8276 add_mac_font_name (name
, size
, style
, SDATA (XCAR (rest
)));
8282 /* Dispose of the iterators. */
8283 FMDisposeFontFamilyIterator (&ffi
);
8284 FMDisposeFontFamilyInstanceIterator (&ffii
);
8285 #else /* !TARGET_API_MAC_CARBON */
8287 SInt16 fontnum
, old_fontnum
;
8288 int num_mac_fonts
= CountResources('FOND');
8290 Handle font_handle
, font_handle_2
;
8291 short id
, scriptcode
;
8294 struct FontAssoc
*fat
;
8295 struct AsscEntry
*assc_entry
;
8296 Lisp_Object text_encoding_info_alist
, text_encoding_info
, family
;
8297 struct gcpro gcpro1
;
8299 GetPort (&port
); /* save the current font number used */
8300 old_fontnum
= port
->txFont
;
8302 text_encoding_info_alist
= create_text_encoding_info_alist ();
8304 GCPRO1 (text_encoding_info_alist
);
8306 for (i
= 1; i
<= num_mac_fonts
; i
++) /* get all available fonts */
8308 font_handle
= GetIndResource ('FOND', i
);
8312 GetResInfo (font_handle
, &id
, &type
, name
);
8313 GetFNum (name
, &fontnum
);
8315 if (fontnum
== 0 || *name
== '.')
8319 scriptcode
= FontToScript (fontnum
);
8320 text_encoding_info
= assq_no_quit (make_number (scriptcode
),
8321 text_encoding_info_alist
);
8322 if (NILP (text_encoding_info
))
8323 text_encoding_info
= assq_no_quit (make_number (smRoman
),
8324 text_encoding_info_alist
);
8325 decode_mac_font_name (name
, sizeof (name
),
8326 XCAR (XCDR (text_encoding_info
)));
8327 family
= build_string (name
);
8328 if (!NILP (Fassoc (family
, fm_font_family_alist
)))
8330 fm_font_family_alist
= Fcons (Fcons (family
, make_number (fontnum
)),
8331 fm_font_family_alist
);
8334 HLock (font_handle
);
8336 if (GetResourceSizeOnDisk (font_handle
)
8337 >= sizeof (struct FamRec
))
8339 fat
= (struct FontAssoc
*) (*font_handle
8340 + sizeof (struct FamRec
));
8342 = (struct AsscEntry
*) (*font_handle
8343 + sizeof (struct FamRec
)
8344 + sizeof (struct FontAssoc
));
8346 for (j
= 0; j
<= fat
->numAssoc
; j
++, assc_entry
++)
8348 Lisp_Object rest
= XCDR (XCDR (text_encoding_info
));
8350 for (; !NILP (rest
); rest
= XCDR (rest
))
8351 add_mac_font_name (name
, assc_entry
->fontSize
,
8352 assc_entry
->fontStyle
,
8353 SDATA (XCAR (rest
)));
8357 HUnlock (font_handle
);
8358 font_handle_2
= GetNextFOND (font_handle
);
8359 ReleaseResource (font_handle
);
8360 font_handle
= font_handle_2
;
8362 while (ResError () == noErr
&& font_handle
);
8367 TextFont (old_fontnum
);
8368 #endif /* !TARGET_API_MAC_CARBON */
8373 mac_clear_font_name_table ()
8377 for (i
= 0; i
< font_name_count
; i
++)
8378 xfree (font_name_table
[i
]);
8379 xfree (font_name_table
);
8380 font_name_table
= NULL
;
8381 font_name_table_size
= font_name_count
= 0;
8382 fm_font_family_alist
= Qnil
;
8386 enum xlfd_scalable_field_index
8388 XLFD_SCL_PIXEL_SIZE
,
8389 XLFD_SCL_POINT_SIZE
,
8394 static const int xlfd_scalable_fields
[] =
8403 mac_do_list_fonts (pattern
, maxnames
)
8404 const char *pattern
;
8408 Lisp_Object font_list
= Qnil
;
8409 struct xlfdpat
*pat
;
8412 int scl_val
[XLFD_SCL_LAST
], *val
;
8416 if (font_name_table
== NULL
) /* Initialize when first used. */
8417 init_font_name_table ();
8419 for (i
= 0; i
< XLFD_SCL_LAST
; i
++)
8422 /* If the pattern contains 14 dashes and one of PIXEL_SIZE,
8423 POINT_SIZE, and AVGWIDTH fields is explicitly specified, scalable
8424 fonts are scaled according to the specified size. */
8427 field
= xlfd_scalable_fields
;
8435 if ('0' <= *ptr
&& *ptr
<= '9')
8437 *val
= *ptr
++ - '0';
8438 while ('0' <= *ptr
&& *ptr
<= '9' && *val
< 10000)
8439 *val
= *val
* 10 + *ptr
++ - '0';
8446 ptr
= strchr (ptr
, '-');
8449 while (ptr
&& i
< 14);
8451 if (i
== 14 && ptr
== NULL
)
8453 if (scl_val
[XLFD_SCL_PIXEL_SIZE
] < 0)
8454 scl_val
[XLFD_SCL_PIXEL_SIZE
] =
8455 (scl_val
[XLFD_SCL_POINT_SIZE
] > 0 ? scl_val
[XLFD_SCL_POINT_SIZE
] / 10
8456 : (scl_val
[XLFD_SCL_AVGWIDTH
] > 0 ? scl_val
[XLFD_SCL_AVGWIDTH
] / 10
8458 if (scl_val
[XLFD_SCL_POINT_SIZE
] < 0)
8459 scl_val
[XLFD_SCL_POINT_SIZE
] =
8460 (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0 ? scl_val
[XLFD_SCL_PIXEL_SIZE
] * 10
8461 : (scl_val
[XLFD_SCL_AVGWIDTH
] > 0 ? scl_val
[XLFD_SCL_AVGWIDTH
]
8463 if (scl_val
[XLFD_SCL_AVGWIDTH
] < 0)
8464 scl_val
[XLFD_SCL_AVGWIDTH
] =
8465 (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0 ? scl_val
[XLFD_SCL_PIXEL_SIZE
] * 10
8466 : (scl_val
[XLFD_SCL_POINT_SIZE
] > 0 ? scl_val
[XLFD_SCL_POINT_SIZE
]
8470 scl_val
[XLFD_SCL_PIXEL_SIZE
] = -1;
8472 pat
= xlfdpat_create (pattern
);
8476 exact
= xlfdpat_exact_p (pat
);
8478 for (i
= 0; i
< font_name_count
; i
++)
8480 if (xlfdpat_match (pat
, font_name_table
[i
]))
8482 font_list
= Fcons (build_string (font_name_table
[i
]), font_list
);
8483 if (exact
|| (maxnames
> 0 && ++n_fonts
>= maxnames
))
8486 else if (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0
8487 && (ptr
= strstr (font_name_table
[i
], "-0-0-0-0-m-0-")))
8489 int former_len
= ptr
- font_name_table
[i
];
8491 scaled
= xmalloc (strlen (font_name_table
[i
]) + 20 + 1);
8492 memcpy (scaled
, font_name_table
[i
], former_len
);
8493 sprintf (scaled
+ former_len
,
8494 "-%d-%d-72-72-m-%d-%s",
8495 scl_val
[XLFD_SCL_PIXEL_SIZE
],
8496 scl_val
[XLFD_SCL_POINT_SIZE
],
8497 scl_val
[XLFD_SCL_AVGWIDTH
],
8498 ptr
+ sizeof ("-0-0-0-0-m-0-") - 1);
8500 if (xlfdpat_match (pat
, scaled
))
8502 font_list
= Fcons (build_string (scaled
), font_list
);
8504 if (exact
|| (maxnames
> 0 && ++n_fonts
>= maxnames
))
8512 xlfdpat_destroy (pat
);
8517 /* Return a list of names of available fonts matching PATTERN on frame F.
8519 Frame F null means we have not yet created any frame on Mac, and
8520 consult the first display in x_display_list. MAXNAMES sets a limit
8521 on how many fonts to match. */
8524 x_list_fonts (f
, pattern
, size
, maxnames
)
8526 Lisp_Object pattern
;
8529 Lisp_Object list
= Qnil
, patterns
, tem
, key
;
8530 struct mac_display_info
*dpyinfo
8531 = f
? FRAME_MAC_DISPLAY_INFO (f
) : x_display_list
;
8533 xassert (size
<= 0);
8535 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
8536 if (NILP (patterns
))
8537 patterns
= Fcons (pattern
, Qnil
);
8539 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
8541 pattern
= XCAR (patterns
);
8543 if (!STRINGP (pattern
))
8546 tem
= XCAR (XCDR (dpyinfo
->name_list_element
));
8547 key
= Fcons (pattern
, make_number (maxnames
));
8549 list
= Fassoc (key
, tem
);
8552 list
= Fcdr_safe (list
);
8553 /* We have a cashed list. Don't have to get the list again. */
8558 list
= mac_do_list_fonts (SDATA (pattern
), maxnames
);
8561 /* MAC_TODO: add code for matching outline fonts here */
8563 /* Now store the result in the cache. */
8564 XSETCAR (XCDR (dpyinfo
->name_list_element
),
8565 Fcons (Fcons (key
, list
),
8566 XCAR (XCDR (dpyinfo
->name_list_element
))));
8569 if (NILP (list
)) continue; /* Try the remaining alternatives. */
8578 /* Check that FONT is valid on frame F. It is if it can be found in F's
8582 x_check_font (f
, font
)
8587 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8589 xassert (font
!= NULL
);
8591 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
8592 if (dpyinfo
->font_table
[i
].name
8593 && font
== dpyinfo
->font_table
[i
].font
)
8596 xassert (i
< dpyinfo
->n_fonts
);
8599 #endif /* GLYPH_DEBUG != 0 */
8601 /* Set *W to the minimum width, *H to the minimum font height of FONT.
8602 Note: There are (broken) X fonts out there with invalid XFontStruct
8603 min_bounds contents. For example, handa@etl.go.jp reports that
8604 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
8605 have font->min_bounds.width == 0. */
8608 x_font_min_bounds (font
, w
, h
)
8609 MacFontStruct
*font
;
8612 *h
= FONT_HEIGHT (font
);
8613 *w
= font
->min_bounds
.width
;
8617 /* Compute the smallest character width and smallest font height over
8618 all fonts available on frame F. Set the members smallest_char_width
8619 and smallest_font_height in F's x_display_info structure to
8620 the values computed. Value is non-zero if smallest_font_height or
8621 smallest_char_width become smaller than they were before. */
8624 x_compute_min_glyph_bounds (f
)
8628 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
8629 MacFontStruct
*font
;
8630 int old_width
= dpyinfo
->smallest_char_width
;
8631 int old_height
= dpyinfo
->smallest_font_height
;
8633 dpyinfo
->smallest_font_height
= 100000;
8634 dpyinfo
->smallest_char_width
= 100000;
8636 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
8637 if (dpyinfo
->font_table
[i
].name
)
8639 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
8642 font
= (MacFontStruct
*) fontp
->font
;
8643 xassert (font
!= (MacFontStruct
*) ~0);
8644 x_font_min_bounds (font
, &w
, &h
);
8646 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
8647 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
8650 xassert (dpyinfo
->smallest_char_width
> 0
8651 && dpyinfo
->smallest_font_height
> 0);
8653 return (dpyinfo
->n_fonts
== 1
8654 || dpyinfo
->smallest_char_width
< old_width
8655 || dpyinfo
->smallest_font_height
< old_height
);
8659 /* Determine whether given string is a fully-specified XLFD: all 14
8660 fields are present, none is '*'. */
8663 is_fully_specified_xlfd (p
)
8672 for (i
= 0; i
< 13; i
++)
8674 q
= strchr (p
+ 1, '-');
8677 if (q
- p
== 2 && *(p
+ 1) == '*')
8682 if (strchr (p
+ 1, '-') != NULL
)
8685 if (*(p
+ 1) == '*' && *(p
+ 2) == '\0')
8692 /* mac_load_query_font creates and returns an internal representation
8693 for a font in a MacFontStruct struct. There is really no concept
8694 corresponding to "loading" a font on the Mac. But we check its
8695 existence and find the font number and all other information for it
8696 and store them in the returned MacFontStruct. */
8698 static MacFontStruct
*
8699 mac_load_query_font (f
, fontname
)
8709 static ATSUFontID font_id
;
8710 ATSUStyle mac_style
= NULL
;
8713 #if TARGET_API_MAC_CARBON
8714 TextEncoding encoding
;
8719 MacFontStruct
*font
;
8720 XCharStruct
*space_bounds
= NULL
, *pcm
;
8722 if (is_fully_specified_xlfd (fontname
))
8726 Lisp_Object matched_fonts
;
8728 matched_fonts
= mac_do_list_fonts (fontname
, 1);
8729 if (NILP (matched_fonts
))
8731 name
= SDATA (XCAR (matched_fonts
));
8734 if (parse_x_font_name (name
, family
, &size
, &fontface
, charset
) == 0)
8738 if (strcmp (charset
, "iso10646-1") == 0) /* XXX */
8741 static const ATSUAttributeTag tags
[] =
8742 {kATSUFontTag
, kATSUSizeTag
,
8743 kATSUQDBoldfaceTag
, kATSUQDItalicTag
};
8744 static const ByteCount sizes
[] =
8745 {sizeof (ATSUFontID
), sizeof (Fixed
),
8746 sizeof (Boolean
), sizeof (Boolean
)};
8747 static Fixed size_fixed
;
8748 static Boolean bold_p
, italic_p
;
8749 static const ATSUAttributeValuePtr values
[] =
8750 {&font_id
, &size_fixed
,
8751 &bold_p
, &italic_p
};
8752 static const ATSUFontFeatureType types
[] =
8753 {kAllTypographicFeaturesType
, kDiacriticsType
};
8754 static const ATSUFontFeatureSelector selectors
[] =
8755 {kAllTypeFeaturesOffSelector
, kDecomposeDiacriticsSelector
};
8758 font_id
= atsu_find_font_from_family_name (family
);
8759 if (font_id
== kATSUInvalidFontID
)
8761 size_fixed
= Long2Fix (size
);
8762 bold_p
= (fontface
& bold
) != 0;
8763 italic_p
= (fontface
& italic
) != 0;
8764 err
= ATSUCreateStyle (&mac_style
);
8767 err
= ATSUSetFontFeatures (mac_style
, sizeof (types
) / sizeof (types
[0]),
8771 err
= ATSUSetAttributes (mac_style
, sizeof (tags
) / sizeof (tags
[0]),
8772 tags
, sizes
, values
);
8775 err
= FMGetFontFamilyInstanceFromFont (font_id
, &fontnum
, &style
);
8778 scriptcode
= kTextEncodingMacUnicode
;
8783 Lisp_Object tmp
= Fassoc (build_string (family
), fm_font_family_alist
);
8787 fontnum
= XINT (XCDR (tmp
));
8788 #if TARGET_API_MAC_CARBON
8789 if (FMGetFontFamilyTextEncoding (fontnum
, &encoding
) != noErr
)
8791 scriptcode
= GetTextEncodingBase (encoding
);
8793 scriptcode
= FontToScript (fontnum
);
8797 font
= (MacFontStruct
*) xmalloc (sizeof (struct MacFontStruct
));
8799 font
->mac_fontnum
= fontnum
;
8800 font
->mac_fontsize
= size
;
8801 font
->mac_fontface
= fontface
;
8802 font
->mac_scriptcode
= scriptcode
;
8804 font
->mac_style
= mac_style
;
8805 #if USE_CG_TEXT_DRAWING
8806 font
->cg_font
= NULL
;
8807 font
->cg_glyphs
= NULL
;
8811 /* Apple Japanese (SJIS) font is listed as both
8812 "*-jisx0208.1983-sjis" (Japanese script) and "*-jisx0201.1976-0"
8813 (Roman script) in init_font_name_table (). The latter should be
8814 treated as a one-byte font. */
8815 if (scriptcode
== smJapanese
&& strcmp (charset
, "jisx0201.1976-0") == 0)
8816 font
->mac_scriptcode
= smRoman
;
8818 font
->full_name
= mac_to_x_fontname (family
, size
, fontface
, charset
);
8821 if (font
->mac_style
)
8826 font
->min_byte1
= 0;
8827 font
->max_byte1
= 0xff;
8828 font
->min_char_or_byte2
= 0;
8829 font
->max_char_or_byte2
= 0xff;
8831 font
->bounds
.rows
= xmalloc (sizeof (XCharStruct
*) * 0x100);
8832 bzero (font
->bounds
.rows
, sizeof (XCharStruct
*) * 0x100);
8833 font
->bounds
.rows
[0] = xmalloc (sizeof (XCharStruct
) * 0x100);
8834 pcm_init (font
->bounds
.rows
[0], 0x100);
8836 #if USE_CG_TEXT_DRAWING
8840 ATSFontRef ats_font
;
8842 err
= FMGetFontFromFontFamilyInstance (fontnum
, fontface
,
8844 /* Use CG text drawing if italic/bold is not synthesized. */
8845 if (err
== noErr
&& style
== fontface
)
8847 ats_font
= FMGetATSFontRefFromFont (font_id
);
8848 font
->cg_font
= CGFontCreateWithPlatformFont (&ats_font
);
8854 font
->cg_glyphs
= xmalloc (sizeof (CGGlyph
) * 0x100);
8855 bzero (font
->cg_glyphs
, sizeof (CGGlyph
) * 0x100);
8858 space_bounds
= font
->bounds
.rows
[0] + 0x20;
8859 err
= mac_query_char_extents (font
->mac_style
, 0x20,
8860 &font
->ascent
, &font
->descent
,
8862 #if USE_CG_TEXT_DRAWING
8863 (font
->cg_glyphs
? font
->cg_glyphs
+ 0x20
8870 || space_bounds
->width
<= 0 || FONT_HEIGHT (font
) <= 0)
8872 mac_unload_font (&one_mac_display_info
, font
);
8876 pcm
= font
->bounds
.rows
[0];
8877 for (c
= 0x21; c
<= 0xff; c
++)
8880 /* Soft hyphen is not supported in ATSUI. */
8884 #if USE_CG_TEXT_DRAWING
8885 if (font
->cg_glyphs
)
8895 mac_query_char_extents (font
->mac_style
, c
, NULL
, NULL
,
8896 pcm
? pcm
+ c
: NULL
,
8897 #if USE_CG_TEXT_DRAWING
8898 (font
->cg_glyphs
? font
->cg_glyphs
+ c
8905 #if USE_CG_TEXT_DRAWING
8906 if (font
->cg_glyphs
&& font
->cg_glyphs
[c
] == 0)
8908 /* Don't use CG text drawing if font substitution occurs in
8909 ASCII or Latin-1 characters. */
8910 CGFontRelease (font
->cg_font
);
8911 font
->cg_font
= NULL
;
8912 xfree (font
->cg_glyphs
);
8913 font
->cg_glyphs
= NULL
;
8924 FontInfo the_fontinfo
;
8925 int is_two_byte_font
;
8928 mac_prepare_for_quickdraw (f
);
8930 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
8934 TextFace (fontface
);
8936 GetFontInfo (&the_fontinfo
);
8938 font
->ascent
= the_fontinfo
.ascent
;
8939 font
->descent
= the_fontinfo
.descent
;
8941 is_two_byte_font
= (font
->mac_scriptcode
== smJapanese
8942 || font
->mac_scriptcode
== smTradChinese
8943 || font
->mac_scriptcode
== smSimpChinese
8944 || font
->mac_scriptcode
== smKorean
);
8946 if (is_two_byte_font
)
8950 font
->min_byte1
= 0xa1;
8951 font
->max_byte1
= 0xfe;
8952 font
->min_char_or_byte2
= 0xa1;
8953 font
->max_char_or_byte2
= 0xfe;
8955 /* Use the width of an "ideographic space" of that font
8956 because the_fontinfo.widMax returns the wrong width for
8958 switch (font
->mac_scriptcode
)
8961 font
->min_byte1
= 0x81;
8962 font
->max_byte1
= 0xfc;
8963 font
->min_char_or_byte2
= 0x40;
8964 font
->max_char_or_byte2
= 0xfc;
8965 char_width
= StringWidth("\p\x81\x40");
8968 font
->min_char_or_byte2
= 0x40;
8969 char_width
= StringWidth("\p\xa1\x40");
8972 char_width
= StringWidth("\p\xa1\xa1");
8975 char_width
= StringWidth("\p\xa1\xa1");
8979 font
->bounds
.per_char
= NULL
;
8981 if (fontface
& italic
)
8982 font
->max_bounds
.rbearing
= char_width
+ 1;
8984 font
->max_bounds
.rbearing
= char_width
;
8985 font
->max_bounds
.lbearing
= 0;
8986 font
->max_bounds
.width
= char_width
;
8987 font
->max_bounds
.ascent
= the_fontinfo
.ascent
;
8988 font
->max_bounds
.descent
= the_fontinfo
.descent
;
8990 font
->min_bounds
= font
->max_bounds
;
8996 font
->min_byte1
= font
->max_byte1
= 0;
8997 font
->min_char_or_byte2
= 0x20;
8998 font
->max_char_or_byte2
= 0xff;
9000 font
->bounds
.per_char
=
9001 xmalloc (sizeof (XCharStruct
) * (0xff - 0x20 + 1));
9002 bzero (font
->bounds
.per_char
,
9003 sizeof (XCharStruct
) * (0xff - 0x20 + 1));
9005 space_bounds
= font
->bounds
.per_char
;
9006 err
= mac_query_char_extents (NULL
, 0x20, &font
->ascent
,
9007 &font
->descent
, space_bounds
, NULL
);
9008 if (err
!= noErr
|| space_bounds
->width
<= 0)
9010 mac_unload_font (&one_mac_display_info
, font
);
9014 for (c
= 0x21, pcm
= space_bounds
+ 1; c
<= 0xff; c
++, pcm
++)
9015 mac_query_char_extents (NULL
, c
, NULL
, NULL
, pcm
, NULL
);
9023 font
->min_bounds
= font
->max_bounds
= *space_bounds
;
9024 for (c
= 0x21, pcm
= space_bounds
+ 1; c
<= 0x7f; c
++, pcm
++)
9027 font
->min_bounds
.lbearing
= min (font
->min_bounds
.lbearing
,
9029 font
->min_bounds
.rbearing
= min (font
->min_bounds
.rbearing
,
9031 font
->min_bounds
.width
= min (font
->min_bounds
.width
,
9033 font
->min_bounds
.ascent
= min (font
->min_bounds
.ascent
,
9035 font
->min_bounds
.descent
= min (font
->min_bounds
.descent
,
9038 font
->max_bounds
.lbearing
= max (font
->max_bounds
.lbearing
,
9040 font
->max_bounds
.rbearing
= max (font
->max_bounds
.rbearing
,
9042 font
->max_bounds
.width
= max (font
->max_bounds
.width
,
9044 font
->max_bounds
.ascent
= max (font
->max_bounds
.ascent
,
9046 font
->max_bounds
.descent
= max (font
->max_bounds
.descent
,
9051 font
->mac_style
== NULL
&&
9053 font
->max_bounds
.width
== font
->min_bounds
.width
9054 && font
->min_bounds
.lbearing
>= 0
9055 && font
->max_bounds
.rbearing
<= font
->max_bounds
.width
)
9057 /* Fixed width and no overhangs. */
9058 xfree (font
->bounds
.per_char
);
9059 font
->bounds
.per_char
= NULL
;
9063 #if !defined (MAC_OS8) || USE_ATSUI
9064 /* AppKit and WebKit do some adjustment to the heights of Courier,
9065 Helvetica, and Times. This only works on the environments where
9066 srcCopy text transfer mode is never used. */
9068 #ifdef MAC_OS8 /* implies USE_ATSUI */
9071 (strcmp (family
, "courier") == 0 || strcmp (family
, "helvetica") == 0
9072 || strcmp (family
, "times") == 0))
9073 font
->ascent
+= (font
->ascent
+ font
->descent
) * .15 + 0.5;
9081 mac_unload_font (dpyinfo
, font
)
9082 struct mac_display_info
*dpyinfo
;
9085 xfree (font
->full_name
);
9087 if (font
->mac_style
)
9091 for (i
= font
->min_byte1
; i
<= font
->max_byte1
; i
++)
9092 if (font
->bounds
.rows
[i
])
9093 xfree (font
->bounds
.rows
[i
]);
9094 xfree (font
->bounds
.rows
);
9095 ATSUDisposeStyle (font
->mac_style
);
9099 if (font
->bounds
.per_char
)
9100 xfree (font
->bounds
.per_char
);
9101 #if USE_CG_TEXT_DRAWING
9103 CGFontRelease (font
->cg_font
);
9104 if (font
->cg_glyphs
)
9105 xfree (font
->cg_glyphs
);
9111 /* Load font named FONTNAME of the size SIZE for frame F, and return a
9112 pointer to the structure font_info while allocating it dynamically.
9113 If SIZE is 0, load any size of font.
9114 If loading is failed, return NULL. */
9117 x_load_font (f
, fontname
, size
)
9119 register char *fontname
;
9122 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
9123 Lisp_Object font_names
;
9125 /* Get a list of all the fonts that match this name. Once we
9126 have a list of matching fonts, we compare them against the fonts
9127 we already have by comparing names. */
9128 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
9130 if (!NILP (font_names
))
9135 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
9136 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
9137 if (dpyinfo
->font_table
[i
].name
9138 && (!strcmp (dpyinfo
->font_table
[i
].name
,
9139 SDATA (XCAR (tail
)))
9140 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
9141 SDATA (XCAR (tail
)))))
9142 return (dpyinfo
->font_table
+ i
);
9147 /* Load the font and add it to the table. */
9149 struct MacFontStruct
*font
;
9150 struct font_info
*fontp
;
9153 fontname
= (char *) SDATA (XCAR (font_names
));
9156 font
= mac_load_query_font (f
, fontname
);
9161 /* Find a free slot in the font table. */
9162 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
9163 if (dpyinfo
->font_table
[i
].name
== NULL
)
9166 /* If no free slot found, maybe enlarge the font table. */
9167 if (i
== dpyinfo
->n_fonts
9168 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
9171 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
9172 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
9174 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
9177 fontp
= dpyinfo
->font_table
+ i
;
9178 if (i
== dpyinfo
->n_fonts
)
9181 /* Now fill in the slots of *FONTP. */
9183 bzero (fontp
, sizeof (*fontp
));
9185 fontp
->font_idx
= i
;
9186 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
9187 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
9189 if (font
->min_bounds
.width
== font
->max_bounds
.width
)
9191 /* Fixed width font. */
9192 fontp
->average_width
= fontp
->space_width
= font
->min_bounds
.width
;
9199 char2b
.byte1
= 0x00, char2b
.byte2
= 0x20;
9200 pcm
= mac_per_char_metric (font
, &char2b
, 0);
9202 fontp
->space_width
= pcm
->width
;
9204 fontp
->space_width
= FONT_WIDTH (font
);
9208 int width
= pcm
->width
;
9209 for (char2b
.byte2
= 33; char2b
.byte2
<= 126; char2b
.byte2
++)
9210 if ((pcm
= mac_per_char_metric (font
, &char2b
, 0)) != NULL
)
9211 width
+= pcm
->width
;
9212 fontp
->average_width
= width
/ 95;
9215 fontp
->average_width
= FONT_WIDTH (font
);
9218 fontp
->full_name
= (char *) xmalloc (strlen (font
->full_name
) + 1);
9219 bcopy (font
->full_name
, fontp
->full_name
, strlen (font
->full_name
) + 1);
9221 fontp
->size
= font
->max_bounds
.width
;
9222 fontp
->height
= FONT_HEIGHT (font
);
9224 /* For some font, ascent and descent in max_bounds field is
9225 larger than the above value. */
9226 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
9227 if (max_height
> fontp
->height
)
9228 fontp
->height
= max_height
;
9231 /* The slot `encoding' specifies how to map a character
9232 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
9233 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
9234 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
9235 2:0xA020..0xFF7F). For the moment, we don't know which charset
9236 uses this font. So, we set information in fontp->encoding[1]
9237 which is never used by any charset. If mapping can't be
9238 decided, set FONT_ENCODING_NOT_DECIDED. */
9239 if (font
->mac_scriptcode
== smJapanese
)
9240 fontp
->encoding
[1] = 4;
9244 = (font
->max_byte1
== 0
9246 ? (font
->min_char_or_byte2
< 0x80
9247 ? (font
->max_char_or_byte2
< 0x80
9248 ? 0 /* 0x20..0x7F */
9249 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
9250 : 1) /* 0xA0..0xFF */
9252 : (font
->min_byte1
< 0x80
9253 ? (font
->max_byte1
< 0x80
9254 ? (font
->min_char_or_byte2
< 0x80
9255 ? (font
->max_char_or_byte2
< 0x80
9256 ? 0 /* 0x2020..0x7F7F */
9257 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
9258 : 3) /* 0x20A0..0x7FFF */
9259 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
9260 : (font
->min_char_or_byte2
< 0x80
9261 ? (font
->max_char_or_byte2
< 0x80
9262 ? 2 /* 0xA020..0xFF7F */
9263 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
9264 : 1))); /* 0xA0A0..0xFFFF */
9267 #if 0 /* MAC_TODO: fill these out with more reasonably values */
9268 fontp
->baseline_offset
9269 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
9270 ? (long) value
: 0);
9271 fontp
->relative_compose
9272 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
9273 ? (long) value
: 0);
9274 fontp
->default_ascent
9275 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
9276 ? (long) value
: 0);
9278 fontp
->baseline_offset
= 0;
9279 fontp
->relative_compose
= 0;
9280 fontp
->default_ascent
= 0;
9283 /* Set global flag fonts_changed_p to non-zero if the font loaded
9284 has a character with a smaller width than any other character
9285 before, or if the font loaded has a smaller height than any
9286 other font loaded before. If this happens, it will make a
9287 glyph matrix reallocation necessary. */
9288 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
9295 /* Return a pointer to struct font_info of a font named FONTNAME for
9296 frame F. If no such font is loaded, return NULL. */
9299 x_query_font (f
, fontname
)
9301 register char *fontname
;
9303 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
9306 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
9307 if (dpyinfo
->font_table
[i
].name
9308 && (!xstricmp (dpyinfo
->font_table
[i
].name
, fontname
)
9309 || !xstricmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
9310 return (dpyinfo
->font_table
+ i
);
9315 /* Find a CCL program for a font specified by FONTP, and set the member
9316 `encoder' of the structure. */
9319 x_find_ccl_program (fontp
)
9320 struct font_info
*fontp
;
9322 Lisp_Object list
, elt
;
9324 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
9328 && STRINGP (XCAR (elt
))
9329 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
9335 struct ccl_program
*ccl
9336 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
9338 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
9341 fontp
->font_encoder
= ccl
;
9345 #if USE_MAC_FONT_PANEL
9346 /* Whether Font Panel has been shown before. The first call to font
9347 panel functions (FPIsFontPanelVisible, SetFontInfoForSelection) is
9348 slow. This variable is used for deferring such a call as much as
9350 static int font_panel_shown_p
= 0;
9352 extern Lisp_Object Qfont
;
9353 static Lisp_Object Qpanel_closed
, Qselection
;
9355 static OSStatus mac_store_event_ref_as_apple_event
P_ ((AEEventClass
, AEEventID
,
9359 const EventParamName
*,
9360 const EventParamType
*));
9363 mac_font_panel_visible_p ()
9365 return font_panel_shown_p
&& FPIsFontPanelVisible ();
9368 static pascal OSStatus
9369 mac_handle_font_event (next_handler
, event
, data
)
9370 EventHandlerCallRef next_handler
;
9374 OSStatus result
, err
;
9377 const EventParamName
*names
;
9378 const EventParamType
*types
;
9379 static const EventParamName names_sel
[] = {kEventParamATSUFontID
,
9380 kEventParamATSUFontSize
,
9381 kEventParamFMFontFamily
,
9382 kEventParamFMFontStyle
,
9383 kEventParamFMFontSize
,
9384 kEventParamFontColor
};
9385 static const EventParamType types_sel
[] = {typeATSUFontID
,
9392 result
= CallNextEventHandler (next_handler
, event
);
9393 if (result
!= eventNotHandledErr
)
9396 switch (GetEventKind (event
))
9398 case kEventFontPanelClosed
:
9399 id_key
= Qpanel_closed
;
9405 case kEventFontSelection
:
9406 id_key
= Qselection
;
9407 num_params
= sizeof (names_sel
) / sizeof (names_sel
[0]);
9413 err
= mac_store_event_ref_as_apple_event (0, 0, Qfont
, id_key
,
9423 mac_show_hide_font_panel ()
9425 if (!font_panel_shown_p
)
9429 static const EventTypeSpec specs
[] =
9430 {{kEventClassFont
, kEventFontPanelClosed
},
9431 {kEventClassFont
, kEventFontSelection
}};
9433 err
= InstallApplicationEventHandler (mac_handle_font_event
,
9434 GetEventTypeCount (specs
),
9439 font_panel_shown_p
= 1;
9442 return FPShowHideFontPanel ();
9446 mac_set_font_info_for_selection (f
, face_id
, c
)
9451 EventTargetRef target
= NULL
;
9452 XFontStruct
*font
= NULL
;
9454 if (!mac_font_panel_visible_p ())
9459 target
= GetWindowEventTarget (FRAME_MAC_WINDOW (f
));
9461 if (FRAME_FACE_CACHE (f
) && CHAR_VALID_P (c
, 0))
9465 face_id
= FACE_FOR_CHAR (f
, FACE_FROM_ID (f
, face_id
), c
);
9466 face
= FACE_FROM_ID (f
, face_id
);
9472 err
= SetFontInfoForSelection (kFontSelectionATSUIType
, 0, NULL
, target
);
9475 if (font
->mac_fontnum
!= -1)
9477 FontSelectionQDStyle qd_style
;
9479 qd_style
.version
= kFontSelectionQDStyleVersionZero
;
9480 qd_style
.instance
.fontFamily
= font
->mac_fontnum
;
9481 qd_style
.instance
.fontStyle
= font
->mac_fontface
;
9482 qd_style
.size
= font
->mac_fontsize
;
9483 qd_style
.hasColor
= false;
9485 err
= SetFontInfoForSelection (kFontSelectionQDType
,
9486 1, &qd_style
, target
);
9489 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,
9490 1, &font
->mac_style
, target
);
9498 /* The Mac Event loop code */
9500 #if !TARGET_API_MAC_CARBON
9502 #include <Quickdraw.h>
9503 #include <Balloons.h>
9504 #include <Devices.h>
9506 #include <Gestalt.h>
9508 #include <Processes.h>
9510 #include <ToolUtils.h>
9511 #include <TextUtils.h>
9512 #include <Dialogs.h>
9515 #include <Resources.h>
9520 #endif /* ! TARGET_API_MAC_CARBON */
9525 #define DEFAULT_NUM_COLS 80
9527 #define MIN_DOC_SIZE 64
9528 #define MAX_DOC_SIZE 32767
9530 #define EXTRA_STACK_ALLOC (256 * 1024)
9532 #define ARGV_STRING_LIST_ID 129
9533 #define ABOUT_ALERT_ID 128
9534 #define RAM_TOO_LARGE_ALERT_ID 129
9536 /* Contains the string "reverse", which is a constant for mouse button emu.*/
9537 Lisp_Object Qreverse
;
9540 /* Modifier associated with the control key, or nil to ignore. */
9541 Lisp_Object Vmac_control_modifier
;
9543 /* Modifier associated with the option key, or nil to ignore. */
9544 Lisp_Object Vmac_option_modifier
;
9546 /* Modifier associated with the command key, or nil to ignore. */
9547 Lisp_Object Vmac_command_modifier
;
9549 /* Modifier associated with the function key, or nil to ignore. */
9550 Lisp_Object Vmac_function_modifier
;
9552 /* True if the option and command modifiers should be used to emulate
9553 a three button mouse */
9554 Lisp_Object Vmac_emulate_three_button_mouse
;
9556 #if TARGET_API_MAC_CARBON
9557 /* Non-zero if the mouse wheel button (i.e. button 4) should map to
9558 mouse-2, instead of mouse-3. */
9559 int mac_wheel_button_is_mouse_2
;
9561 /* If non-zero, the Mac "Command" key is passed on to the Mac Toolbox
9562 for processing before Emacs sees it. */
9563 int mac_pass_command_to_system
;
9565 /* If non-zero, the Mac "Control" key is passed on to the Mac Toolbox
9566 for processing before Emacs sees it. */
9567 int mac_pass_control_to_system
;
9570 /* Points to the variable `inev' in the function XTread_socket. It is
9571 used for passing an input event to the function back from
9572 Carbon/Apple event handlers. */
9573 static struct input_event
*read_socket_inev
= NULL
;
9575 /* Whether or not the screen configuration has changed. */
9576 static int mac_screen_config_changed
= 0;
9578 Point saved_menu_event_location
;
9581 #if TARGET_API_MAC_CARBON
9582 static Lisp_Object Qhi_command
;
9584 extern Lisp_Object Qwindow
;
9585 static Lisp_Object Qtoolbar_switch_mode
;
9588 static TSMDocumentID tsm_document_id
;
9589 static Lisp_Object Qtext_input
;
9590 static Lisp_Object Qupdate_active_input_area
, Qunicode_for_key_event
;
9591 static Lisp_Object Vmac_ts_active_input_overlay
;
9592 extern Lisp_Object Qbefore_string
;
9593 static Lisp_Object Vmac_ts_script_language_on_focus
;
9594 static Lisp_Object saved_ts_script_language_on_focus
;
9595 static ScriptLanguageRecord saved_ts_language
;
9596 static Component saved_ts_component
;
9598 #endif /* TARGET_API_MAC_CARBON */
9599 extern int mac_ready_for_apple_events
;
9600 extern Lisp_Object Qundefined
;
9601 extern void init_apple_event_handler
P_ ((void));
9602 extern void mac_find_apple_event_spec
P_ ((AEEventClass
, AEEventID
,
9603 Lisp_Object
*, Lisp_Object
*,
9605 extern OSErr init_coercion_handler
P_ ((void));
9608 extern OSErr install_drag_handler
P_ ((WindowRef
));
9609 extern void remove_drag_handler
P_ ((WindowRef
));
9611 #if TARGET_API_MAC_CARBON
9612 /* Showing help echo string during menu tracking */
9613 extern OSStatus install_menu_target_item_handler
P_ ((void));
9616 extern OSStatus
install_service_handler ();
9617 static Lisp_Object Qservice
, Qpaste
, Qperform
;
9621 extern void init_emacs_passwd_dir ();
9622 extern int emacs_main (int, char **, char **);
9624 extern void initialize_applescript();
9625 extern void terminate_applescript();
9627 /* Table for translating Mac keycode to X keysym values. Contributed
9629 Mapping for special keys is now identical to that in Apple X11
9630 except `clear' (-> <clear>) on the KeyPad, `enter' (-> <kp-enter>)
9631 on the right of the Cmd key on laptops, and fn + `enter' (->
9633 static const unsigned char keycode_to_xkeysym_table
[] = {
9634 /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9635 /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9636 /*0x20*/ 0, 0, 0, 0, 0x0d /*return*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9638 /*0x30*/ 0x09 /*tab*/, 0 /*0x0020 space*/, 0, 0x08 /*backspace*/,
9639 /*0x34*/ 0x8d /*enter on laptops*/, 0x1b /*escape*/, 0, 0,
9640 /*0x38*/ 0, 0, 0, 0,
9641 /*0x3C*/ 0, 0, 0, 0,
9643 /*0x40*/ 0, 0xae /*kp-decimal*/, 0, 0xaa /*kp-multiply*/,
9644 /*0x44*/ 0, 0xab /*kp-add*/, 0, 0x0b /*clear*/,
9645 /*0x48*/ 0, 0, 0, 0xaf /*kp-divide*/,
9646 /*0x4C*/ 0x8d /*kp-enter*/, 0, 0xad /*kp-subtract*/, 0,
9648 /*0x50*/ 0, 0xbd /*kp-equal*/, 0xb0 /*kp-0*/, 0xb1 /*kp-1*/,
9649 /*0x54*/ 0xb2 /*kp-2*/, 0xb3 /*kp-3*/, 0xb4 /*kp-4*/, 0xb5 /*kp-5*/,
9650 /*0x58*/ 0xb6 /*kp-6*/, 0xb7 /*kp-7*/, 0, 0xb8 /*kp-8*/,
9651 /*0x5C*/ 0xb9 /*kp-9*/, 0, 0, 0,
9653 /*0x60*/ 0xc2 /*f5*/, 0xc3 /*f6*/, 0xc4 /*f7*/, 0xc0 /*f3*/,
9654 /*0x64*/ 0xc5 /*f8*/, 0xc6 /*f9*/, 0, 0xc8 /*f11*/,
9655 /*0x68*/ 0, 0xca /*f13*/, 0xcd /*f16*/, 0xcb /*f14*/,
9656 /*0x6C*/ 0, 0xc7 /*f10*/, 0x0a /*fn+enter on laptops*/, 0xc9 /*f12*/,
9658 /*0x70*/ 0, 0xcc /*f15*/, 0x6a /*help*/, 0x50 /*home*/,
9659 /*0x74*/ 0x55 /*pgup*/, 0xff /*delete*/, 0xc1 /*f4*/, 0x57 /*end*/,
9660 /*0x78*/ 0xbf /*f2*/, 0x56 /*pgdown*/, 0xbe /*f1*/, 0x51 /*left*/,
9661 /*0x7C*/ 0x53 /*right*/, 0x54 /*down*/, 0x52 /*up*/, 0
9665 /* Table for translating Mac keycode with the laptop `fn' key to that
9666 without it. Destination symbols in comments are keys on US
9667 keyboard, and they may not be the same on other types of keyboards.
9668 If the destination is identical to the source (f1 ... f12), it
9669 doesn't map `fn' key to a modifier. */
9670 static const unsigned char fn_keycode_to_keycode_table
[] = {
9671 /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9672 /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9673 /*0x20*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9675 /*0x30*/ 0, 0, 0, 0,
9676 /*0x34*/ 0, 0, 0, 0,
9677 /*0x38*/ 0, 0, 0, 0,
9678 /*0x3C*/ 0, 0, 0, 0,
9680 /*0x40*/ 0, 0x2f /*kp-decimal -> '.'*/, 0, 0x23 /*kp-multiply -> 'p'*/,
9681 /*0x44*/ 0, 0x2c /*kp-add -> '/'*/, 0, 0x16 /*clear -> '6'*/,
9682 /*0x48*/ 0, 0, 0, 0x1d /*kp-/ -> '0'*/,
9683 /*0x4C*/ 0x24 /*kp-enter -> return*/, 0, 0x29 /*kp-subtract -> ';'*/, 0,
9685 /*0x50*/ 0, 0x1b /*kp-equal -> '-'*/, 0x2e /*kp-0 -> 'm'*/, 0x26 /*kp-1 -> 'j'*/,
9686 /*0x54*/ 0x28 /*kp-2 -> 'k'*/, 0x25 /*kp-3 -> 'l'*/, 0x20 /*kp-4 -> 'u'*/, 0x22 /*kp-5 ->'i'*/,
9687 /*0x58*/ 0x1f /*kp-6 -> 'o'*/, 0x1a /*kp-7 -> '7'*/, 0, 0x1c /*kp-8 -> '8'*/,
9688 /*0x5C*/ 0x19 /*kp-9 -> '9'*/, 0, 0, 0,
9690 /*0x60*/ 0x60 /*f5 = f5*/, 0x61 /*f6 = f6*/, 0x62 /*f7 = f7*/, 0x63 /*f3 = f3*/,
9691 /*0x64*/ 0x64 /*f8 = f8*/, 0x65 /*f9 = f9*/, 0, 0x67 /*f11 = f11*/,
9692 /*0x68*/ 0, 0, 0, 0,
9693 /*0x6C*/ 0, 0x6d /*f10 = f10*/, 0, 0x6f /*f12 = f12*/,
9695 /*0x70*/ 0, 0, 0, 0x7b /*home -> left*/,
9696 /*0x74*/ 0x7e /*pgup -> up*/, 0x33 /*delete -> backspace*/, 0x76 /*f4 = f4*/, 0x7c /*end -> right*/,
9697 /*0x78*/ 0x78 /*f2 = f2*/, 0x7d /*pgdown -> down*/, 0x7a /*f1 = f1*/, 0,
9700 #endif /* MAC_OSX */
9703 #if TARGET_API_MAC_CARBON
9704 mac_to_emacs_modifiers (UInt32 mods
)
9706 mac_to_emacs_modifiers (EventModifiers mods
)
9709 unsigned int result
= 0;
9710 if (mods
& shiftKey
)
9711 result
|= shift_modifier
;
9713 /* Deactivated to simplify configuration:
9714 if Vmac_option_modifier is non-NIL, we fully process the Option
9715 key. Otherwise, we only process it if an additional Ctrl or Command
9716 is pressed. That way the system may convert the character to a
9718 if ((mods & optionKey) &&
9719 (( !NILP(Vmac_option_modifier) ||
9720 ((mods & cmdKey) || (mods & controlKey))))) */
9722 if (!NILP (Vmac_option_modifier
) && (mods
& optionKey
)) {
9723 Lisp_Object val
= Fget(Vmac_option_modifier
, Qmodifier_value
);
9725 result
|= XUINT(val
);
9727 if (!NILP (Vmac_command_modifier
) && (mods
& cmdKey
)) {
9728 Lisp_Object val
= Fget(Vmac_command_modifier
, Qmodifier_value
);
9730 result
|= XUINT(val
);
9732 if (!NILP (Vmac_control_modifier
) && (mods
& controlKey
)) {
9733 Lisp_Object val
= Fget(Vmac_control_modifier
, Qmodifier_value
);
9735 result
|= XUINT(val
);
9739 if (!NILP (Vmac_function_modifier
) && (mods
& kEventKeyModifierFnMask
)) {
9740 Lisp_Object val
= Fget(Vmac_function_modifier
, Qmodifier_value
);
9742 result
|= XUINT(val
);
9750 mac_mapped_modifiers (modifiers
)
9753 UInt32 mapped_modifiers_all
=
9754 (NILP (Vmac_control_modifier
) ? 0 : controlKey
)
9755 | (NILP (Vmac_option_modifier
) ? 0 : optionKey
)
9756 | (NILP (Vmac_command_modifier
) ? 0 : cmdKey
);
9759 mapped_modifiers_all
|=
9760 (NILP (Vmac_function_modifier
) ? 0 : kEventKeyModifierFnMask
);
9763 return mapped_modifiers_all
& modifiers
;
9767 mac_get_emulated_btn ( UInt32 modifiers
)
9770 if (!NILP (Vmac_emulate_three_button_mouse
)) {
9771 int cmdIs3
= !EQ (Vmac_emulate_three_button_mouse
, Qreverse
);
9772 if (modifiers
& cmdKey
)
9773 result
= cmdIs3
? 2 : 1;
9774 else if (modifiers
& optionKey
)
9775 result
= cmdIs3
? 1 : 2;
9780 #if TARGET_API_MAC_CARBON
9781 /***** Code to handle C-g testing *****/
9782 extern int quit_char
;
9783 extern int make_ctrl_char
P_ ((int));
9786 mac_quit_char_key_p (modifiers
, key_code
)
9787 UInt32 modifiers
, key_code
;
9790 unsigned long some_state
= 0;
9791 Ptr kchr_ptr
= (Ptr
) GetScriptManagerVariable (smKCHRCache
);
9792 int c
, emacs_modifiers
;
9794 /* Mask off modifier keys that are mapped to some Emacs modifiers. */
9795 key_code
|= (modifiers
& ~(mac_mapped_modifiers (modifiers
)));
9796 char_code
= KeyTranslate (kchr_ptr
, key_code
, &some_state
);
9797 if (char_code
& ~0xff)
9800 emacs_modifiers
= mac_to_emacs_modifiers (modifiers
);
9801 if (emacs_modifiers
& ctrl_modifier
)
9802 c
= make_ctrl_char (char_code
);
9804 c
|= (emacs_modifiers
9805 & (meta_modifier
| alt_modifier
9806 | hyper_modifier
| super_modifier
));
9808 return c
== quit_char
;
9812 #if TARGET_API_MAC_CARBON
9813 /* Obtains the event modifiers from the event ref and then calls
9814 mac_to_emacs_modifiers. */
9816 mac_event_to_emacs_modifiers (EventRef eventRef
)
9818 UInt32 mods
= 0, class;
9820 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
9821 sizeof (UInt32
), NULL
, &mods
);
9822 class = GetEventClass (eventRef
);
9823 if (!NILP (Vmac_emulate_three_button_mouse
) &&
9824 (class == kEventClassMouse
|| class == kEventClassCommand
))
9826 mods
&= ~(optionKey
| cmdKey
);
9828 return mac_to_emacs_modifiers (mods
);
9831 /* Given an event ref, return the code to use for the mouse button
9832 code in the emacs input_event. */
9834 mac_get_mouse_btn (EventRef ref
)
9836 EventMouseButton result
= kEventMouseButtonPrimary
;
9837 GetEventParameter (ref
, kEventParamMouseButton
, typeMouseButton
, NULL
,
9838 sizeof (EventMouseButton
), NULL
, &result
);
9841 case kEventMouseButtonPrimary
:
9842 if (NILP (Vmac_emulate_three_button_mouse
))
9846 GetEventParameter (ref
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
9847 sizeof (UInt32
), NULL
, &mods
);
9848 return mac_get_emulated_btn(mods
);
9850 case kEventMouseButtonSecondary
:
9851 return mac_wheel_button_is_mouse_2
? 2 : 1;
9852 case kEventMouseButtonTertiary
:
9853 case 4: /* 4 is the number for the mouse wheel button */
9854 return mac_wheel_button_is_mouse_2
? 1 : 2;
9860 /* Normally, ConvertEventRefToEventRecord will correctly handle all
9861 events. However the click of the mouse wheel is not converted to a
9862 mouseDown or mouseUp event. Likewise for dead key events. This
9863 calls ConvertEventRefToEventRecord, but then checks to see if it is
9864 a mouse up/down, or a dead key Carbon event that has not been
9865 converted, and if so, converts it by hand (to be picked up in the
9866 XTread_socket loop). */
9867 static Boolean
mac_convert_event_ref (EventRef eventRef
, EventRecord
*eventRec
)
9870 Boolean result
= ConvertEventRefToEventRecord (eventRef
, eventRec
);
9876 switch (GetEventClass (eventRef
))
9878 case kEventClassMouse
:
9879 switch (GetEventKind (eventRef
))
9881 case kEventMouseDown
:
9882 eventRec
->what
= mouseDown
;
9887 eventRec
->what
= mouseUp
;
9896 case kEventClassKeyboard
:
9897 switch (GetEventKind (eventRef
))
9899 case kEventRawKeyDown
:
9901 goto keystroke_common
;
9902 case kEventRawKeyRepeat
:
9904 goto keystroke_common
;
9905 case kEventRawKeyUp
:
9909 unsigned char char_codes
;
9912 err
= GetEventParameter (eventRef
, kEventParamKeyMacCharCodes
,
9913 typeChar
, NULL
, sizeof (char),
9916 err
= GetEventParameter (eventRef
, kEventParamKeyCode
,
9917 typeUInt32
, NULL
, sizeof (UInt32
),
9921 eventRec
->what
= action
;
9922 eventRec
->message
= char_codes
| ((key_code
& 0xff) << 8);
9939 /* Need where and when. */
9942 GetEventParameter (eventRef
, kEventParamMouseLocation
, typeQDPoint
,
9943 NULL
, sizeof (Point
), NULL
, &eventRec
->where
);
9944 /* Use two step process because new event modifiers are 32-bit
9945 and old are 16-bit. Currently, only loss is NumLock & Fn. */
9946 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
,
9947 NULL
, sizeof (UInt32
), NULL
, &mods
);
9948 eventRec
->modifiers
= mods
;
9950 eventRec
->when
= EventTimeToTicks (GetEventTime (eventRef
));
9962 Handle menubar_handle
;
9965 menubar_handle
= GetNewMBar (128);
9966 if(menubar_handle
== NULL
)
9968 SetMenuBar (menubar_handle
);
9971 #if !TARGET_API_MAC_CARBON
9972 menu
= GetMenuRef (M_APPLE
);
9974 AppendResMenu (menu
, 'DRVR');
9982 do_init_managers (void)
9984 #if !TARGET_API_MAC_CARBON
9985 InitGraf (&qd
.thePort
);
9987 FlushEvents (everyEvent
, 0);
9992 #endif /* !TARGET_API_MAC_CARBON */
9995 #if !TARGET_API_MAC_CARBON
9996 /* set up some extra stack space for use by emacs */
9997 SetApplLimit ((Ptr
) ((long) GetApplLimit () - EXTRA_STACK_ALLOC
));
9999 /* MaxApplZone must be called for AppleScript to execute more
10000 complicated scripts */
10003 #endif /* !TARGET_API_MAC_CARBON */
10007 do_check_ram_size (void)
10009 SInt32 physical_ram_size
, logical_ram_size
;
10011 if (Gestalt (gestaltPhysicalRAMSize
, &physical_ram_size
) != noErr
10012 || Gestalt (gestaltLogicalRAMSize
, &logical_ram_size
) != noErr
10013 || physical_ram_size
> (1 << VALBITS
)
10014 || logical_ram_size
> (1 << VALBITS
))
10016 StopAlert (RAM_TOO_LARGE_ALERT_ID
, NULL
);
10020 #endif /* MAC_OS8 */
10023 do_window_update (WindowRef win
)
10025 struct frame
*f
= mac_window_to_frame (win
);
10029 /* The tooltip has been drawn already. Avoid the SET_FRAME_GARBAGED
10031 if (win
!= tip_window
)
10033 if (f
->async_visible
== 0)
10035 /* Update events may occur when a frame gets iconified. */
10037 f
->async_visible
= 1;
10038 f
->async_iconified
= 0;
10039 SET_FRAME_GARBAGED (f
);
10045 #if TARGET_API_MAC_CARBON
10046 RgnHandle region
= NewRgn ();
10048 GetPortVisibleRegion (GetWindowPort (win
), region
);
10049 GetRegionBounds (region
, &r
);
10050 expose_frame (f
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
);
10052 mac_prepare_for_quickdraw (f
);
10054 UpdateControls (win
, region
);
10055 DisposeRgn (region
);
10057 r
= (*win
->visRgn
)->rgnBBox
;
10058 expose_frame (f
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
);
10059 UpdateControls (win
, win
->visRgn
);
10068 is_emacs_window (WindowRef win
)
10070 Lisp_Object tail
, frame
;
10075 FOR_EACH_FRAME (tail
, frame
)
10076 if (FRAME_MAC_P (XFRAME (frame
)))
10077 if (FRAME_MAC_WINDOW (XFRAME (frame
)) == win
)
10088 ScriptLanguageRecord slrec
, *slptr
= NULL
;
10090 err
= ActivateTSMDocument (tsm_document_id
);
10094 if (EQ (Vmac_ts_script_language_on_focus
, Qt
)
10095 && EQ (saved_ts_script_language_on_focus
, Qt
))
10096 slptr
= &saved_ts_language
;
10097 else if (CONSP (Vmac_ts_script_language_on_focus
)
10098 && INTEGERP (XCAR (Vmac_ts_script_language_on_focus
))
10099 && INTEGERP (XCDR (Vmac_ts_script_language_on_focus
))
10100 && CONSP (saved_ts_script_language_on_focus
)
10101 && EQ (XCAR (saved_ts_script_language_on_focus
),
10102 XCAR (Vmac_ts_script_language_on_focus
))
10103 && EQ (XCDR (saved_ts_script_language_on_focus
),
10104 XCDR (Vmac_ts_script_language_on_focus
)))
10106 slrec
.fScript
= XINT (XCAR (Vmac_ts_script_language_on_focus
));
10107 slrec
.fLanguage
= XINT (XCDR (Vmac_ts_script_language_on_focus
));
10114 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
10115 err
= SetDefaultInputMethodOfClass (saved_ts_component
, slptr
,
10116 kKeyboardInputMethodClass
);
10118 err
= SetDefaultInputMethod (saved_ts_component
, slptr
);
10121 err
= SetTextServiceLanguage (slptr
);
10123 /* Seems to be needed on Mac OS X 10.2. */
10125 KeyScript (slptr
->fScript
| smKeyForceKeyScriptMask
);
10135 ScriptLanguageRecord slrec
, *slptr
= NULL
;
10137 saved_ts_script_language_on_focus
= Vmac_ts_script_language_on_focus
;
10139 if (EQ (Vmac_ts_script_language_on_focus
, Qt
))
10141 err
= GetTextServiceLanguage (&saved_ts_language
);
10143 slptr
= &saved_ts_language
;
10145 else if (CONSP (Vmac_ts_script_language_on_focus
)
10146 && INTEGERP (XCAR (Vmac_ts_script_language_on_focus
))
10147 && INTEGERP (XCDR (Vmac_ts_script_language_on_focus
)))
10149 slrec
.fScript
= XINT (XCAR (Vmac_ts_script_language_on_focus
));
10150 slrec
.fLanguage
= XINT (XCDR (Vmac_ts_script_language_on_focus
));
10156 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
10157 GetDefaultInputMethodOfClass (&saved_ts_component
, slptr
,
10158 kKeyboardInputMethodClass
);
10160 GetDefaultInputMethod (&saved_ts_component
, slptr
);
10164 err
= DeactivateTSMDocument (tsm_document_id
);
10170 #if !TARGET_API_MAC_CARBON
10172 do_apple_menu (SInt16 menu_item
)
10175 SInt16 da_driver_refnum
;
10177 if (menu_item
== I_ABOUT
)
10178 NoteAlert (ABOUT_ALERT_ID
, NULL
);
10181 GetMenuItemText (GetMenuRef (M_APPLE
), menu_item
, item_name
);
10182 da_driver_refnum
= OpenDeskAcc (item_name
);
10185 #endif /* !TARGET_API_MAC_CARBON */
10187 /* Handle drags in size box. Based on code contributed by Ben
10188 Mesander and IM - Window Manager A. */
10191 do_grow_window (w
, e
)
10193 const EventRecord
*e
;
10196 int rows
, columns
, width
, height
;
10197 struct frame
*f
= mac_window_to_frame (w
);
10198 XSizeHints
*size_hints
= FRAME_SIZE_HINTS (f
);
10199 int min_width
= MIN_DOC_SIZE
, min_height
= MIN_DOC_SIZE
;
10200 #if TARGET_API_MAC_CARBON
10206 if (size_hints
->flags
& PMinSize
)
10208 min_width
= size_hints
->min_width
;
10209 min_height
= size_hints
->min_height
;
10211 SetRect (&limit_rect
, min_width
, min_height
, MAX_DOC_SIZE
, MAX_DOC_SIZE
);
10213 #if TARGET_API_MAC_CARBON
10214 if (!ResizeWindow (w
, e
->where
, &limit_rect
, &new_rect
))
10216 height
= new_rect
.bottom
- new_rect
.top
;
10217 width
= new_rect
.right
- new_rect
.left
;
10219 grow_size
= GrowWindow (w
, e
->where
, &limit_rect
);
10220 /* see if it really changed size */
10221 if (grow_size
== 0)
10223 height
= HiWord (grow_size
);
10224 width
= LoWord (grow_size
);
10227 if (width
!= FRAME_PIXEL_WIDTH (f
)
10228 || height
!= FRAME_PIXEL_HEIGHT (f
))
10230 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, height
);
10231 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, width
);
10233 x_set_window_size (f
, 0, columns
, rows
);
10238 #if TARGET_API_MAC_CARBON
10240 mac_get_ideal_size (f
)
10243 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
10244 WindowRef w
= FRAME_MAC_WINDOW (f
);
10246 Rect standard_rect
;
10247 int height
, width
, columns
, rows
;
10249 ideal_size
.h
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
10250 ideal_size
.v
= dpyinfo
->height
;
10251 IsWindowInStandardState (w
, &ideal_size
, &standard_rect
);
10252 /* Adjust the standard size according to character boundaries. */
10253 width
= standard_rect
.right
- standard_rect
.left
;
10254 height
= standard_rect
.bottom
- standard_rect
.top
;
10255 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, width
);
10256 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, height
);
10257 ideal_size
.h
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, columns
);
10258 ideal_size
.v
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
10264 /* Handle clicks in zoom box. Calculation of "standard state" based
10265 on code in IM - Window Manager A and code contributed by Ben
10266 Mesander. The standard state of an Emacs window is 80-characters
10267 wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */
10270 do_zoom_window (WindowRef w
, int zoom_in_or_out
)
10272 Rect zoom_rect
, port_rect
;
10274 struct frame
*f
= mac_window_to_frame (w
);
10275 #if TARGET_API_MAC_CARBON
10276 Point ideal_size
= mac_get_ideal_size (f
);
10278 GetWindowBounds (w
, kWindowContentRgn
, &port_rect
);
10279 if (IsWindowInStandardState (w
, &ideal_size
, &zoom_rect
)
10280 && port_rect
.left
== zoom_rect
.left
10281 && port_rect
.top
== zoom_rect
.top
)
10282 zoom_in_or_out
= inZoomIn
;
10284 zoom_in_or_out
= inZoomOut
;
10287 mac_clear_window (f
);
10289 ZoomWindowIdeal (w
, zoom_in_or_out
, &ideal_size
);
10290 #else /* not TARGET_API_MAC_CARBON */
10293 int w_title_height
, rows
;
10294 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
10296 GetPort (&save_port
);
10298 SetPortWindowPort (w
);
10300 /* Clear window to avoid flicker. */
10301 EraseRect (&(w
->portRect
));
10302 if (zoom_in_or_out
== inZoomOut
)
10304 SetPt (&top_left
, w
->portRect
.left
, w
->portRect
.top
);
10305 LocalToGlobal (&top_left
);
10307 /* calculate height of window's title bar */
10308 w_title_height
= top_left
.v
- 1
10309 - (**((WindowPeek
) w
)->strucRgn
).rgnBBox
.top
+ GetMBarHeight ();
10311 /* get maximum height of window into zoom_rect.bottom - zoom_rect.top */
10312 zoom_rect
= qd
.screenBits
.bounds
;
10313 zoom_rect
.top
+= w_title_height
;
10314 InsetRect (&zoom_rect
, 8, 4); /* not too tight */
10316 zoom_rect
.right
= zoom_rect
.left
10317 + FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
10319 /* Adjust the standard size according to character boundaries. */
10320 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, zoom_rect
.bottom
- zoom_rect
.top
);
10322 zoom_rect
.top
+ FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
10324 (**((WStateDataHandle
) ((WindowPeek
) w
)->dataHandle
)).stdState
10328 ZoomWindow (w
, zoom_in_or_out
, f
== mac_focus_frame (dpyinfo
));
10330 SetPort (save_port
);
10331 #endif /* not TARGET_API_MAC_CARBON */
10333 #if !TARGET_API_MAC_CARBON
10334 /* retrieve window size and update application values */
10335 port_rect
= w
->portRect
;
10336 height
= port_rect
.bottom
- port_rect
.top
;
10337 width
= port_rect
.right
- port_rect
.left
;
10339 mac_handle_size_change (f
, width
, height
);
10340 mac_handle_origin_change (f
);
10345 mac_set_unicode_keystroke_event (code
, buf
)
10347 struct input_event
*buf
;
10349 int charset_id
, c1
, c2
;
10353 buf
->kind
= ASCII_KEYSTROKE_EVENT
;
10356 else if (code
< 0x100)
10359 charset_id
= CHARSET_8_BIT_CONTROL
;
10361 charset_id
= charset_latin_iso8859_1
;
10362 buf
->kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
10363 buf
->code
= MAKE_CHAR (charset_id
, code
, 0);
10368 charset_id
= charset_mule_unicode_0100_24ff
,
10370 else if (code
< 0x33FF)
10371 charset_id
= charset_mule_unicode_2500_33ff
,
10373 else if (code
>= 0xE000)
10374 charset_id
= charset_mule_unicode_e000_ffff
,
10376 c1
= (code
/ 96) + 32, c2
= (code
% 96) + 32;
10377 buf
->kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
10378 buf
->code
= MAKE_CHAR (charset_id
, c1
, c2
);
10383 do_keystroke (action
, char_code
, key_code
, modifiers
, timestamp
, buf
)
10385 unsigned char char_code
;
10386 UInt32 key_code
, modifiers
;
10387 unsigned long timestamp
;
10388 struct input_event
*buf
;
10390 static SInt16 last_key_script
= -1;
10391 SInt16 current_key_script
= GetScriptManagerVariable (smKeyScript
);
10392 UInt32 mapped_modifiers
= mac_mapped_modifiers (modifiers
);
10395 if (mapped_modifiers
& kEventKeyModifierFnMask
10396 && key_code
<= 0x7f
10397 && fn_keycode_to_keycode_table
[key_code
])
10398 key_code
= fn_keycode_to_keycode_table
[key_code
];
10401 if (key_code
<= 0x7f && keycode_to_xkeysym_table
[key_code
])
10403 buf
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
10404 buf
->code
= 0xff00 | keycode_to_xkeysym_table
[key_code
];
10406 if (modifiers
& kEventKeyModifierFnMask
10407 && key_code
<= 0x7f
10408 && fn_keycode_to_keycode_table
[key_code
] == key_code
)
10409 modifiers
&= ~kEventKeyModifierFnMask
;
10412 else if (mapped_modifiers
)
10414 /* translate the keycode back to determine the original key */
10416 UCKeyboardLayout
*uchr_ptr
= NULL
;
10417 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
10419 KeyboardLayoutRef layout
;
10421 err
= KLGetCurrentKeyboardLayout (&layout
);
10423 err
= KLGetKeyboardLayoutProperty (layout
, kKLuchrData
,
10424 (const void **) &uchr_ptr
);
10426 static SInt16 last_key_layout_id
= 0;
10427 static Handle uchr_handle
= (Handle
)-1;
10428 SInt16 current_key_layout_id
=
10429 GetScriptVariable (current_key_script
, smScriptKeys
);
10431 if (uchr_handle
== (Handle
)-1
10432 || last_key_layout_id
!= current_key_layout_id
)
10434 uchr_handle
= GetResource ('uchr', current_key_layout_id
);
10435 last_key_layout_id
= current_key_layout_id
;
10438 uchr_ptr
= (UCKeyboardLayout
*)*uchr_handle
;
10444 UInt16 key_action
= action
- keyDown
;
10445 UInt32 modifier_key_state
= (modifiers
& ~mapped_modifiers
) >> 8;
10446 UInt32 keyboard_type
= LMGetKbdType ();
10447 SInt32 dead_key_state
= 0;
10449 UniCharCount actual_length
;
10451 status
= UCKeyTranslate (uchr_ptr
, key_code
, key_action
,
10452 modifier_key_state
, keyboard_type
,
10453 kUCKeyTranslateNoDeadKeysMask
,
10455 1, &actual_length
, &code
);
10456 if (status
== noErr
&& actual_length
== 1)
10457 mac_set_unicode_keystroke_event (code
, buf
);
10459 #endif /* MAC_OSX */
10461 if (buf
->kind
== NO_EVENT
)
10463 /* This code comes from Keyboard Resource, Appendix C of IM
10464 - Text. This is necessary since shift is ignored in KCHR
10465 table translation when option or command is pressed. It
10466 also does not translate correctly control-shift chars
10467 like C-% so mask off shift here also. */
10468 /* Mask off modifier keys that are mapped to some Emacs
10470 int new_modifiers
= modifiers
& ~mapped_modifiers
;
10471 /* set high byte of keycode to modifier high byte*/
10472 int new_key_code
= key_code
| new_modifiers
;
10473 Ptr kchr_ptr
= (Ptr
) GetScriptManagerVariable (smKCHRCache
);
10474 unsigned long some_state
= 0;
10475 UInt32 new_char_code
;
10477 new_char_code
= KeyTranslate (kchr_ptr
, new_key_code
, &some_state
);
10478 if (new_char_code
== 0)
10479 /* Seems like a dead key. Append up-stroke. */
10480 new_char_code
= KeyTranslate (kchr_ptr
, new_key_code
| 0x80,
10484 buf
->kind
= ASCII_KEYSTROKE_EVENT
;
10485 buf
->code
= new_char_code
& 0xff;
10490 if (buf
->kind
== NO_EVENT
)
10492 buf
->kind
= ASCII_KEYSTROKE_EVENT
;
10493 buf
->code
= char_code
;
10496 buf
->modifiers
= mac_to_emacs_modifiers (modifiers
);
10497 buf
->modifiers
|= (extra_keyboard_modifiers
10498 & (meta_modifier
| alt_modifier
10499 | hyper_modifier
| super_modifier
));
10501 #if TARGET_API_MAC_CARBON
10502 if (buf
->kind
== ASCII_KEYSTROKE_EVENT
10503 && buf
->code
>= 0x80 && buf
->modifiers
)
10506 TextEncoding encoding
= kTextEncodingMacRoman
;
10507 TextToUnicodeInfo ttu_info
;
10509 UpgradeScriptInfoToTextEncoding (current_key_script
,
10510 kTextLanguageDontCare
,
10511 kTextRegionDontCare
,
10513 err
= CreateTextToUnicodeInfoByEncoding (encoding
, &ttu_info
);
10518 ByteCount unicode_len
;
10521 pstr
[1] = buf
->code
;
10522 err
= ConvertFromPStringToUnicode (ttu_info
, pstr
,
10524 &unicode_len
, &code
);
10525 if (err
== noErr
&& unicode_len
== sizeof (UniChar
))
10526 mac_set_unicode_keystroke_event (code
, buf
);
10527 DisposeTextToUnicodeInfo (&ttu_info
);
10532 if (buf
->kind
== ASCII_KEYSTROKE_EVENT
10533 && buf
->code
>= 0x80
10534 && last_key_script
!= current_key_script
)
10536 struct input_event event
;
10538 EVENT_INIT (event
);
10539 event
.kind
= LANGUAGE_CHANGE_EVENT
;
10541 event
.code
= current_key_script
;
10542 event
.timestamp
= timestamp
;
10543 kbd_buffer_store_event (&event
);
10544 last_key_script
= current_key_script
;
10549 mac_store_apple_event (class, id
, desc
)
10550 Lisp_Object
class, id
;
10551 const AEDesc
*desc
;
10553 struct input_event buf
;
10557 buf
.kind
= MAC_APPLE_EVENT
;
10560 XSETFRAME (buf
.frame_or_window
,
10561 mac_focus_frame (&one_mac_display_info
));
10562 /* Now that Lisp object allocations are protected by BLOCK_INPUT, it
10563 is safe to use them during read_socket_hook. */
10564 buf
.arg
= mac_aedesc_to_lisp (desc
);
10565 kbd_buffer_store_event (&buf
);
10568 #if TARGET_API_MAC_CARBON
10570 mac_store_event_ref_as_apple_event (class, id
, class_key
, id_key
,
10571 event
, num_params
, names
, types
)
10572 AEEventClass
class;
10574 Lisp_Object class_key
, id_key
;
10577 const EventParamName
*names
;
10578 const EventParamType
*types
;
10580 OSStatus err
= eventNotHandledErr
;
10581 Lisp_Object binding
;
10583 mac_find_apple_event_spec (class, id
, &class_key
, &id_key
, &binding
);
10584 if (!NILP (binding
) && !EQ (binding
, Qundefined
))
10586 if (INTEGERP (binding
))
10587 err
= XINT (binding
);
10590 AppleEvent apple_event
;
10591 err
= create_apple_event_from_event_ref (event
, num_params
,
10596 mac_store_apple_event (class_key
, id_key
, &apple_event
);
10597 AEDisposeDesc (&apple_event
);
10598 mac_wakeup_from_rne ();
10607 mac_store_drag_event (window
, mouse_pos
, modifiers
, desc
)
10611 const AEDesc
*desc
;
10613 struct input_event buf
;
10617 buf
.kind
= DRAG_N_DROP_EVENT
;
10618 buf
.modifiers
= mac_to_emacs_modifiers (modifiers
);
10619 buf
.timestamp
= TickCount () * (1000 / 60);
10620 XSETINT (buf
.x
, mouse_pos
.h
);
10621 XSETINT (buf
.y
, mouse_pos
.v
);
10622 XSETFRAME (buf
.frame_or_window
, mac_window_to_frame (window
));
10623 buf
.arg
= mac_aedesc_to_lisp (desc
);
10624 kbd_buffer_store_event (&buf
);
10629 mac_store_service_event (event
)
10633 Lisp_Object id_key
;
10635 const EventParamName
*names
;
10636 const EventParamType
*types
;
10637 static const EventParamName names_pfm
[] =
10638 {kEventParamServiceMessageName
, kEventParamServiceUserData
};
10639 static const EventParamType types_pfm
[] =
10640 {typeCFStringRef
, typeCFStringRef
};
10642 switch (GetEventKind (event
))
10644 case kEventServicePaste
:
10651 case kEventServicePerform
:
10653 num_params
= sizeof (names_pfm
) / sizeof (names_pfm
[0]);
10662 err
= mac_store_event_ref_as_apple_event (0, 0, Qservice
, id_key
,
10668 #endif /* MAC_OSX */
10670 static pascal OSStatus
10671 mac_handle_window_event (next_handler
, event
, data
)
10672 EventHandlerCallRef next_handler
;
10677 OSStatus err
, result
= eventNotHandledErr
;
10680 XSizeHints
*size_hints
;
10682 err
= GetEventParameter (event
, kEventParamDirectObject
, typeWindowRef
,
10683 NULL
, sizeof (WindowRef
), NULL
, &wp
);
10685 return eventNotHandledErr
;
10687 f
= mac_window_to_frame (wp
);
10688 switch (GetEventKind (event
))
10690 /* -- window refresh events -- */
10692 case kEventWindowUpdate
:
10693 result
= CallNextEventHandler (next_handler
, event
);
10694 if (result
!= eventNotHandledErr
)
10697 do_window_update (wp
);
10701 /* -- window state change events -- */
10703 case kEventWindowShowing
:
10704 size_hints
= FRAME_SIZE_HINTS (f
);
10705 if (!(size_hints
->flags
& (USPosition
| PPosition
)))
10707 struct frame
*sf
= SELECTED_FRAME ();
10709 if (!(FRAME_MAC_P (sf
) && sf
->async_visible
))
10710 RepositionWindow (wp
, NULL
, kWindowCenterOnMainScreen
);
10713 RepositionWindow (wp
, FRAME_MAC_WINDOW (sf
),
10714 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
10715 kWindowCascadeStartAtParentWindowScreen
10717 kWindowCascadeOnParentWindowScreen
10720 #if USE_MAC_TOOLBAR
10721 /* This is a workaround. RepositionWindow fails to put
10722 a window at the cascading position when its parent
10723 window has a Carbon HIToolbar. */
10724 if ((f
->left_pos
== sf
->left_pos
10725 && f
->top_pos
== sf
->top_pos
)
10726 || (f
->left_pos
== sf
->left_pos
+ 10 * 2
10727 && f
->top_pos
== sf
->top_pos
+ 32 * 2))
10728 MoveWindowStructure (wp
, sf
->left_pos
+ 10, sf
->top_pos
+ 32);
10735 case kEventWindowHiding
:
10736 /* Before unmapping the window, update the WM_SIZE_HINTS
10737 property to claim that the current position of the window is
10738 user-specified, rather than program-specified, so that when
10739 the window is mapped again, it will be placed at the same
10740 location, without forcing the user to position it by hand
10741 again (they have already done that once for this window.) */
10742 x_wm_set_size_hint (f
, (long) 0, 1);
10746 case kEventWindowShown
:
10747 case kEventWindowHidden
:
10748 case kEventWindowCollapsed
:
10749 case kEventWindowExpanded
:
10750 mac_handle_visibility_change (f
);
10754 case kEventWindowBoundsChanging
:
10755 result
= CallNextEventHandler (next_handler
, event
);
10756 if (result
!= eventNotHandledErr
)
10759 err
= GetEventParameter (event
, kEventParamAttributes
, typeUInt32
,
10760 NULL
, sizeof (UInt32
), NULL
, &attributes
);
10764 size_hints
= FRAME_SIZE_HINTS (f
);
10765 if ((attributes
& kWindowBoundsChangeUserResize
)
10766 && ((size_hints
->flags
& (PResizeInc
| PBaseSize
| PMinSize
))
10767 == (PResizeInc
| PBaseSize
| PMinSize
)))
10772 err
= GetEventParameter (event
, kEventParamCurrentBounds
,
10773 typeQDRectangle
, NULL
, sizeof (Rect
),
10778 width
= bounds
.right
- bounds
.left
;
10779 height
= bounds
.bottom
- bounds
.top
;
10781 if (width
< size_hints
->min_width
)
10782 width
= size_hints
->min_width
;
10784 width
= size_hints
->base_width
10785 + (int) ((width
- size_hints
->base_width
)
10786 / (float) size_hints
->width_inc
+ .5)
10787 * size_hints
->width_inc
;
10789 if (height
< size_hints
->min_height
)
10790 height
= size_hints
->min_height
;
10792 height
= size_hints
->base_height
10793 + (int) ((height
- size_hints
->base_height
)
10794 / (float) size_hints
->height_inc
+ .5)
10795 * size_hints
->height_inc
;
10797 bounds
.right
= bounds
.left
+ width
;
10798 bounds
.bottom
= bounds
.top
+ height
;
10799 SetEventParameter (event
, kEventParamCurrentBounds
,
10800 typeQDRectangle
, sizeof (Rect
), &bounds
);
10805 case kEventWindowBoundsChanged
:
10806 err
= GetEventParameter (event
, kEventParamAttributes
, typeUInt32
,
10807 NULL
, sizeof (UInt32
), NULL
, &attributes
);
10811 if (attributes
& kWindowBoundsChangeSizeChanged
)
10815 err
= GetEventParameter (event
, kEventParamCurrentBounds
,
10816 typeQDRectangle
, NULL
, sizeof (Rect
),
10822 width
= bounds
.right
- bounds
.left
;
10823 height
= bounds
.bottom
- bounds
.top
;
10824 mac_handle_size_change (f
, width
, height
);
10825 mac_wakeup_from_rne ();
10829 if (attributes
& kWindowBoundsChangeOriginChanged
)
10830 mac_handle_origin_change (f
);
10835 /* -- window action events -- */
10837 case kEventWindowClose
:
10839 struct input_event buf
;
10842 buf
.kind
= DELETE_WINDOW_EVENT
;
10843 XSETFRAME (buf
.frame_or_window
, f
);
10845 kbd_buffer_store_event (&buf
);
10850 case kEventWindowGetIdealSize
:
10851 result
= CallNextEventHandler (next_handler
, event
);
10852 if (result
!= eventNotHandledErr
)
10856 Point ideal_size
= mac_get_ideal_size (f
);
10858 err
= SetEventParameter (event
, kEventParamDimensions
,
10859 typeQDPoint
, sizeof (Point
), &ideal_size
);
10866 case kEventWindowToolbarSwitchMode
:
10868 static const EventParamName names
[] = {kEventParamDirectObject
,
10869 kEventParamWindowMouseLocation
,
10870 kEventParamKeyModifiers
,
10871 kEventParamMouseButton
,
10872 kEventParamClickCount
,
10873 kEventParamMouseChord
};
10874 static const EventParamType types
[] = {typeWindowRef
,
10880 int num_params
= sizeof (names
) / sizeof (names
[0]);
10882 err
= mac_store_event_ref_as_apple_event (0, 0,
10884 Qtoolbar_switch_mode
,
10894 /* -- window focus events -- */
10896 case kEventWindowFocusAcquired
:
10897 err
= mac_tsm_resume ();
10902 case kEventWindowFocusRelinquish
:
10903 err
= mac_tsm_suspend ();
10916 static pascal OSStatus
10917 mac_handle_application_event (next_handler
, event
, data
)
10918 EventHandlerCallRef next_handler
;
10922 OSStatus err
, result
= eventNotHandledErr
;
10924 switch (GetEventKind (event
))
10927 case kEventAppActivated
:
10928 err
= mac_tsm_resume ();
10931 case kEventAppDeactivated
:
10932 err
= mac_tsm_suspend ();
10946 static pascal OSStatus
10947 mac_handle_keyboard_event (next_handler
, event
, data
)
10948 EventHandlerCallRef next_handler
;
10952 OSStatus err
, result
= eventNotHandledErr
;
10953 UInt32 event_kind
, key_code
, modifiers
;
10954 unsigned char char_code
;
10956 event_kind
= GetEventKind (event
);
10957 switch (event_kind
)
10959 case kEventRawKeyDown
:
10960 case kEventRawKeyRepeat
:
10961 case kEventRawKeyUp
:
10962 /* When using Carbon Events, we need to pass raw keyboard events
10963 to the TSM ourselves. If TSM handles it, it will pass back
10964 noErr, otherwise it will pass back "eventNotHandledErr" and
10965 we can process it normally. */
10966 result
= CallNextEventHandler (next_handler
, event
);
10967 if (result
!= eventNotHandledErr
)
10970 if (read_socket_inev
== NULL
)
10974 if (read_socket_inev
->kind
!= NO_EVENT
)
10981 if (event_kind
== kEventRawKeyUp
)
10984 err
= GetEventParameter (event
, kEventParamKeyMacCharCodes
,
10986 sizeof (char), NULL
, &char_code
);
10990 err
= GetEventParameter (event
, kEventParamKeyCode
,
10992 sizeof (UInt32
), NULL
, &key_code
);
10996 err
= GetEventParameter (event
, kEventParamKeyModifiers
,
10998 sizeof (UInt32
), NULL
, &modifiers
);
11002 do_keystroke ((event_kind
== kEventRawKeyDown
? keyDown
: autoKey
),
11003 char_code
, key_code
, modifiers
,
11005 (GetEventTime (event
) / kEventDurationMillisecond
)),
11017 static pascal OSStatus
11018 mac_handle_command_event (next_handler
, event
, data
)
11019 EventHandlerCallRef next_handler
;
11023 OSStatus err
, result
= eventNotHandledErr
;
11025 static const EventParamName names
[] =
11026 {kEventParamDirectObject
, kEventParamKeyModifiers
};
11027 static const EventParamType types
[] =
11028 {typeHICommand
, typeUInt32
};
11029 int num_params
= sizeof (names
) / sizeof (names
[0]);
11031 err
= GetEventParameter (event
, kEventParamDirectObject
, typeHICommand
,
11032 NULL
, sizeof (HICommand
), NULL
, &command
);
11034 return eventNotHandledErr
;
11036 switch (GetEventKind (event
))
11038 case kEventCommandProcess
:
11039 result
= CallNextEventHandler (next_handler
, event
);
11040 if (result
!= eventNotHandledErr
)
11043 err
= GetEventParameter (event
, kEventParamDirectObject
,
11044 typeHICommand
, NULL
,
11045 sizeof (HICommand
), NULL
, &command
);
11047 if (err
!= noErr
|| command
.commandID
== 0)
11050 /* A HI command event is mapped to an Apple event whose event
11051 class symbol is `hi-command' and event ID is its command
11053 err
= mac_store_event_ref_as_apple_event (0, command
.commandID
,
11068 static pascal OSStatus
11069 mac_handle_mouse_event (next_handler
, event
, data
)
11070 EventHandlerCallRef next_handler
;
11074 OSStatus err
, result
= eventNotHandledErr
;
11076 switch (GetEventKind (event
))
11078 case kEventMouseWheelMoved
:
11082 EventMouseWheelAxis axis
;
11086 result
= CallNextEventHandler (next_handler
, event
);
11087 if (result
!= eventNotHandledErr
|| read_socket_inev
== NULL
)
11090 f
= mac_focus_frame (&one_mac_display_info
);
11092 err
= GetEventParameter (event
, kEventParamWindowRef
, typeWindowRef
,
11093 NULL
, sizeof (WindowRef
), NULL
, &wp
);
11095 || wp
!= FRAME_MAC_WINDOW (f
))
11098 err
= GetEventParameter (event
, kEventParamMouseWheelAxis
,
11099 typeMouseWheelAxis
, NULL
,
11100 sizeof (EventMouseWheelAxis
), NULL
, &axis
);
11101 if (err
!= noErr
|| axis
!= kEventMouseWheelAxisY
)
11104 err
= GetEventParameter (event
, kEventParamMouseLocation
,
11105 typeQDPoint
, NULL
, sizeof (Point
),
11110 point
.h
-= f
->left_pos
+ FRAME_OUTER_TO_INNER_DIFF_X (f
);
11111 point
.v
-= f
->top_pos
+ FRAME_OUTER_TO_INNER_DIFF_Y (f
);
11112 if (point
.h
< 0 || point
.v
< 0
11113 || EQ (window_from_coordinates (f
, point
.h
, point
.v
, 0, 0, 0, 1),
11114 f
->tool_bar_window
))
11117 err
= GetEventParameter (event
, kEventParamMouseWheelDelta
,
11118 typeSInt32
, NULL
, sizeof (SInt32
),
11123 read_socket_inev
->kind
= WHEEL_EVENT
;
11124 read_socket_inev
->code
= 0;
11125 read_socket_inev
->modifiers
=
11126 (mac_event_to_emacs_modifiers (event
)
11127 | ((delta
< 0) ? down_modifier
: up_modifier
));
11128 XSETINT (read_socket_inev
->x
, point
.h
);
11129 XSETINT (read_socket_inev
->y
, point
.v
);
11130 XSETFRAME (read_socket_inev
->frame_or_window
, f
);
11144 static pascal OSStatus
11145 mac_handle_text_input_event (next_handler
, event
, data
)
11146 EventHandlerCallRef next_handler
;
11150 OSStatus err
, result
;
11151 Lisp_Object id_key
= Qnil
;
11153 const EventParamName
*names
;
11154 const EventParamType
*types
;
11155 static UInt32 seqno_uaia
= 0;
11156 static const EventParamName names_uaia
[] =
11157 {kEventParamTextInputSendComponentInstance
,
11158 kEventParamTextInputSendRefCon
,
11159 kEventParamTextInputSendSLRec
,
11160 kEventParamTextInputSendFixLen
,
11161 kEventParamTextInputSendText
,
11162 kEventParamTextInputSendUpdateRng
,
11163 kEventParamTextInputSendHiliteRng
,
11164 kEventParamTextInputSendClauseRng
,
11165 kEventParamTextInputSendPinRng
,
11166 kEventParamTextInputSendTextServiceEncoding
,
11167 kEventParamTextInputSendTextServiceMacEncoding
,
11168 EVENT_PARAM_TEXT_INPUT_SEQUENCE_NUMBER
};
11169 static const EventParamType types_uaia
[] =
11170 {typeComponentInstance
,
11172 typeIntlWritingCode
,
11179 typeTextRangeArray
,
11180 typeTextRangeArray
,
11186 static const EventParamName names_ufke
[] =
11187 {kEventParamTextInputSendComponentInstance
,
11188 kEventParamTextInputSendRefCon
,
11189 kEventParamTextInputSendSLRec
,
11190 kEventParamTextInputSendText
};
11191 static const EventParamType types_ufke
[] =
11192 {typeComponentInstance
,
11194 typeIntlWritingCode
,
11197 result
= CallNextEventHandler (next_handler
, event
);
11198 if (result
!= eventNotHandledErr
)
11201 switch (GetEventKind (event
))
11203 case kEventTextInputUpdateActiveInputArea
:
11204 id_key
= Qupdate_active_input_area
;
11205 num_params
= sizeof (names_uaia
) / sizeof (names_uaia
[0]);
11206 names
= names_uaia
;
11207 types
= types_uaia
;
11208 SetEventParameter (event
, EVENT_PARAM_TEXT_INPUT_SEQUENCE_NUMBER
,
11209 typeUInt32
, sizeof (UInt32
), &seqno_uaia
);
11214 case kEventTextInputUnicodeForKeyEvent
:
11216 EventRef kbd_event
;
11217 UInt32 actual_size
, modifiers
;
11219 err
= GetEventParameter (event
, kEventParamTextInputSendKeyboardEvent
,
11220 typeEventRef
, NULL
, sizeof (EventRef
), NULL
,
11223 err
= GetEventParameter (kbd_event
, kEventParamKeyModifiers
,
11225 sizeof (UInt32
), NULL
, &modifiers
);
11226 if (err
== noErr
&& mac_mapped_modifiers (modifiers
))
11227 /* There're mapped modifier keys. Process it in
11231 err
= GetEventParameter (kbd_event
, kEventParamKeyUnicodes
,
11232 typeUnicodeText
, NULL
, 0, &actual_size
,
11234 if (err
== noErr
&& actual_size
== sizeof (UniChar
))
11238 err
= GetEventParameter (kbd_event
, kEventParamKeyUnicodes
,
11239 typeUnicodeText
, NULL
,
11240 sizeof (UniChar
), NULL
, &code
);
11241 if (err
== noErr
&& code
< 0x80)
11243 /* ASCII character. Process it in do_keystroke. */
11244 if (read_socket_inev
&& code
>= 0x20 && code
<= 0x7e)
11248 err
= GetEventParameter (kbd_event
, kEventParamKeyCode
,
11249 typeUInt32
, NULL
, sizeof (UInt32
),
11251 if (!(err
== noErr
&& key_code
<= 0x7f
11252 && keycode_to_xkeysym_table
[key_code
]))
11255 mac_focus_frame (&one_mac_display_info
);
11257 read_socket_inev
->kind
= ASCII_KEYSTROKE_EVENT
;
11258 read_socket_inev
->code
= code
;
11259 read_socket_inev
->modifiers
=
11260 mac_to_emacs_modifiers (modifiers
);
11261 read_socket_inev
->modifiers
|=
11262 (extra_keyboard_modifiers
11263 & (meta_modifier
| alt_modifier
11264 | hyper_modifier
| super_modifier
));
11265 XSETFRAME (read_socket_inev
->frame_or_window
, f
);
11273 /* Non-ASCII keystrokes without mapped modifiers are
11274 processed at the Lisp level. */
11275 id_key
= Qunicode_for_key_event
;
11276 num_params
= sizeof (names_ufke
) / sizeof (names_ufke
[0]);
11277 names
= names_ufke
;
11278 types
= types_ufke
;
11284 case kEventTextInputOffsetToPos
:
11290 if (!OVERLAYP (Vmac_ts_active_input_overlay
))
11293 /* Strictly speaking, this is not always correct because
11294 previous events may change some states about display. */
11295 if (!NILP (Foverlay_get (Vmac_ts_active_input_overlay
, Qbefore_string
)))
11297 /* Active input area is displayed around the current point. */
11298 f
= SELECTED_FRAME ();
11299 w
= XWINDOW (f
->selected_window
);
11301 else if (WINDOWP (echo_area_window
))
11303 /* Active input area is displayed in the echo area. */
11304 w
= XWINDOW (echo_area_window
);
11305 f
= WINDOW_XFRAME (w
);
11310 p
.h
= (WINDOW_TO_FRAME_PIXEL_X (w
, w
->cursor
.x
)
11311 + WINDOW_LEFT_FRINGE_WIDTH (w
)
11312 + f
->left_pos
+ FRAME_OUTER_TO_INNER_DIFF_X (f
));
11313 p
.v
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->cursor
.y
)
11314 + FONT_BASE (FRAME_FONT (f
))
11315 + f
->top_pos
+ FRAME_OUTER_TO_INNER_DIFF_Y (f
));
11316 err
= SetEventParameter (event
, kEventParamTextInputReplyPoint
,
11317 typeQDPoint
, sizeof (typeQDPoint
), &p
);
11327 if (!NILP (id_key
))
11328 err
= mac_store_event_ref_as_apple_event (0, 0, Qtext_input
, id_key
,
11334 #endif /* TARGET_API_MAC_CARBON */
11338 install_window_handler (window
)
11341 OSStatus err
= noErr
;
11343 #if TARGET_API_MAC_CARBON
11346 static const EventTypeSpec specs
[] =
11348 /* -- window refresh events -- */
11349 {kEventClassWindow
, kEventWindowUpdate
},
11350 /* -- window state change events -- */
11351 {kEventClassWindow
, kEventWindowShowing
},
11352 {kEventClassWindow
, kEventWindowHiding
},
11353 {kEventClassWindow
, kEventWindowShown
},
11354 {kEventClassWindow
, kEventWindowHidden
},
11355 {kEventClassWindow
, kEventWindowCollapsed
},
11356 {kEventClassWindow
, kEventWindowExpanded
},
11357 {kEventClassWindow
, kEventWindowBoundsChanging
},
11358 {kEventClassWindow
, kEventWindowBoundsChanged
},
11359 /* -- window action events -- */
11360 {kEventClassWindow
, kEventWindowClose
},
11361 {kEventClassWindow
, kEventWindowGetIdealSize
},
11363 {kEventClassWindow
, kEventWindowToolbarSwitchMode
},
11366 /* -- window focus events -- */
11367 {kEventClassWindow
, kEventWindowFocusAcquired
},
11368 {kEventClassWindow
, kEventWindowFocusRelinquish
},
11371 static EventHandlerUPP handle_window_eventUPP
= NULL
;
11373 if (handle_window_eventUPP
== NULL
)
11374 handle_window_eventUPP
= NewEventHandlerUPP (mac_handle_window_event
);
11376 err
= InstallWindowEventHandler (window
, handle_window_eventUPP
,
11377 GetEventTypeCount (specs
),
11378 specs
, NULL
, NULL
);
11383 err
= install_drag_handler (window
);
11389 remove_window_handler (window
)
11392 remove_drag_handler (window
);
11395 #if TARGET_API_MAC_CARBON
11397 install_application_handler ()
11399 OSStatus err
= noErr
;
11403 static const EventTypeSpec specs
[] = {
11405 {kEventClassApplication
, kEventAppActivated
},
11406 {kEventClassApplication
, kEventAppDeactivated
},
11410 err
= InstallApplicationEventHandler (NewEventHandlerUPP
11411 (mac_handle_application_event
),
11412 GetEventTypeCount (specs
),
11413 specs
, NULL
, NULL
);
11418 static const EventTypeSpec specs
[] =
11419 {{kEventClassKeyboard
, kEventRawKeyDown
},
11420 {kEventClassKeyboard
, kEventRawKeyRepeat
},
11421 {kEventClassKeyboard
, kEventRawKeyUp
}};
11423 err
= InstallApplicationEventHandler (NewEventHandlerUPP
11424 (mac_handle_keyboard_event
),
11425 GetEventTypeCount (specs
),
11426 specs
, NULL
, NULL
);
11431 static const EventTypeSpec specs
[] =
11432 {{kEventClassCommand
, kEventCommandProcess
}};
11434 err
= InstallApplicationEventHandler (NewEventHandlerUPP
11435 (mac_handle_command_event
),
11436 GetEventTypeCount (specs
),
11437 specs
, NULL
, NULL
);
11442 static const EventTypeSpec specs
[] =
11443 {{kEventClassMouse
, kEventMouseWheelMoved
}};
11445 err
= InstallApplicationEventHandler (NewEventHandlerUPP
11446 (mac_handle_mouse_event
),
11447 GetEventTypeCount (specs
),
11448 specs
, NULL
, NULL
);
11454 static const EventTypeSpec spec
[] =
11455 {{kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
},
11456 {kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
},
11457 {kEventClassTextInput
, kEventTextInputOffsetToPos
}};
11459 err
= InstallApplicationEventHandler (NewEventHandlerUPP
11460 (mac_handle_text_input_event
),
11461 GetEventTypeCount (spec
),
11467 err
= install_menu_target_item_handler ();
11471 err
= install_service_handler ();
11479 mac_handle_dm_notification (event
)
11482 mac_screen_config_changed
= 1;
11485 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
11487 mac_handle_cg_display_reconfig (display
, flags
, user_info
)
11488 CGDirectDisplayID display
;
11489 CGDisplayChangeSummaryFlags flags
;
11492 mac_screen_config_changed
= 1;
11497 init_dm_notification_handler ()
11501 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
11502 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
11503 if (CGDisplayRegisterReconfigurationCallback
!= NULL
)
11506 CGDisplayRegisterReconfigurationCallback (mac_handle_cg_display_reconfig
,
11509 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
11510 else /* CGDisplayRegisterReconfigurationCallback == NULL */
11512 #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */
11513 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020
11515 static DMNotificationUPP handle_dm_notificationUPP
= NULL
;
11516 ProcessSerialNumber psn
;
11518 if (handle_dm_notificationUPP
== NULL
)
11519 handle_dm_notificationUPP
=
11520 NewDMNotificationUPP (mac_handle_dm_notification
);
11522 err
= GetCurrentProcess (&psn
);
11524 err
= DMRegisterNotifyProc (handle_dm_notificationUPP
, &psn
);
11532 mac_get_screen_info (dpyinfo
)
11533 struct mac_display_info
*dpyinfo
;
11536 /* HasDepth returns true if it is possible to have a 32 bit display,
11537 but this may not be what is actually used. Mac OSX can do better. */
11538 dpyinfo
->color_p
= CGDisplaySamplesPerPixel (kCGDirectMainDisplay
) > 1;
11539 dpyinfo
->n_planes
= CGDisplayBitsPerPixel (kCGDirectMainDisplay
);
11542 CGDisplayCount ndisps
;
11543 CGDirectDisplayID
*displays
;
11545 err
= CGGetActiveDisplayList (0, NULL
, &ndisps
);
11548 displays
= alloca (sizeof (CGDirectDisplayID
) * ndisps
);
11549 err
= CGGetActiveDisplayList (ndisps
, displays
, &ndisps
);
11553 CGRect bounds
= CGRectZero
;
11555 while (ndisps
-- > 0)
11556 bounds
= CGRectUnion (bounds
, CGDisplayBounds (displays
[ndisps
]));
11557 dpyinfo
->height
= CGRectGetHeight (bounds
);
11558 dpyinfo
->width
= CGRectGetWidth (bounds
);
11562 dpyinfo
->height
= CGDisplayPixelsHigh (kCGDirectMainDisplay
);
11563 dpyinfo
->width
= CGDisplayPixelsWide (kCGDirectMainDisplay
);
11566 #else /* !MAC_OSX */
11568 GDHandle gdh
= GetMainDevice ();
11569 Rect rect
= (**gdh
).gdRect
;
11571 dpyinfo
->color_p
= TestDeviceAttribute (gdh
, gdDevType
);
11572 for (dpyinfo
->n_planes
= 32; dpyinfo
->n_planes
> 0; dpyinfo
->n_planes
>>= 1)
11573 if (HasDepth (gdh
, dpyinfo
->n_planes
, gdDevType
, dpyinfo
->color_p
))
11576 for (gdh
= DMGetFirstScreenDevice (dmOnlyActiveDisplays
); gdh
;
11577 gdh
= DMGetNextScreenDevice (gdh
, dmOnlyActiveDisplays
))
11578 UnionRect (&rect
, &(**gdh
).gdRect
, &rect
);
11580 dpyinfo
->height
= rect
.bottom
- rect
.top
;
11581 dpyinfo
->width
= rect
.right
- rect
.left
;
11583 #endif /* !MAC_OSX */
11589 profiler_exit_proc ()
11591 ProfilerDump ("\pEmacs.prof");
11596 /* These few functions implement Emacs as a normal Mac application
11597 (almost): set up the heap and the Toolbox, handle necessary system
11598 events plus a few simple menu events. They also set up Emacs's
11599 access to functions defined in the rest of this file. Emacs uses
11600 function hooks to perform all its terminal I/O. A complete list of
11601 these functions appear in termhooks.h. For what they do, read the
11602 comments there and see also w32term.c and xterm.c. What's
11603 noticeably missing here is the event loop, which is normally
11604 present in most Mac application. After performing the necessary
11605 Mac initializations, main passes off control to emacs_main
11606 (corresponding to main in emacs.c). Emacs_main calls XTread_socket
11607 (defined further below) to read input. This is where
11608 WaitNextEvent/ReceiveNextEvent is called to process Mac events. */
11615 #if __profile__ /* is the profiler on? */
11616 if (ProfilerInit(collectDetailed
, bestTimeBase
, 5000, 200))
11621 /* set creator and type for files created by MSL */
11622 _fcreator
= MAC_EMACS_CREATOR_CODE
;
11626 do_init_managers ();
11630 #ifndef USE_LSB_TAG
11631 do_check_ram_size ();
11634 init_emacs_passwd_dir ();
11638 init_coercion_handler ();
11640 initialize_applescript ();
11642 init_apple_event_handler ();
11644 init_dm_notification_handler ();
11650 /* set up argv array from STR# resource */
11651 get_string_list (&argv
, ARGV_STRING_LIST_ID
);
11655 /* free up AppleScript resources on exit */
11656 atexit (terminate_applescript
);
11658 #if __profile__ /* is the profiler on? */
11659 atexit (profiler_exit_proc
);
11662 /* 3rd param "envp" never used in emacs_main */
11663 (void) emacs_main (argc
, argv
, 0);
11666 /* Never reached - real exit in Fkill_emacs */
11671 #if !TARGET_API_MAC_CARBON
11672 static RgnHandle mouse_region
= NULL
;
11675 mac_wait_next_event (er
, sleep_time
, dequeue
)
11680 static EventRecord er_buf
= {nullEvent
};
11681 UInt32 target_tick
, current_tick
;
11682 EventMask event_mask
;
11684 if (mouse_region
== NULL
)
11685 mouse_region
= NewRgn ();
11687 event_mask
= everyEvent
;
11688 if (!mac_ready_for_apple_events
)
11689 event_mask
-= highLevelEventMask
;
11691 current_tick
= TickCount ();
11692 target_tick
= current_tick
+ sleep_time
;
11694 if (er_buf
.what
== nullEvent
)
11695 while (!WaitNextEvent (event_mask
, &er_buf
,
11696 target_tick
- current_tick
, mouse_region
))
11698 current_tick
= TickCount ();
11699 if (target_tick
<= current_tick
)
11705 er_buf
.what
= nullEvent
;
11708 #endif /* not TARGET_API_MAC_CARBON */
11710 #if TARGET_API_MAC_CARBON
11712 mac_post_mouse_moved_event ()
11714 EventRef event
= NULL
;
11717 err
= CreateEvent (NULL
, kEventClassMouse
, kEventMouseMoved
, 0,
11718 kEventAttributeNone
, &event
);
11723 GetGlobalMouse (&mouse_pos
);
11724 err
= SetEventParameter (event
, kEventParamMouseLocation
, typeQDPoint
,
11725 sizeof (Point
), &mouse_pos
);
11729 UInt32 modifiers
= GetCurrentKeyModifiers ();
11731 err
= SetEventParameter (event
, kEventParamKeyModifiers
, typeUInt32
,
11732 sizeof (UInt32
), &modifiers
);
11735 err
= PostEventToQueue (GetCurrentEventQueue (), event
,
11736 kEventPriorityStandard
);
11738 ReleaseEvent (event
);
11744 /* Emacs calls this whenever it wants to read an input event from the
11747 XTread_socket (sd
, expected
, hold_quit
)
11749 struct input_event
*hold_quit
;
11751 struct input_event inev
;
11753 #if TARGET_API_MAC_CARBON
11755 EventTargetRef toolbox_dispatcher
;
11758 struct mac_display_info
*dpyinfo
= &one_mac_display_info
;
11760 if (interrupt_input_blocked
)
11762 interrupt_input_pending
= 1;
11766 interrupt_input_pending
= 0;
11769 /* So people can tell when we have read the available input. */
11770 input_signal_count
++;
11774 #if TARGET_API_MAC_CARBON
11775 toolbox_dispatcher
= GetEventDispatcherTarget ();
11779 mac_prepare_for_quickdraw (NULL
),
11781 !ReceiveNextEvent (0, NULL
, kEventDurationNoWait
,
11782 kEventRemoveFromQueue
, &eventRef
))
11783 #else /* !TARGET_API_MAC_CARBON */
11784 while (mac_wait_next_event (&er
, 0, true))
11785 #endif /* !TARGET_API_MAC_CARBON */
11789 unsigned long timestamp
;
11792 inev
.kind
= NO_EVENT
;
11795 #if TARGET_API_MAC_CARBON
11796 timestamp
= GetEventTime (eventRef
) / kEventDurationMillisecond
;
11798 if (!mac_convert_event_ref (eventRef
, &er
))
11800 #else /* !TARGET_API_MAC_CARBON */
11801 timestamp
= er
.when
* (1000 / 60); /* ticks to milliseconds */
11802 #endif /* !TARGET_API_MAC_CARBON */
11809 WindowRef window_ptr
;
11810 ControlPartCode part_code
;
11811 int tool_bar_p
= 0;
11813 #if TARGET_API_MAC_CARBON
11816 /* This is needed to send mouse events like aqua window
11817 buttons to the correct handler. */
11818 read_socket_inev
= &inev
;
11819 err
= SendEventToEventTarget (eventRef
, toolbox_dispatcher
);
11820 read_socket_inev
= NULL
;
11821 if (err
!= eventNotHandledErr
)
11824 last_mouse_glyph_frame
= 0;
11826 if (dpyinfo
->grabbed
&& last_mouse_frame
11827 && FRAME_LIVE_P (last_mouse_frame
))
11829 window_ptr
= FRAME_MAC_WINDOW (last_mouse_frame
);
11830 part_code
= inContent
;
11834 part_code
= FindWindow (er
.where
, &window_ptr
);
11835 if (tip_window
&& window_ptr
== tip_window
)
11837 HideWindow (tip_window
);
11838 part_code
= FindWindow (er
.where
, &window_ptr
);
11842 if (er
.what
!= mouseDown
&&
11843 (part_code
!= inContent
|| dpyinfo
->grabbed
== 0))
11849 f
= mac_focus_frame (dpyinfo
);
11850 saved_menu_event_location
= er
.where
;
11851 inev
.kind
= MENU_BAR_ACTIVATE_EVENT
;
11852 XSETFRAME (inev
.frame_or_window
, f
);
11857 #if TARGET_API_MAC_CARBON
11858 FrontNonFloatingWindow ()
11863 || (mac_window_to_frame (window_ptr
)
11864 != dpyinfo
->x_focus_frame
))
11865 SelectWindow (window_ptr
);
11868 ControlPartCode control_part_code
;
11872 ControlKind control_kind
;
11875 f
= mac_window_to_frame (window_ptr
);
11876 /* convert to local coordinates of new window */
11877 mouse_loc
.h
= (er
.where
.h
11879 + FRAME_OUTER_TO_INNER_DIFF_X (f
)));
11880 mouse_loc
.v
= (er
.where
.v
11882 + FRAME_OUTER_TO_INNER_DIFF_Y (f
)));
11883 #if TARGET_API_MAC_CARBON
11884 ch
= FindControlUnderMouse (mouse_loc
, window_ptr
,
11885 &control_part_code
);
11888 GetControlKind (ch
, &control_kind
);
11891 control_part_code
= FindControl (mouse_loc
, window_ptr
,
11895 #if TARGET_API_MAC_CARBON
11896 inev
.code
= mac_get_mouse_btn (eventRef
);
11897 inev
.modifiers
= mac_event_to_emacs_modifiers (eventRef
);
11899 inev
.code
= mac_get_emulated_btn (er
.modifiers
);
11900 inev
.modifiers
= mac_to_emacs_modifiers (er
.modifiers
);
11902 XSETINT (inev
.x
, mouse_loc
.h
);
11903 XSETINT (inev
.y
, mouse_loc
.v
);
11905 if ((dpyinfo
->grabbed
&& tracked_scroll_bar
)
11907 #ifndef USE_TOOLKIT_SCROLL_BARS
11908 /* control_part_code becomes kControlNoPart if
11909 a progress indicator is clicked. */
11910 && control_part_code
!= kControlNoPart
11911 #else /* USE_TOOLKIT_SCROLL_BARS */
11913 && control_kind
.kind
== kControlKindScrollBar
11914 #endif /* MAC_OSX */
11915 #endif /* USE_TOOLKIT_SCROLL_BARS */
11918 struct scroll_bar
*bar
;
11920 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
11922 bar
= tracked_scroll_bar
;
11923 #ifndef USE_TOOLKIT_SCROLL_BARS
11924 control_part_code
= kControlIndicatorPart
;
11928 bar
= (struct scroll_bar
*) GetControlReference (ch
);
11929 #ifdef USE_TOOLKIT_SCROLL_BARS
11930 /* Make the "Ctrl-Mouse-2 splits window" work
11931 for toolkit scroll bars. */
11932 if (inev
.modifiers
& ctrl_modifier
)
11933 x_scroll_bar_handle_click (bar
, control_part_code
,
11935 else if (er
.what
== mouseDown
)
11936 x_scroll_bar_handle_press (bar
, control_part_code
,
11939 x_scroll_bar_handle_release (bar
, &inev
);
11940 #else /* not USE_TOOLKIT_SCROLL_BARS */
11941 x_scroll_bar_handle_click (bar
, control_part_code
,
11943 if (er
.what
== mouseDown
11944 && control_part_code
== kControlIndicatorPart
)
11945 tracked_scroll_bar
= bar
;
11947 tracked_scroll_bar
= NULL
;
11948 #endif /* not USE_TOOLKIT_SCROLL_BARS */
11952 Lisp_Object window
;
11953 int x
= mouse_loc
.h
;
11954 int y
= mouse_loc
.v
;
11956 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
11957 if (EQ (window
, f
->tool_bar_window
))
11959 if (er
.what
== mouseDown
)
11960 handle_tool_bar_click (f
, x
, y
, 1, 0);
11962 handle_tool_bar_click (f
, x
, y
, 0,
11968 XSETFRAME (inev
.frame_or_window
, f
);
11969 inev
.kind
= MOUSE_CLICK_EVENT
;
11973 if (er
.what
== mouseDown
)
11975 dpyinfo
->grabbed
|= (1 << inev
.code
);
11976 last_mouse_frame
= f
;
11979 last_tool_bar_item
= -1;
11983 if ((dpyinfo
->grabbed
& (1 << inev
.code
)) == 0)
11984 /* If a button is released though it was not
11985 previously pressed, that would be because
11986 of multi-button emulation. */
11987 dpyinfo
->grabbed
= 0;
11989 dpyinfo
->grabbed
&= ~(1 << inev
.code
);
11992 /* Ignore any mouse motion that happened before
11993 this event; any subsequent mouse-movement Emacs
11994 events should reflect only motion after the
11997 f
->mouse_moved
= 0;
11999 #ifdef USE_TOOLKIT_SCROLL_BARS
12000 if (inev
.kind
== MOUSE_CLICK_EVENT
12001 || (inev
.kind
== SCROLL_BAR_CLICK_EVENT
12002 && (inev
.modifiers
& ctrl_modifier
)))
12007 inev
.modifiers
|= down_modifier
;
12010 inev
.modifiers
|= up_modifier
;
12017 #if TARGET_API_MAC_CARBON
12019 if (IsWindowPathSelectClick (window_ptr
, &er
))
12021 WindowPathSelect (window_ptr
, NULL
, NULL
);
12024 if (part_code
== inProxyIcon
12025 && (TrackWindowProxyDrag (window_ptr
, er
.where
)
12026 != errUserWantsToDragWindow
))
12028 DragWindow (window_ptr
, er
.where
, NULL
);
12029 #else /* not TARGET_API_MAC_CARBON */
12030 DragWindow (window_ptr
, er
.where
, &qd
.screenBits
.bounds
);
12031 /* Update the frame parameters. */
12033 struct frame
*f
= mac_window_to_frame (window_ptr
);
12035 if (f
&& !f
->async_iconified
)
12036 mac_handle_origin_change (f
);
12038 #endif /* not TARGET_API_MAC_CARBON */
12042 if (TrackGoAway (window_ptr
, er
.where
))
12044 inev
.kind
= DELETE_WINDOW_EVENT
;
12045 XSETFRAME (inev
.frame_or_window
,
12046 mac_window_to_frame (window_ptr
));
12050 /* window resize handling added --ben */
12052 do_grow_window (window_ptr
, &er
);
12055 /* window zoom handling added --ben */
12058 if (TrackBox (window_ptr
, er
.where
, part_code
))
12059 do_zoom_window (window_ptr
, part_code
);
12062 #if USE_MAC_TOOLBAR
12068 err
= HIViewGetViewForMouseEvent (HIViewGetRoot (window_ptr
),
12070 /* This doesn't work on Mac OS X 10.2. */
12072 HIViewClick (ch
, eventRef
);
12075 #endif /* USE_MAC_TOOLBAR */
12083 #if !TARGET_API_MAC_CARBON
12085 do_window_update ((WindowRef
) er
.message
);
12090 switch ((er
.message
>> 24) & 0x000000FF)
12092 case mouseMovedMessage
:
12093 #if !TARGET_API_MAC_CARBON
12094 SetRectRgn (mouse_region
, er
.where
.h
, er
.where
.v
,
12095 er
.where
.h
+ 1, er
.where
.v
+ 1);
12097 previous_help_echo_string
= help_echo_string
;
12098 help_echo_string
= Qnil
;
12100 if (dpyinfo
->grabbed
&& last_mouse_frame
12101 && FRAME_LIVE_P (last_mouse_frame
))
12102 f
= last_mouse_frame
;
12104 f
= dpyinfo
->x_focus_frame
;
12106 if (dpyinfo
->mouse_face_hidden
)
12108 dpyinfo
->mouse_face_hidden
= 0;
12109 clear_mouse_face (dpyinfo
);
12114 WindowRef wp
= FRAME_MAC_WINDOW (f
);
12117 mouse_pos
.h
= (er
.where
.h
12119 + FRAME_OUTER_TO_INNER_DIFF_X (f
)));
12120 mouse_pos
.v
= (er
.where
.v
12122 + FRAME_OUTER_TO_INNER_DIFF_Y (f
)));
12123 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
12124 #ifdef USE_TOOLKIT_SCROLL_BARS
12125 x_scroll_bar_handle_drag (wp
, tracked_scroll_bar
,
12127 #else /* not USE_TOOLKIT_SCROLL_BARS */
12128 x_scroll_bar_note_movement (tracked_scroll_bar
,
12130 - XINT (tracked_scroll_bar
->top
),
12131 er
.when
* (1000 / 60));
12132 #endif /* not USE_TOOLKIT_SCROLL_BARS */
12135 /* Generate SELECT_WINDOW_EVENTs when needed. */
12136 if (!NILP (Vmouse_autoselect_window
))
12138 Lisp_Object window
;
12140 window
= window_from_coordinates (f
,
12145 /* Window will be selected only when it is
12146 not selected now and last mouse movement
12147 event was not in it. Minibuffer window
12148 will be selected only when it is active. */
12149 if (WINDOWP (window
)
12150 && !EQ (window
, last_window
)
12151 && !EQ (window
, selected_window
))
12153 inev
.kind
= SELECT_WINDOW_EVENT
;
12154 inev
.frame_or_window
= window
;
12157 last_window
=window
;
12159 if (!note_mouse_movement (f
, &mouse_pos
))
12160 help_echo_string
= previous_help_echo_string
;
12161 #if USE_MAC_TOOLBAR
12163 mac_tool_bar_note_mouse_movement (f
, eventRef
);
12168 /* If the contents of the global variable
12169 help_echo_string has changed, generate a
12171 if (!NILP (help_echo_string
) || !NILP (previous_help_echo_string
))
12182 WindowRef window_ptr
= (WindowRef
) er
.message
;
12184 ControlRef root_control
;
12186 if (window_ptr
== tip_window
)
12188 HideWindow (tip_window
);
12192 if (!is_emacs_window (window_ptr
))
12195 f
= mac_window_to_frame (window_ptr
);
12197 if ((er
.modifiers
& activeFlag
) != 0)
12199 /* A window has been activated */
12202 err
= GetRootControl (FRAME_MAC_WINDOW (f
), &root_control
);
12204 ActivateControl (root_control
);
12206 x_detect_focus_change (dpyinfo
, &er
, &inev
);
12208 mouse_loc
.h
= (er
.where
.h
12210 + FRAME_OUTER_TO_INNER_DIFF_X (f
)));
12211 mouse_loc
.v
= (er
.where
.v
12213 + FRAME_OUTER_TO_INNER_DIFF_Y (f
)));
12214 /* Window-activated event counts as mouse movement,
12215 so update things that depend on mouse position. */
12216 note_mouse_movement (f
, &mouse_loc
);
12220 /* A window has been deactivated */
12221 err
= GetRootControl (FRAME_MAC_WINDOW (f
), &root_control
);
12223 DeactivateControl (root_control
);
12225 #ifdef USE_TOOLKIT_SCROLL_BARS
12226 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
12228 struct input_event event
;
12230 EVENT_INIT (event
);
12231 event
.kind
= NO_EVENT
;
12232 x_scroll_bar_handle_release (tracked_scroll_bar
, &event
);
12233 if (event
.kind
!= NO_EVENT
)
12235 event
.timestamp
= timestamp
;
12236 kbd_buffer_store_event_hold (&event
, hold_quit
);
12241 dpyinfo
->grabbed
= 0;
12243 x_detect_focus_change (dpyinfo
, &er
, &inev
);
12245 if (f
== dpyinfo
->mouse_face_mouse_frame
)
12247 /* If we move outside the frame, then we're
12248 certainly no longer on any text in the
12250 clear_mouse_face (dpyinfo
);
12251 dpyinfo
->mouse_face_mouse_frame
= 0;
12254 /* Generate a nil HELP_EVENT to cancel a help-echo.
12255 Do it only if there's something to cancel.
12256 Otherwise, the startup message is cleared when the
12257 mouse leaves the frame. */
12258 if (any_help_event_p
)
12269 f
= mac_focus_frame (dpyinfo
);
12270 XSETFRAME (inev
.frame_or_window
, f
);
12272 /* If mouse-highlight is an integer, input clears out mouse
12274 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
12275 && !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
))
12277 clear_mouse_face (dpyinfo
);
12278 dpyinfo
->mouse_face_hidden
= 1;
12282 UInt32 modifiers
= er
.modifiers
, mapped_modifiers
;
12285 GetEventParameter (eventRef
, kEventParamKeyModifiers
,
12287 sizeof (UInt32
), NULL
, &modifiers
);
12289 mapped_modifiers
= mac_mapped_modifiers (modifiers
);
12291 #if TARGET_API_MAC_CARBON
12292 if (!(mapped_modifiers
12293 & ~(mac_pass_command_to_system
? cmdKey
: 0)
12294 & ~(mac_pass_control_to_system
? controlKey
: 0)))
12298 if (er
.what
!= keyUp
)
12299 do_keystroke (er
.what
, er
.message
& charCodeMask
,
12300 (er
.message
& keyCodeMask
) >> 8,
12301 modifiers
, timestamp
, &inev
);
12305 case kHighLevelEvent
:
12306 AEProcessAppleEvent (&er
);
12311 #if TARGET_API_MAC_CARBON
12315 read_socket_inev
= &inev
;
12316 err
= SendEventToEventTarget (eventRef
, toolbox_dispatcher
);
12317 read_socket_inev
= NULL
;
12322 #if TARGET_API_MAC_CARBON
12323 ReleaseEvent (eventRef
);
12326 if (inev
.kind
!= NO_EVENT
)
12328 inev
.timestamp
= timestamp
;
12329 kbd_buffer_store_event_hold (&inev
, hold_quit
);
12334 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
12339 XSETFRAME (frame
, f
);
12345 any_help_event_p
= 1;
12346 gen_help_event (help_echo_string
, frame
, help_echo_window
,
12347 help_echo_object
, help_echo_pos
);
12351 help_echo_string
= Qnil
;
12352 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
12358 /* If the focus was just given to an autoraising frame,
12360 /* ??? This ought to be able to handle more than one such frame. */
12361 if (pending_autoraise_frame
)
12363 x_raise_frame (pending_autoraise_frame
);
12364 pending_autoraise_frame
= 0;
12367 if (mac_screen_config_changed
)
12369 mac_get_screen_info (dpyinfo
);
12370 mac_screen_config_changed
= 0;
12373 #if !TARGET_API_MAC_CARBON
12374 /* Check which frames are still visible. We do this here because
12375 there doesn't seem to be any direct notification from the Window
12376 Manager that the visibility of a window has changed (at least,
12377 not in all cases). */
12379 Lisp_Object tail
, frame
;
12381 FOR_EACH_FRAME (tail
, frame
)
12383 struct frame
*f
= XFRAME (frame
);
12385 /* The tooltip has been drawn already. Avoid the
12386 SET_FRAME_GARBAGED in mac_handle_visibility_change. */
12387 if (EQ (frame
, tip_frame
))
12390 if (FRAME_MAC_P (f
))
12391 mac_handle_visibility_change (f
);
12402 /* Need to override CodeWarrior's input function so no conversion is
12403 done on newlines Otherwise compiled functions in .elc files will be
12404 read incorrectly. Defined in ...:MSL C:MSL
12405 Common:Source:buffer_io.c. */
12408 __convert_to_newlines (unsigned char * p
, size_t * n
)
12410 #pragma unused(p,n)
12414 __convert_from_newlines (unsigned char * p
, size_t * n
)
12416 #pragma unused(p,n)
12422 make_mac_terminal_frame (struct frame
*f
)
12427 XSETFRAME (frame
, f
);
12429 f
->output_method
= output_mac
;
12430 f
->output_data
.mac
= (struct mac_output
*)
12431 xmalloc (sizeof (struct mac_output
));
12432 bzero (f
->output_data
.mac
, sizeof (struct mac_output
));
12434 XSETFRAME (FRAME_KBOARD (f
)->Vdefault_minibuffer_frame
, f
);
12436 FRAME_COLS (f
) = 96;
12437 FRAME_LINES (f
) = 4;
12439 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
12440 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_right
;
12442 FRAME_DESIRED_CURSOR (f
) = FILLED_BOX_CURSOR
;
12444 f
->output_data
.mac
->cursor_pixel
= 0;
12445 f
->output_data
.mac
->border_pixel
= 0x00ff00;
12446 f
->output_data
.mac
->mouse_pixel
= 0xff00ff;
12447 f
->output_data
.mac
->cursor_foreground_pixel
= 0x0000ff;
12449 f
->output_data
.mac
->text_cursor
= kThemeIBeamCursor
;
12450 f
->output_data
.mac
->nontext_cursor
= kThemeArrowCursor
;
12451 f
->output_data
.mac
->modeline_cursor
= kThemeArrowCursor
;
12452 f
->output_data
.mac
->hand_cursor
= kThemePointingHandCursor
;
12453 f
->output_data
.mac
->hourglass_cursor
= kThemeWatchCursor
;
12454 f
->output_data
.mac
->horizontal_drag_cursor
= kThemeResizeLeftRightCursor
;
12456 FRAME_FONTSET (f
) = -1;
12457 f
->output_data
.mac
->explicit_parent
= 0;
12460 f
->border_width
= 0;
12462 f
->internal_border_width
= 0;
12467 f
->new_text_cols
= 0;
12468 f
->new_text_lines
= 0;
12470 SetRect (&r
, f
->left_pos
, f
->top_pos
,
12471 f
->left_pos
+ FRAME_PIXEL_WIDTH (f
),
12472 f
->top_pos
+ FRAME_PIXEL_HEIGHT (f
));
12476 if (!(FRAME_MAC_WINDOW (f
) =
12477 NewCWindow (NULL
, &r
, "\p", true, dBoxProc
,
12478 (WindowRef
) -1, 1, (long) f
->output_data
.mac
)))
12480 /* so that update events can find this mac_output struct */
12481 f
->output_data
.mac
->mFP
= f
; /* point back to emacs frame */
12487 /* Need to be initialized for unshow_buffer in window.c. */
12488 selected_window
= f
->selected_window
;
12490 Fmodify_frame_parameters (frame
,
12491 Fcons (Fcons (Qfont
,
12492 build_string ("-*-monaco-medium-r-*--*-90-*-*-*-*-mac-roman")), Qnil
));
12493 Fmodify_frame_parameters (frame
,
12494 Fcons (Fcons (Qforeground_color
,
12495 build_string ("black")), Qnil
));
12496 Fmodify_frame_parameters (frame
,
12497 Fcons (Fcons (Qbackground_color
,
12498 build_string ("white")), Qnil
));
12503 /***********************************************************************
12505 ***********************************************************************/
12507 static int mac_initialized
= 0;
12510 mac_make_rdb (xrm_option
)
12511 const char *xrm_option
;
12513 XrmDatabase database
;
12515 database
= xrm_get_preference_database (NULL
);
12517 xrm_merge_string_database (database
, xrm_option
);
12522 struct mac_display_info
*
12523 mac_term_init (display_name
, xrm_option
, resource_name
)
12524 Lisp_Object display_name
;
12526 char *resource_name
;
12528 struct mac_display_info
*dpyinfo
;
12529 struct terminal
*terminal
;
12533 if (!mac_initialized
)
12536 mac_initialized
= 1;
12539 if (x_display_list
)
12540 error ("Sorry, this version can only handle one display");
12542 dpyinfo
= &one_mac_display_info
;
12543 bzero (dpyinfo
, sizeof (*dpyinfo
));
12545 terminal
= mac_create_terminal (dpyinfo
);
12547 /* Set the name of the terminal. */
12548 terminal
->name
= (char *) xmalloc (SBYTES (display_name
) + 1);
12549 strncpy (terminal
->name
, SDATA (display_name
), SBYTES (display_name
));
12550 terminal
->name
[SBYTES (display_name
)] = 0;
12553 dpyinfo
->mac_id_name
12554 = (char *) xmalloc (SCHARS (Vinvocation_name
)
12555 + SCHARS (Vsystem_name
)
12557 sprintf (dpyinfo
->mac_id_name
, "%s@%s",
12558 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
12560 dpyinfo
->mac_id_name
= (char *) xmalloc (strlen ("Mac Display") + 1);
12561 strcpy (dpyinfo
->mac_id_name
, "Mac Display");
12564 dpyinfo
->reference_count
= 0;
12565 dpyinfo
->resx
= 72.0;
12566 dpyinfo
->resy
= 72.0;
12568 mac_get_screen_info (dpyinfo
);
12570 dpyinfo
->grabbed
= 0;
12571 dpyinfo
->root_window
= NULL
;
12572 dpyinfo
->image_cache
= make_image_cache ();
12574 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
12575 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
12576 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
12577 dpyinfo
->mouse_face_window
= Qnil
;
12578 dpyinfo
->mouse_face_overlay
= Qnil
;
12579 dpyinfo
->mouse_face_hidden
= 0;
12581 dpyinfo
->xrdb
= mac_make_rdb (xrm_option
);
12583 /* Put this display on the chain. */
12584 dpyinfo
->next
= x_display_list
;
12585 x_display_list
= dpyinfo
;
12587 /* Put it on x_display_name_list. */
12588 x_display_name_list
= Fcons (Fcons (display_name
,
12589 Fcons (Qnil
, dpyinfo
->xrdb
)),
12590 x_display_name_list
);
12591 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
12598 /* Get rid of display DPYINFO, assuming all frames are already gone. */
12601 x_delete_display (dpyinfo
)
12602 struct mac_display_info
*dpyinfo
;
12606 /* Discard this display from x_display_name_list and x_display_list.
12607 We can't use Fdelq because that can quit. */
12608 if (! NILP (x_display_name_list
)
12609 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
12610 x_display_name_list
= XCDR (x_display_name_list
);
12615 tail
= x_display_name_list
;
12616 while (CONSP (tail
) && CONSP (XCDR (tail
)))
12618 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
12620 XSETCDR (tail
, XCDR (XCDR (tail
)));
12623 tail
= XCDR (tail
);
12627 if (x_display_list
== dpyinfo
)
12628 x_display_list
= dpyinfo
->next
;
12631 struct x_display_info
*tail
;
12633 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
12634 if (tail
->next
== dpyinfo
)
12635 tail
->next
= tail
->next
->next
;
12638 /* Free the font names in the font table. */
12639 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12640 if (dpyinfo
->font_table
[i
].name
)
12642 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
12643 xfree (dpyinfo
->font_table
[i
].full_name
);
12644 xfree (dpyinfo
->font_table
[i
].name
);
12647 if (dpyinfo
->font_table
)
12649 if (dpyinfo
->font_table
->font_encoder
)
12650 xfree (dpyinfo
->font_table
->font_encoder
);
12651 xfree (dpyinfo
->font_table
);
12653 if (dpyinfo
->mac_id_name
)
12654 xfree (dpyinfo
->mac_id_name
);
12656 if (x_display_list
== 0)
12658 mac_clear_font_name_table ();
12659 bzero (dpyinfo
, sizeof (*dpyinfo
));
12670 MenuItemIndex menu_index
;
12672 err
= GetIndMenuItemWithCommandID (NULL
, kHICommandQuit
, 1,
12673 &menu
, &menu_index
);
12675 SetMenuItemCommandKey (menu
, menu_index
, false, 0);
12676 EnableMenuCommand (NULL
, kHICommandPreferences
);
12677 err
= GetIndMenuItemWithCommandID (NULL
, kHICommandPreferences
, 1,
12678 &menu
, &menu_index
);
12681 SetMenuItemCommandKey (menu
, menu_index
, false, 0);
12682 InsertMenuItemTextWithCFString (menu
, NULL
,
12683 0, kMenuItemAttrSeparator
, 0);
12684 InsertMenuItemTextWithCFString (menu
, CFSTR ("About Emacs"),
12685 0, 0, kHICommandAbout
);
12687 #else /* !MAC_OSX */
12688 #if TARGET_API_MAC_CARBON
12689 SetMenuItemCommandID (GetMenuRef (M_APPLE
), I_ABOUT
, kHICommandAbout
);
12699 static InterfaceTypeList types
= {kUnicodeDocument
};
12701 static InterfaceTypeList types
= {kTextService
};
12704 NewTSMDocument (sizeof (types
) / sizeof (types
[0]), types
,
12705 &tsm_document_id
, 0);
12709 /* Set up use of X before we make the first connection. */
12711 extern frame_parm_handler mac_frame_parm_handlers
[];
12713 static struct redisplay_interface x_redisplay_interface
=
12715 mac_frame_parm_handlers
,
12719 x_clear_end_of_line
,
12721 x_after_update_window_line
,
12722 x_update_window_begin
,
12723 x_update_window_end
,
12727 mac_flush_display_optional
,
12729 0, /* flush_display_optional */
12731 x_clear_window_mouse_face
,
12732 x_get_glyph_overhangs
,
12733 x_fix_overlapping_area
,
12734 x_draw_fringe_bitmap
,
12736 mac_define_fringe_bitmap
,
12737 mac_destroy_fringe_bitmap
,
12739 0, /* define_fringe_bitmap */
12740 0, /* destroy_fringe_bitmap */
12742 mac_per_char_metric
,
12744 mac_compute_glyph_string_overhangs
,
12745 x_draw_glyph_string
,
12746 mac_define_frame_cursor
,
12747 mac_clear_frame_area
,
12748 mac_draw_window_cursor
,
12749 mac_draw_vertical_window_border
,
12750 mac_shift_glyphs_for_insert
12753 static struct terminal
*
12754 mac_create_terminal (struct mac_display_info
*dpyinfo
)
12756 struct terminal
*terminal
;
12758 terminal
= create_terminal ();
12760 terminal
->type
= output_mac
;
12761 terminal
->display_info
.mac
= dpyinfo
;
12762 dpyinfo
->terminal
= terminal
;
12764 terminal
->clear_frame_hook
= x_clear_frame
;
12765 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
12766 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
12767 terminal
->ring_bell_hook
= XTring_bell
;
12768 terminal
->reset_terminal_modes_hook
= XTreset_terminal_modes
;
12769 terminal
->set_terminal_modes_hook
= XTset_terminal_modes
;
12770 terminal
->update_begin_hook
= x_update_begin
;
12771 terminal
->update_end_hook
= x_update_end
;
12772 terminal
->set_terminal_window_hook
= XTset_terminal_window
;
12773 terminal
->read_socket_hook
= XTread_socket
;
12774 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
12775 terminal
->mouse_position_hook
= XTmouse_position
;
12776 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
12777 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
12778 /* terminal->fullscreen_hook = XTfullscreen_hook; */
12779 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
12780 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
12781 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
12782 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
12783 terminal
->delete_frame_hook
= x_destroy_window
;
12784 /* terminal->delete_terminal_hook = x_delete_terminal; */
12786 terminal
->rif
= &x_redisplay_interface
;
12788 TTY_SCROLL_REGION_OK (CURTTY ()) = 1; /* we'll scroll partial frames */
12789 TTY_CHAR_INS_DEL_OK (CURTTY ()) = 1;
12790 TTY_LINE_INS_DEL_OK (CURTTY ()) = 1; /* we'll just blt 'em */
12791 TTY_FAST_CLEAR_END_OF_LINE (CURTTY ()) = 1; /* X does this well */
12792 TTY_MEMORY_BELOW_FRAME (CURTTY ()) = 0; /* we don't remember what
12796 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
12797 terminal
->char_ins_del_ok
= 1;
12798 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
12799 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
12800 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
12813 last_tool_bar_item
= -1;
12814 any_help_event_p
= 0;
12816 /* Try to use interrupt input; if we can't, then start polling. */
12817 Fset_input_interrupt_mode (Qt
);
12821 #if TARGET_API_MAC_CARBON
12823 install_application_handler ();
12832 init_coercion_handler ();
12834 init_apple_event_handler ();
12836 init_dm_notification_handler ();
12838 if (!inhibit_window_system
)
12840 static const ProcessSerialNumber psn
= {0, kCurrentProcess
};
12842 SetFrontProcess (&psn
);
12850 mac_init_fringe ();
12862 staticpro (&x_error_message_string
);
12863 x_error_message_string
= Qnil
;
12866 Qcontrol
= intern ("control"); staticpro (&Qcontrol
);
12867 Qmeta
= intern ("meta"); staticpro (&Qmeta
);
12868 Qalt
= intern ("alt"); staticpro (&Qalt
);
12869 Qhyper
= intern ("hyper"); staticpro (&Qhyper
);
12870 Qsuper
= intern ("super"); staticpro (&Qsuper
);
12871 Qmodifier_value
= intern ("modifier-value");
12872 staticpro (&Qmodifier_value
);
12874 Fput (Qcontrol
, Qmodifier_value
, make_number (ctrl_modifier
));
12875 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
12876 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
12877 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
12878 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
12880 #if TARGET_API_MAC_CARBON
12881 Qhi_command
= intern ("hi-command"); staticpro (&Qhi_command
);
12883 Qtoolbar_switch_mode
= intern ("toolbar-switch-mode");
12884 staticpro (&Qtoolbar_switch_mode
);
12885 #if USE_MAC_FONT_PANEL
12886 Qpanel_closed
= intern ("panel-closed"); staticpro (&Qpanel_closed
);
12887 Qselection
= intern ("selection"); staticpro (&Qselection
);
12890 Qservice
= intern ("service"); staticpro (&Qservice
);
12891 Qpaste
= intern ("paste"); staticpro (&Qpaste
);
12892 Qperform
= intern ("perform"); staticpro (&Qperform
);
12895 Qtext_input
= intern ("text-input"); staticpro (&Qtext_input
);
12896 Qupdate_active_input_area
= intern ("update-active-input-area");
12897 staticpro (&Qupdate_active_input_area
);
12898 Qunicode_for_key_event
= intern ("unicode-for-key-event");
12899 staticpro (&Qunicode_for_key_event
);
12904 Fprovide (intern ("mac-carbon"), Qnil
);
12907 staticpro (&Qreverse
);
12908 Qreverse
= intern ("reverse");
12910 staticpro (&x_display_name_list
);
12911 x_display_name_list
= Qnil
;
12913 staticpro (&last_mouse_scroll_bar
);
12914 last_mouse_scroll_bar
= Qnil
;
12916 staticpro (&fm_font_family_alist
);
12917 fm_font_family_alist
= Qnil
;
12920 staticpro (&atsu_font_id_hash
);
12921 atsu_font_id_hash
= Qnil
;
12923 staticpro (&fm_style_face_attributes_alist
);
12924 fm_style_face_attributes_alist
= Qnil
;
12928 staticpro (&saved_ts_script_language_on_focus
);
12929 saved_ts_script_language_on_focus
= Qnil
;
12932 /* We don't yet support this, but defining this here avoids whining
12933 from cus-start.el and other places, like "M-x set-variable". */
12934 DEFVAR_BOOL ("x-use-underline-position-properties",
12935 &x_use_underline_position_properties
,
12936 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
12937 A value of nil means ignore them. If you encounter fonts with bogus
12938 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
12939 to 4.1, set this to nil.
12941 NOTE: Not supported on Mac yet. */);
12942 x_use_underline_position_properties
= 0;
12944 DEFVAR_BOOL ("x-underline-at-descent-line",
12945 &x_underline_at_descent_line
,
12946 doc
: /* *Non-nil means to draw the underline at the same place as the descent line.
12947 A value of nil means to draw the underline according to the value of the
12948 variable `x-use-underline-position-properties', which is usually at the
12949 baseline level. The default value is nil. */);
12950 x_underline_at_descent_line
= 0;
12952 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
12953 doc
: /* If not nil, Emacs uses toolkit scroll bars. */);
12954 #ifdef USE_TOOLKIT_SCROLL_BARS
12955 Vx_toolkit_scroll_bars
= Qt
;
12957 Vx_toolkit_scroll_bars
= Qnil
;
12960 staticpro (&last_mouse_motion_frame
);
12961 last_mouse_motion_frame
= Qnil
;
12963 /* Variables to configure modifier key assignment. */
12965 DEFVAR_LISP ("mac-control-modifier", &Vmac_control_modifier
,
12966 doc
: /* *Modifier key assumed when the Mac control key is pressed.
12967 The value can be `control', `meta', `alt', `hyper', or `super' for the
12968 respective modifier. The default is `control'. */);
12969 Vmac_control_modifier
= Qcontrol
;
12971 DEFVAR_LISP ("mac-option-modifier", &Vmac_option_modifier
,
12972 doc
: /* *Modifier key assumed when the Mac alt/option key is pressed.
12973 The value can be `control', `meta', `alt', `hyper', or `super' for the
12974 respective modifier. If the value is nil then the key will act as the
12975 normal Mac control modifier, and the option key can be used to compose
12976 characters depending on the chosen Mac keyboard setting. */);
12977 Vmac_option_modifier
= Qnil
;
12979 DEFVAR_LISP ("mac-command-modifier", &Vmac_command_modifier
,
12980 doc
: /* *Modifier key assumed when the Mac command key is pressed.
12981 The value can be `control', `meta', `alt', `hyper', or `super' for the
12982 respective modifier. The default is `meta'. */);
12983 Vmac_command_modifier
= Qmeta
;
12985 DEFVAR_LISP ("mac-function-modifier", &Vmac_function_modifier
,
12986 doc
: /* *Modifier key assumed when the Mac function key is pressed.
12987 The value can be `control', `meta', `alt', `hyper', or `super' for the
12988 respective modifier. Note that remapping the function key may lead to
12989 unexpected results for some keys on non-US/GB keyboards. */);
12990 Vmac_function_modifier
= Qnil
;
12992 DEFVAR_LISP ("mac-emulate-three-button-mouse",
12993 &Vmac_emulate_three_button_mouse
,
12994 doc
: /* *Specify a way of three button mouse emulation.
12995 The value can be nil, t, or the symbol `reverse'.
12996 A value of nil means that no emulation should be done and the modifiers
12997 should be placed on the mouse-1 event.
12998 t means that when the option-key is held down while pressing the mouse
12999 button, the click will register as mouse-2 and while the command-key
13000 is held down, the click will register as mouse-3.
13001 The symbol `reverse' means that the option-key will register for
13002 mouse-3 and the command-key will register for mouse-2. */);
13003 Vmac_emulate_three_button_mouse
= Qnil
;
13005 #if TARGET_API_MAC_CARBON
13006 DEFVAR_BOOL ("mac-wheel-button-is-mouse-2", &mac_wheel_button_is_mouse_2
,
13007 doc
: /* *Non-nil if the wheel button is mouse-2 and the right click mouse-3.
13008 Otherwise, the right click will be treated as mouse-2 and the wheel
13009 button will be mouse-3. */);
13010 mac_wheel_button_is_mouse_2
= 1;
13012 DEFVAR_BOOL ("mac-pass-command-to-system", &mac_pass_command_to_system
,
13013 doc
: /* *Non-nil if command key presses are passed on to the Mac Toolbox. */);
13014 mac_pass_command_to_system
= 1;
13016 DEFVAR_BOOL ("mac-pass-control-to-system", &mac_pass_control_to_system
,
13017 doc
: /* *Non-nil if control key presses are passed on to the Mac Toolbox. */);
13018 mac_pass_control_to_system
= 1;
13022 DEFVAR_BOOL ("mac-allow-anti-aliasing", &mac_use_core_graphics
,
13023 doc
: /* *If non-nil, allow anti-aliasing.
13024 The text will be rendered using Core Graphics text rendering which
13025 may anti-alias the text. */);
13027 mac_use_core_graphics
= 1;
13029 mac_use_core_graphics
= 0;
13032 /* Register an entry for `mac-roman' so that it can be used when
13033 creating the terminal frame on Mac OS 9 before loading
13034 term/mac-win.elc. */
13035 DEFVAR_LISP ("mac-charset-info-alist", &Vmac_charset_info_alist
,
13036 doc
: /* Alist of Emacs character sets vs text encodings and coding systems.
13037 Each entry should be of the form:
13039 (CHARSET-NAME TEXT-ENCODING CODING-SYSTEM)
13041 where CHARSET-NAME is a string used in font names to identify the
13042 charset, TEXT-ENCODING is a TextEncodingBase value in Mac, and
13043 CODING_SYSTEM is a coding system corresponding to TEXT-ENCODING. */);
13044 Vmac_charset_info_alist
=
13045 Fcons (list3 (build_string ("mac-roman"),
13046 make_number (smRoman
), Qnil
), Qnil
);
13049 DEFVAR_LISP ("mac-ts-active-input-overlay", &Vmac_ts_active_input_overlay
,
13050 doc
: /* Overlay used to display Mac TSM active input area. */);
13051 Vmac_ts_active_input_overlay
= Qnil
;
13053 DEFVAR_LISP ("mac-ts-script-language-on-focus", &Vmac_ts_script_language_on_focus
,
13054 doc
: /* *How to change Mac TSM script/language when a frame gets focus.
13055 If the value is t, the input script and language are restored to those
13056 used in the last focus frame. If the value is a pair of integers, the
13057 input script and language codes, which are defined in the Script
13058 Manager, are set to its car and cdr parts, respectively. Otherwise,
13059 Emacs doesn't set them and thus follows the system default behavior. */);
13060 Vmac_ts_script_language_on_focus
= Qnil
;
13064 /* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b
13065 (do not change this comment) */