1 /* Implementation of GUI terminal on the Mac OS.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004,
3 2005, 2006 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* Contributed by Andrew Choi (akochoi@mac.com). */
30 #include "blockinput.h"
38 #if TARGET_API_MAC_CARBON
39 /* USE_CARBON_EVENTS determines if the Carbon Event Manager is used to
40 obtain events from the event queue. If set to 0, WaitNextEvent is
42 #define USE_CARBON_EVENTS 1
43 #else /* not TARGET_API_MAC_CARBON */
44 #include <Quickdraw.h>
45 #include <ToolUtils.h>
49 #include <Resources.h>
51 #include <TextUtils.h>
55 #if defined (__MRC__) || (__MSL__ >= 0x6000)
56 #include <ControlDefinitions.h>
62 #endif /* not TARGET_API_MAC_CARBON */
75 #include "dispextern.h"
77 #include "termhooks.h"
84 #include "intervals.h"
90 /* Non-nil means Emacs uses toolkit scroll bars. */
92 Lisp_Object Vx_toolkit_scroll_bars
;
94 /* If non-zero, the text will be rendered using Core Graphics text
95 rendering which may anti-alias the text. */
96 int mac_use_core_graphics
;
99 /* Non-zero means that a HELP_EVENT has been generated since Emacs
102 static int any_help_event_p
;
104 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
105 static Lisp_Object last_window
;
107 /* Non-zero means make use of UNDERLINE_POSITION font properties.
108 (Not yet supported.) */
109 int x_use_underline_position_properties
;
111 /* This is a chain of structures for all the X displays currently in
114 struct x_display_info
*x_display_list
;
116 /* This is a list of cons cells, each of the form (NAME
117 FONT-LIST-CACHE . RESOURCE-DATABASE), one for each element of
118 x_display_list and in the same order. NAME is the name of the
119 frame. FONT-LIST-CACHE records previous values returned by
120 x-list-fonts. RESOURCE-DATABASE preserves the X Resource Database
121 equivalent, which is implemented with a Lisp object, for the
124 Lisp_Object x_display_name_list
;
126 /* This is display since Mac does not support multiple ones. */
127 struct mac_display_info one_mac_display_info
;
129 /* Frame being updated by update_frame. This is declared in term.c.
130 This is set by update_begin and looked at by all the XT functions.
131 It is zero while not inside an update. In that case, the XT
132 functions assume that `selected_frame' is the frame to apply to. */
134 extern struct frame
*updating_frame
;
136 /* This is a frame waiting to be auto-raised, within XTread_socket. */
138 struct frame
*pending_autoraise_frame
;
142 Formerly, we used PointerMotionHintMask (in standard_event_mask)
143 so that we would have to call XQueryPointer after each MotionNotify
144 event to ask for another such event. However, this made mouse tracking
145 slow, and there was a bug that made it eventually stop.
147 Simply asking for MotionNotify all the time seems to work better.
149 In order to avoid asking for motion events and then throwing most
150 of them away or busy-polling the server for mouse positions, we ask
151 the server for pointer motion hints. This means that we get only
152 one event per group of mouse movements. "Groups" are delimited by
153 other kinds of events (focus changes and button clicks, for
154 example), or by XQueryPointer calls; when one of these happens, we
155 get another MotionNotify event the next time the mouse moves. This
156 is at least as efficient as getting motion events when mouse
157 tracking is on, and I suspect only negligibly worse when tracking
160 /* Where the mouse was last time we reported a mouse event. */
162 static Rect last_mouse_glyph
;
163 static FRAME_PTR last_mouse_glyph_frame
;
165 /* The scroll bar in which the last X motion event occurred.
167 If the last X motion event occurred in a scroll bar, we set this so
168 XTmouse_position can know whether to report a scroll bar motion or
171 If the last X motion event didn't occur in a scroll bar, we set
172 this to Qnil, to tell XTmouse_position to return an ordinary motion
175 static Lisp_Object last_mouse_scroll_bar
;
177 /* This is a hack. We would really prefer that XTmouse_position would
178 return the time associated with the position it returns, but there
179 doesn't seem to be any way to wrest the time-stamp from the server
180 along with the position query. So, we just keep track of the time
181 of the last movement we received, and return that in hopes that
182 it's somewhat accurate. */
184 static Time last_mouse_movement_time
;
186 struct scroll_bar
*tracked_scroll_bar
= NULL
;
188 /* Incremented by XTread_socket whenever it really tries to read
192 static int volatile input_signal_count
;
194 static int input_signal_count
;
197 extern Lisp_Object Vsystem_name
;
199 /* A mask of extra modifier bits to put into every keyboard char. */
201 extern EMACS_INT extra_keyboard_modifiers
;
203 /* The keysyms to use for the various modifiers. */
205 static Lisp_Object Qalt
, Qhyper
, Qsuper
, Qcontrol
, Qmeta
, Qmodifier_value
;
207 extern int inhibit_window_system
;
209 #if __MRC__ && !TARGET_API_MAC_CARBON
210 QDGlobals qd
; /* QuickDraw global information structure. */
213 #define mac_window_to_frame(wp) (((mac_output *) GetWRefCon (wp))->mFP)
215 struct mac_display_info
*mac_display_info_for_display (Display
*);
216 static void x_update_window_end
P_ ((struct window
*, int, int));
217 int x_catch_errors
P_ ((Display
*));
218 void x_uncatch_errors
P_ ((Display
*, int));
219 void x_lower_frame
P_ ((struct frame
*));
220 void x_scroll_bar_clear
P_ ((struct frame
*));
221 int x_had_errors_p
P_ ((Display
*));
222 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
223 void x_raise_frame
P_ ((struct frame
*));
224 void x_set_window_size
P_ ((struct frame
*, int, int, int));
225 void x_wm_set_window_state
P_ ((struct frame
*, int));
226 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
227 void mac_initialize
P_ ((void));
228 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
229 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
230 static void x_update_end
P_ ((struct frame
*));
231 static void XTframe_up_to_date
P_ ((struct frame
*));
232 static void XTset_terminal_modes
P_ ((void));
233 static void XTreset_terminal_modes
P_ ((void));
234 static void x_clear_frame
P_ ((void));
235 static void frame_highlight
P_ ((struct frame
*));
236 static void frame_unhighlight
P_ ((struct frame
*));
237 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
238 static void mac_focus_changed
P_ ((int, struct mac_display_info
*,
239 struct frame
*, struct input_event
*));
240 static void x_detect_focus_change
P_ ((struct mac_display_info
*,
241 EventRecord
*, struct input_event
*));
242 static void XTframe_rehighlight
P_ ((struct frame
*));
243 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
244 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
245 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
246 enum text_cursor_kinds
));
248 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*, int, GC
));
249 static void x_flush
P_ ((struct frame
*f
));
250 static void x_update_begin
P_ ((struct frame
*));
251 static void x_update_window_begin
P_ ((struct window
*));
252 static void x_after_update_window_line
P_ ((struct glyph_row
*));
253 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
254 enum scroll_bar_part
*,
255 Lisp_Object
*, Lisp_Object
*,
258 static int is_emacs_window
P_ ((WindowPtr
));
259 static XCharStruct
*mac_per_char_metric
P_ ((XFontStruct
*, XChar2b
*, int));
260 static void XSetFont
P_ ((Display
*, GC
, XFontStruct
*));
262 /* Defined in macmenu.h. */
263 extern void menubar_selection_callback (FRAME_PTR
, int);
265 #define GC_FORE_COLOR(gc) (&(gc)->fore_color)
266 #define GC_BACK_COLOR(gc) (&(gc)->back_color)
267 #define GC_FONT(gc) ((gc)->xgcv.font)
268 #define FRAME_NORMAL_GC(f) ((f)->output_data.mac->normal_gc)
269 #define CG_SET_FILL_COLOR(context, color) \
270 CGContextSetRGBFillColor (context, \
271 RED_FROM_ULONG (color) / 255.0f, \
272 GREEN_FROM_ULONG (color) / 255.0f, \
273 BLUE_FROM_ULONG (color) / 255.0f, 1.0f)
274 #define CG_SET_STROKE_COLOR(context, color) \
275 CGContextSetRGBStrokeColor (context, \
276 RED_FROM_ULONG (color) / 255.0f, \
277 GREEN_FROM_ULONG (color) / 255.0f, \
278 BLUE_FROM_ULONG (color) / 255.0f, 1.0f)
280 #define FRAME_CG_CONTEXT(f) ((f)->output_data.mac->cg_context)
282 /* Fringe bitmaps. */
284 static int max_fringe_bmp
= 0;
285 static CGImageRef
*fringe_bmp
= 0;
288 mac_begin_cg_clip (f
, gc
)
292 CGContextRef context
= FRAME_CG_CONTEXT (f
);
296 QDBeginCGContext (GetWindowPort (FRAME_MAC_WINDOW (f
)), &context
);
297 FRAME_CG_CONTEXT (f
) = context
;
300 CGContextSaveGState (context
);
301 CGContextTranslateCTM (context
, 0, FRAME_PIXEL_HEIGHT (f
));
302 CGContextScaleCTM (context
, 1, -1);
303 if (gc
&& gc
->n_clip_rects
)
304 CGContextClipToRects (context
, gc
->clip_rects
, gc
->n_clip_rects
);
313 CGContextRestoreGState (FRAME_CG_CONTEXT (f
));
317 mac_prepare_for_quickdraw (f
)
322 Lisp_Object rest
, frame
;
323 FOR_EACH_FRAME (rest
, frame
)
324 if (FRAME_MAC_P (XFRAME (frame
)))
325 mac_prepare_for_quickdraw (XFRAME (frame
));
329 CGContextRef context
= FRAME_CG_CONTEXT (f
);
333 CGContextSynchronize (context
);
334 QDEndCGContext (GetWindowPort (FRAME_MAC_WINDOW (f
)),
335 &FRAME_CG_CONTEXT (f
));
341 static RgnHandle saved_port_clip_region
= NULL
;
347 static RgnHandle new_region
= NULL
;
349 if (saved_port_clip_region
== NULL
)
350 saved_port_clip_region
= NewRgn ();
351 if (new_region
== NULL
)
352 new_region
= NewRgn ();
354 if (gc
->n_clip_rects
)
356 GetClip (saved_port_clip_region
);
357 SectRgn (saved_port_clip_region
, gc
->clip_region
, new_region
);
358 SetClip (new_region
);
366 if (gc
->n_clip_rects
)
367 SetClip (saved_port_clip_region
);
371 /* X display function emulation */
374 XFreePixmap (display
, pixmap
)
375 Display
*display
; /* not used */
378 DisposeGWorld (pixmap
);
382 /* Mac version of XDrawLine. */
385 mac_draw_line (f
, gc
, x1
, y1
, x2
, y2
)
391 CGContextRef context
;
392 float gx1
= x1
, gy1
= y1
, gx2
= x2
, gy2
= y2
;
395 gx1
+= 0.5f
, gx2
+= 0.5f
;
397 gy1
+= 0.5f
, gy2
+= 0.5f
;
399 context
= mac_begin_cg_clip (f
, gc
);
400 CG_SET_STROKE_COLOR (context
, gc
->xgcv
.foreground
);
401 CGContextBeginPath (context
);
402 CGContextMoveToPoint (context
, gx1
, gy1
);
403 CGContextAddLineToPoint (context
, gx2
, gy2
);
404 CGContextClosePath (context
);
405 CGContextStrokePath (context
);
423 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
425 RGBForeColor (GC_FORE_COLOR (gc
));
435 mac_draw_line_to_pixmap (display
, p
, gc
, x1
, y1
, x2
, y2
)
459 GetGWorld (&old_port
, &old_gdh
);
462 RGBForeColor (GC_FORE_COLOR (gc
));
464 LockPixels (GetGWorldPixMap (p
));
467 UnlockPixels (GetGWorldPixMap (p
));
469 SetGWorld (old_port
, old_gdh
);
474 mac_erase_rectangle (f
, gc
, x
, y
, width
, height
)
478 unsigned int width
, height
;
481 CGContextRef context
;
483 context
= mac_begin_cg_clip (f
, gc
);
484 CG_SET_FILL_COLOR (context
, gc
->xgcv
.background
);
485 CGContextFillRect (context
, CGRectMake (x
, y
, width
, height
));
490 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
492 RGBBackColor (GC_BACK_COLOR (gc
));
493 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
499 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
504 /* Mac version of XClearArea. */
507 mac_clear_area (f
, x
, y
, width
, height
)
510 unsigned int width
, height
;
512 mac_erase_rectangle (f
, FRAME_NORMAL_GC (f
), x
, y
, width
, height
);
515 /* Mac version of XClearWindow. */
522 CGContextRef context
;
523 GC gc
= FRAME_NORMAL_GC (f
);
525 context
= mac_begin_cg_clip (f
, NULL
);
526 CG_SET_FILL_COLOR (context
, gc
->xgcv
.background
);
527 CGContextFillRect (context
, CGRectMake (0, 0, FRAME_PIXEL_WIDTH (f
),
528 FRAME_PIXEL_HEIGHT (f
)));
531 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
533 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
535 #if TARGET_API_MAC_CARBON
539 GetWindowPortBounds (FRAME_MAC_WINDOW (f
), &r
);
542 #else /* not TARGET_API_MAC_CARBON */
543 EraseRect (&(FRAME_MAC_WINDOW (f
)->portRect
));
544 #endif /* not TARGET_API_MAC_CARBON */
549 /* Mac replacement for XCopyArea. */
553 mac_draw_cg_image (image
, f
, gc
, src_x
, src_y
, width
, height
,
554 dest_x
, dest_y
, overlay_p
)
559 unsigned int width
, height
;
560 int dest_x
, dest_y
, overlay_p
;
562 CGContextRef context
;
563 float port_height
= FRAME_PIXEL_HEIGHT (f
);
564 CGRect dest_rect
= CGRectMake (dest_x
, dest_y
, width
, height
);
566 context
= mac_begin_cg_clip (f
, gc
);
569 CG_SET_FILL_COLOR (context
, gc
->xgcv
.background
);
570 CGContextFillRect (context
, dest_rect
);
572 CGContextClipToRect (context
, dest_rect
);
573 CGContextScaleCTM (context
, 1, -1);
574 CGContextTranslateCTM (context
, 0, -port_height
);
575 if (CGImageIsMask (image
))
576 CG_SET_FILL_COLOR (context
, gc
->xgcv
.foreground
);
577 CGContextDrawImage (context
,
578 CGRectMake (dest_x
- src_x
,
579 port_height
- (dest_y
- src_y
580 + CGImageGetHeight (image
)),
581 CGImageGetWidth (image
),
582 CGImageGetHeight (image
)),
587 #else /* !USE_CG_DRAWING */
590 mac_draw_bitmap (f
, gc
, x
, y
, width
, height
, bits
, overlay_p
)
593 int x
, y
, width
, height
;
594 unsigned short *bits
;
600 bitmap
.rowBytes
= sizeof(unsigned short);
601 bitmap
.baseAddr
= (char *)bits
;
602 SetRect (&(bitmap
.bounds
), 0, 0, width
, height
);
604 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
606 RGBForeColor (GC_FORE_COLOR (gc
));
607 RGBBackColor (GC_BACK_COLOR (gc
));
608 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
611 #if TARGET_API_MAC_CARBON
617 CopyBits (&bitmap
, GetPortBitMapForCopyBits (port
),
618 &(bitmap
.bounds
), &r
, overlay_p
? srcOr
: srcCopy
, 0);
619 UnlockPortBits (port
);
621 #else /* not TARGET_API_MAC_CARBON */
622 CopyBits (&bitmap
, &(FRAME_MAC_WINDOW (f
)->portBits
), &(bitmap
.bounds
), &r
,
623 overlay_p
? srcOr
: srcCopy
, 0);
624 #endif /* not TARGET_API_MAC_CARBON */
627 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
629 #endif /* !USE_CG_DRAWING */
632 /* Mac replacement for XCreateBitmapFromBitmapData. */
635 mac_create_bitmap_from_bitmap_data (bitmap
, bits
, w
, h
)
640 static unsigned char swap_nibble
[16]
641 = { 0x0, 0x8, 0x4, 0xc, /* 0000 1000 0100 1100 */
642 0x2, 0xa, 0x6, 0xe, /* 0010 1010 0110 1110 */
643 0x1, 0x9, 0x5, 0xd, /* 0001 1001 0101 1101 */
644 0x3, 0xb, 0x7, 0xf }; /* 0011 1011 0111 1111 */
648 w1
= (w
+ 7) / 8; /* nb of 8bits elt in X bitmap */
649 bitmap
->rowBytes
= ((w
+ 15) / 16) * 2; /* nb of 16bits elt in Mac bitmap */
650 bitmap
->baseAddr
= xmalloc (bitmap
->rowBytes
* h
);
651 bzero (bitmap
->baseAddr
, bitmap
->rowBytes
* h
);
652 for (i
= 0; i
< h
; i
++)
654 p
= bitmap
->baseAddr
+ i
* bitmap
->rowBytes
;
655 for (j
= 0; j
< w1
; j
++)
657 /* Bitswap XBM bytes to match how Mac does things. */
658 unsigned char c
= *bits
++;
659 *p
++ = (unsigned char)((swap_nibble
[c
& 0xf] << 4)
660 | (swap_nibble
[(c
>>4) & 0xf]));;
664 SetRect (&(bitmap
->bounds
), 0, 0, w
, h
);
669 mac_free_bitmap (bitmap
)
672 xfree (bitmap
->baseAddr
);
677 XCreatePixmap (display
, w
, width
, height
, depth
)
678 Display
*display
; /* not used */
680 unsigned int width
, height
;
687 SetPortWindowPort (w
);
689 SetRect (&r
, 0, 0, width
, height
);
690 #if !defined (WORDS_BIG_ENDIAN) && USE_CG_DRAWING
693 err
= NewGWorld (&pixmap
, depth
, &r
, NULL
, NULL
, 0);
694 #if !defined (WORDS_BIG_ENDIAN) && USE_CG_DRAWING
696 /* CreateCGImageFromPixMaps requires ARGB format. */
697 err
= QTNewGWorld (&pixmap
, k32ARGBPixelFormat
, &r
, NULL
, NULL
, 0);
706 XCreatePixmapFromBitmapData (display
, w
, data
, width
, height
, fg
, bg
, depth
)
707 Display
*display
; /* not used */
710 unsigned int width
, height
;
711 unsigned long fg
, bg
;
718 static GC gc
= NULL
; /* not reentrant */
721 gc
= XCreateGC (display
, w
, 0, NULL
);
723 pixmap
= XCreatePixmap (display
, w
, width
, height
, depth
);
727 GetGWorld (&old_port
, &old_gdh
);
728 SetGWorld (pixmap
, NULL
);
729 mac_create_bitmap_from_bitmap_data (&bitmap
, data
, width
, height
);
730 XSetForeground (display
, gc
, fg
);
731 XSetBackground (display
, gc
, bg
);
732 RGBForeColor (GC_FORE_COLOR (gc
));
733 RGBBackColor (GC_BACK_COLOR (gc
));
734 LockPixels (GetGWorldPixMap (pixmap
));
735 #if TARGET_API_MAC_CARBON
736 CopyBits (&bitmap
, GetPortBitMapForCopyBits (pixmap
),
737 &bitmap
.bounds
, &bitmap
.bounds
, srcCopy
, 0);
738 #else /* not TARGET_API_MAC_CARBON */
739 CopyBits (&bitmap
, &(((GrafPtr
)pixmap
)->portBits
),
740 &bitmap
.bounds
, &bitmap
.bounds
, srcCopy
, 0);
741 #endif /* not TARGET_API_MAC_CARBON */
742 UnlockPixels (GetGWorldPixMap (pixmap
));
743 SetGWorld (old_port
, old_gdh
);
744 mac_free_bitmap (&bitmap
);
750 /* Mac replacement for XFillRectangle. */
753 mac_fill_rectangle (f
, gc
, x
, y
, width
, height
)
757 unsigned int width
, height
;
760 CGContextRef context
;
762 context
= mac_begin_cg_clip (f
, gc
);
763 CG_SET_FILL_COLOR (context
, gc
->xgcv
.foreground
);
764 CGContextFillRect (context
, CGRectMake (x
, y
, width
, height
));
769 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
771 RGBForeColor (GC_FORE_COLOR (gc
));
772 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
775 PaintRect (&r
); /* using foreground color of gc */
781 /* Mac replacement for XDrawRectangle: dest is a window. */
784 mac_draw_rectangle (f
, gc
, x
, y
, width
, height
)
788 unsigned int width
, height
;
791 CGContextRef context
;
793 context
= mac_begin_cg_clip (f
, gc
);
794 CG_SET_STROKE_COLOR (context
, gc
->xgcv
.foreground
);
795 CGContextStrokeRect (context
,
796 CGRectMake (x
+ 0.5f
, y
+ 0.5f
, width
, height
));
801 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
803 RGBForeColor (GC_FORE_COLOR (gc
));
804 SetRect (&r
, x
, y
, x
+ width
+ 1, y
+ height
+ 1);
807 FrameRect (&r
); /* using foreground color of gc */
815 atsu_get_text_layout_with_text_ptr (text
, text_length
, style
, text_layout
)
816 ConstUniCharArrayPtr text
;
817 UniCharCount text_length
;
819 ATSUTextLayout
*text_layout
;
822 static ATSUTextLayout saved_text_layout
= NULL
; /* not reentrant */
824 if (saved_text_layout
== NULL
)
826 UniCharCount lengths
[] = {kATSUToTextEnd
};
827 ATSUAttributeTag tags
[] = {kATSULineLayoutOptionsTag
};
828 ByteCount sizes
[] = {sizeof (ATSLineLayoutOptions
)};
829 static ATSLineLayoutOptions line_layout
=
830 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
831 kATSLineDisableAllLayoutOperations
| kATSLineUseDeviceMetrics
832 | kATSLineUseQDRendering
834 kATSLineIsDisplayOnly
| kATSLineFractDisable
837 ATSUAttributeValuePtr values
[] = {&line_layout
};
839 err
= ATSUCreateTextLayoutWithTextPtr (text
,
840 kATSUFromTextBeginning
,
846 err
= ATSUSetLayoutControls (saved_text_layout
,
847 sizeof (tags
) / sizeof (tags
[0]),
848 tags
, sizes
, values
);
849 /* XXX: Should we do this? */
851 err
= ATSUSetTransientFontMatching (saved_text_layout
, true);
855 err
= ATSUSetRunStyle (saved_text_layout
, style
,
856 kATSUFromTextBeginning
, kATSUToTextEnd
);
858 err
= ATSUSetTextPointerLocation (saved_text_layout
, text
,
859 kATSUFromTextBeginning
,
865 *text_layout
= saved_text_layout
;
872 mac_invert_rectangle (f
, x
, y
, width
, height
)
875 unsigned int width
, height
;
880 mac_prepare_for_quickdraw (f
);
882 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
884 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
891 mac_draw_string_common (f
, gc
, x
, y
, buf
, nchars
, bg_width
, bytes_per_char
)
896 int nchars
, bg_width
, bytes_per_char
;
898 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
901 if (GC_FONT (gc
)->mac_style
)
904 ATSUTextLayout text_layout
;
906 xassert (bytes_per_char
== 2);
908 #ifndef WORDS_BIG_ENDIAN
911 UniChar
*text
= (UniChar
*)buf
;
913 for (i
= 0; i
< nchars
; i
++)
914 text
[i
] = EndianU16_BtoN (text
[i
]);
917 err
= atsu_get_text_layout_with_text_ptr ((ConstUniCharArrayPtr
)buf
,
919 GC_FONT (gc
)->mac_style
,
924 if (!mac_use_core_graphics
)
928 mac_prepare_for_quickdraw (f
);
931 RGBForeColor (GC_FORE_COLOR (gc
));
936 SetRect (&r
, x
, y
- FONT_BASE (GC_FONT (gc
)),
937 x
+ bg_width
, y
+ FONT_DESCENT (GC_FONT (gc
)));
938 RGBBackColor (GC_BACK_COLOR (gc
));
940 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
943 ATSUDrawText (text_layout
,
944 kATSUFromTextBeginning
, kATSUToTextEnd
,
945 kATSUUseGrafPortPenLoc
, kATSUUseGrafPortPenLoc
);
952 CGContextRef context
;
953 float port_height
= FRAME_PIXEL_HEIGHT (f
);
954 ATSUAttributeTag tags
[] = {kATSUCGContextTag
};
955 ByteCount sizes
[] = {sizeof (CGContextRef
)};
956 ATSUAttributeValuePtr values
[] = {&context
};
959 context
= mac_begin_cg_clip (f
, gc
);
962 QDBeginCGContext (port
, &context
);
963 if (gc
->n_clip_rects
|| bg_width
)
965 CGContextTranslateCTM (context
, 0, port_height
);
966 CGContextScaleCTM (context
, 1, -1);
967 if (gc
->n_clip_rects
)
968 CGContextClipToRects (context
, gc
->clip_rects
,
973 CG_SET_FILL_COLOR (context
, gc
->xgcv
.background
);
976 CGRectMake (x
, y
- FONT_BASE (GC_FONT (gc
)),
977 bg_width
, FONT_HEIGHT (GC_FONT (gc
))));
979 CGContextScaleCTM (context
, 1, -1);
980 CGContextTranslateCTM (context
, 0, -port_height
);
984 CG_SET_FILL_COLOR (context
, gc
->xgcv
.foreground
);
985 err
= ATSUSetLayoutControls (text_layout
,
986 sizeof (tags
) / sizeof (tags
[0]),
987 tags
, sizes
, values
);
989 ATSUDrawText (text_layout
,
990 kATSUFromTextBeginning
, kATSUToTextEnd
,
991 Long2Fix (x
), Long2Fix (port_height
- y
));
996 CGContextSynchronize (context
);
997 QDEndCGContext (port
, &context
);
1000 /* This doesn't work on Mac OS X 10.1. */
1001 ATSUClearLayoutControls (text_layout
,
1002 sizeof (tags
) / sizeof (tags
[0]), tags
);
1004 ATSUSetLayoutControls (text_layout
,
1005 sizeof (tags
) / sizeof (tags
[0]),
1006 tags
, sizes
, values
);
1009 #endif /* MAC_OSX */
1012 #endif /* USE_ATSUI */
1014 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1017 if (mac_use_core_graphics
)
1018 savedFlags
= SwapQDTextFlags (kQDUseCGTextRendering
);
1021 mac_prepare_for_quickdraw (f
);
1023 mac_begin_clip (gc
);
1024 RGBForeColor (GC_FORE_COLOR (gc
));
1028 RGBBackColor (GC_BACK_COLOR (gc
));
1034 /* We prefer not to use srcCopy text transfer mode on Mac OS X
1036 - Screen is double-buffered. (In srcCopy mode, a text is
1037 drawn into an offscreen graphics world first. So
1038 performance gain cannot be expected.)
1039 - It lowers rendering quality.
1040 - Some fonts leave garbage on cursor movement. */
1045 RGBBackColor (GC_BACK_COLOR (gc
));
1046 SetRect (&r
, x
, y
- FONT_BASE (GC_FONT (gc
)),
1047 x
+ bg_width
, y
+ FONT_DESCENT (GC_FONT (gc
)));
1052 TextFont (GC_FONT (gc
)->mac_fontnum
);
1053 TextSize (GC_FONT (gc
)->mac_fontsize
);
1054 TextFace (GC_FONT (gc
)->mac_fontface
);
1056 DrawText (buf
, 0, nchars
* bytes_per_char
);
1058 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1061 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1062 if (mac_use_core_graphics
)
1063 SwapQDTextFlags(savedFlags
);
1069 /* Mac replacement for XDrawString. */
1072 mac_draw_string (f
, gc
, x
, y
, buf
, nchars
)
1079 mac_draw_string_common (f
, gc
, x
, y
, buf
, nchars
, 0, 1);
1083 /* Mac replacement for XDrawString16. */
1086 mac_draw_string_16 (f
, gc
, x
, y
, buf
, nchars
)
1093 mac_draw_string_common (f
, gc
, x
, y
, (char *) buf
, nchars
, 0, 2);
1097 /* Mac replacement for XDrawImageString. */
1100 mac_draw_image_string (f
, gc
, x
, y
, buf
, nchars
, bg_width
)
1105 int nchars
, bg_width
;
1107 mac_draw_string_common (f
, gc
, x
, y
, buf
, nchars
, bg_width
, 1);
1111 /* Mac replacement for XDrawString16. */
1114 mac_draw_image_string_16 (f
, gc
, x
, y
, buf
, nchars
, bg_width
)
1119 int nchars
, bg_width
;
1121 mac_draw_string_common (f
, gc
, x
, y
, (char *) buf
, nchars
, bg_width
, 2);
1125 /* Mac replacement for XQueryTextExtents, but takes a character. If
1126 STYLE is NULL, measurement is done by QuickDraw Text routines for
1127 the font of the current graphics port. If CG_GLYPH is not NULL,
1128 *CG_GLYPH is set to the glyph ID or 0 if it cannot be obtained. */
1131 mac_query_char_extents (style
, c
,
1132 font_ascent_return
, font_descent_return
,
1133 overall_return
, cg_glyph
)
1140 int *font_ascent_return
, *font_descent_return
;
1141 XCharStruct
*overall_return
;
1142 #if USE_CG_TEXT_DRAWING
1155 ATSUTextLayout text_layout
;
1158 err
= atsu_get_text_layout_with_text_ptr (&ch
, 1, style
, &text_layout
);
1161 ATSTrapezoid glyph_bounds
;
1163 err
= ATSUGetGlyphBounds (text_layout
, 0, 0,
1164 kATSUFromTextBeginning
, kATSUToTextEnd
,
1165 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1166 kATSUseFractionalOrigins
,
1168 kATSUseDeviceOrigins
,
1170 1, &glyph_bounds
, NULL
);
1173 xassert (glyph_bounds
.lowerRight
.x
- glyph_bounds
.lowerLeft
.x
1174 == glyph_bounds
.upperRight
.x
- glyph_bounds
.upperLeft
.x
);
1176 width
= Fix2Long (glyph_bounds
.upperRight
.x
1177 - glyph_bounds
.upperLeft
.x
);
1178 if (font_ascent_return
)
1179 *font_ascent_return
= -Fix2Long (glyph_bounds
.upperLeft
.y
);
1180 if (font_descent_return
)
1181 *font_descent_return
= Fix2Long (glyph_bounds
.lowerLeft
.y
);
1184 if (err
== noErr
&& overall_return
)
1186 err
= ATSUMeasureTextImage (text_layout
,
1187 kATSUFromTextBeginning
, kATSUToTextEnd
,
1188 0, 0, &char_bounds
);
1190 STORE_XCHARSTRUCT (*overall_return
, width
, char_bounds
);
1191 #if USE_CG_TEXT_DRAWING
1192 if (err
== noErr
&& cg_glyph
)
1195 ATSUGlyphInfoArray glyph_info_array
;
1196 ByteCount count
= sizeof (ATSUGlyphInfoArray
);
1198 err1
= ATSUMatchFontsToText (text_layout
, kATSUFromTextBeginning
,
1199 kATSUToTextEnd
, NULL
, NULL
, NULL
);
1201 err1
= ATSUGetGlyphInfo (text_layout
, kATSUFromTextBeginning
,
1202 kATSUToTextEnd
, &count
,
1206 xassert (glyph_info_array
.glyphs
[0].glyphID
);
1207 *cg_glyph
= glyph_info_array
.glyphs
[0].glyphID
;
1218 if (font_ascent_return
|| font_descent_return
)
1222 GetFontInfo (&font_info
);
1223 if (font_ascent_return
)
1224 *font_ascent_return
= font_info
.ascent
;
1225 if (font_descent_return
)
1226 *font_descent_return
= font_info
.descent
;
1232 width
= CharWidth (ch
);
1233 QDTextBounds (1, &ch
, &char_bounds
);
1234 STORE_XCHARSTRUCT (*overall_return
, width
, char_bounds
);
1242 /* Mac replacement for XTextExtents16. Only sets horizontal metrics. */
1245 mac_text_extents_16 (font_struct
, string
, nchars
, overall_return
)
1246 XFontStruct
*font_struct
;
1249 XCharStruct
*overall_return
;
1252 short width
= 0, lbearing
= 0, rbearing
= 0;
1255 for (i
= 0; i
< nchars
; i
++)
1257 pcm
= mac_per_char_metric (font_struct
, string
, 0);
1259 width
+= FONT_WIDTH (font_struct
);
1262 lbearing
= min (lbearing
, width
+ pcm
->lbearing
);
1263 rbearing
= max (rbearing
, width
+ pcm
->rbearing
);
1264 width
+= pcm
->width
;
1269 overall_return
->lbearing
= lbearing
;
1270 overall_return
->rbearing
= rbearing
;
1271 overall_return
->width
= width
;
1273 /* What's the meaning of the return value of XTextExtents16? */
1277 #if USE_CG_TEXT_DRAWING
1278 static int cg_text_anti_aliasing_threshold
= 8;
1281 init_cg_text_anti_aliasing_threshold ()
1287 CFPreferencesGetAppIntegerValue (CFSTR ("AppleAntiAliasingThreshold"),
1288 kCFPreferencesCurrentApplication
,
1291 cg_text_anti_aliasing_threshold
= threshold
;
1295 mac_draw_image_string_cg (f
, gc
, x
, y
, buf
, nchars
, bg_width
)
1300 int nchars
, bg_width
;
1303 float port_height
, gx
, gy
;
1305 CGContextRef context
;
1309 if (!mac_use_core_graphics
|| GC_FONT (gc
)->cg_font
== NULL
)
1312 port
= GetWindowPort (FRAME_MAC_WINDOW (f
));
1313 port_height
= FRAME_PIXEL_HEIGHT (f
);
1315 gy
= port_height
- y
;
1316 glyphs
= (CGGlyph
*)buf
;
1317 advances
= alloca (sizeof (CGSize
) * nchars
);
1318 if (advances
== NULL
)
1320 for (i
= 0; i
< nchars
; i
++)
1322 XCharStruct
*pcm
= mac_per_char_metric (GC_FONT (gc
), buf
, 0);
1324 advances
[i
].width
= pcm
->width
;
1325 advances
[i
].height
= 0;
1326 glyphs
[i
] = GC_FONT (gc
)->cg_glyphs
[buf
->byte2
];
1331 context
= mac_begin_cg_clip (f
, gc
);
1333 QDBeginCGContext (port
, &context
);
1334 if (gc
->n_clip_rects
|| bg_width
)
1336 CGContextTranslateCTM (context
, 0, port_height
);
1337 CGContextScaleCTM (context
, 1, -1);
1338 if (gc
->n_clip_rects
)
1339 CGContextClipToRects (context
, gc
->clip_rects
, gc
->n_clip_rects
);
1343 CG_SET_FILL_COLOR (context
, gc
->xgcv
.background
);
1346 CGRectMake (gx
, y
- FONT_BASE (GC_FONT (gc
)),
1347 bg_width
, FONT_HEIGHT (GC_FONT (gc
))));
1349 CGContextScaleCTM (context
, 1, -1);
1350 CGContextTranslateCTM (context
, 0, -port_height
);
1354 CG_SET_FILL_COLOR (context
, gc
->xgcv
.foreground
);
1355 CGContextSetFont (context
, GC_FONT (gc
)->cg_font
);
1356 CGContextSetFontSize (context
, GC_FONT (gc
)->mac_fontsize
);
1357 if (GC_FONT (gc
)->mac_fontsize
<= cg_text_anti_aliasing_threshold
)
1358 CGContextSetShouldAntialias (context
, false);
1359 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
1360 CGContextSetTextPosition (context
, gx
, gy
);
1361 CGContextShowGlyphsWithAdvances (context
, glyphs
, advances
, nchars
);
1363 for (i
= 0; i
< nchars
; i
++)
1365 CGContextShowGlyphsAtPoint (context
, gx
, gy
, glyphs
+ i
, 1);
1366 gx
+= advances
[i
].width
;
1370 mac_end_cg_clip (f
);
1372 CGContextSynchronize (context
);
1373 QDEndCGContext (port
, &context
);
1382 /* Mac replacement for XCopyArea: dest must be window. */
1385 mac_copy_area (src
, f
, gc
, src_x
, src_y
, width
, height
, dest_x
, dest_y
)
1390 unsigned int width
, height
;
1395 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
1397 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1398 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1400 ForeColor (blackColor
);
1401 BackColor (whiteColor
);
1403 mac_begin_clip (gc
);
1404 LockPixels (GetGWorldPixMap (src
));
1405 #if TARGET_API_MAC_CARBON
1410 LockPortBits (port
);
1411 CopyBits (GetPortBitMapForCopyBits (src
),
1412 GetPortBitMapForCopyBits (port
),
1413 &src_r
, &dest_r
, srcCopy
, 0);
1414 UnlockPortBits (port
);
1416 #else /* not TARGET_API_MAC_CARBON */
1417 CopyBits (&(((GrafPtr
)src
)->portBits
), &(FRAME_MAC_WINDOW (f
)->portBits
),
1418 &src_r
, &dest_r
, srcCopy
, 0);
1419 #endif /* not TARGET_API_MAC_CARBON */
1420 UnlockPixels (GetGWorldPixMap (src
));
1423 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1428 mac_copy_area_with_mask (src
, mask
, f
, gc
, src_x
, src_y
,
1429 width
, height
, dest_x
, dest_y
)
1434 unsigned int width
, height
;
1439 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
1441 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1442 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1444 ForeColor (blackColor
);
1445 BackColor (whiteColor
);
1447 mac_begin_clip (gc
);
1448 LockPixels (GetGWorldPixMap (src
));
1449 LockPixels (GetGWorldPixMap (mask
));
1450 #if TARGET_API_MAC_CARBON
1455 LockPortBits (port
);
1456 CopyMask (GetPortBitMapForCopyBits (src
), GetPortBitMapForCopyBits (mask
),
1457 GetPortBitMapForCopyBits (port
),
1458 &src_r
, &src_r
, &dest_r
);
1459 UnlockPortBits (port
);
1461 #else /* not TARGET_API_MAC_CARBON */
1462 CopyMask (&(((GrafPtr
)src
)->portBits
), &(((GrafPtr
)mask
)->portBits
),
1463 &(FRAME_MAC_WINDOW (f
)->portBits
), &src_r
, &src_r
, &dest_r
);
1464 #endif /* not TARGET_API_MAC_CARBON */
1465 UnlockPixels (GetGWorldPixMap (mask
));
1466 UnlockPixels (GetGWorldPixMap (src
));
1469 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1471 #endif /* !USE_CG_DRAWING */
1474 /* Mac replacement for XCopyArea: used only for scrolling. */
1477 mac_scroll_area (f
, gc
, src_x
, src_y
, width
, height
, dest_x
, dest_y
)
1481 unsigned int width
, height
;
1484 #if TARGET_API_MAC_CARBON
1486 RgnHandle dummy
= NewRgn (); /* For avoiding update events. */
1488 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1490 mac_prepare_for_quickdraw (f
);
1492 ScrollWindowRect (FRAME_MAC_WINDOW (f
),
1493 &src_r
, dest_x
- src_x
, dest_y
- src_y
,
1494 kScrollWindowNoOptions
, dummy
);
1496 #else /* not TARGET_API_MAC_CARBON */
1498 WindowPtr w
= FRAME_MAC_WINDOW (f
);
1502 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1503 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1505 /* In Color QuickDraw, set ForeColor and BackColor as follows to avoid
1506 color mapping in CopyBits. Otherwise, it will be slow. */
1507 ForeColor (blackColor
);
1508 BackColor (whiteColor
);
1509 mac_begin_clip (gc
);
1510 CopyBits (&(w
->portBits
), &(w
->portBits
), &src_r
, &dest_r
, srcCopy
, 0);
1513 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1514 #endif /* not TARGET_API_MAC_CARBON */
1518 /* Mac replacement for XChangeGC. */
1521 XChangeGC (display
, gc
, mask
, xgcv
)
1527 if (mask
& GCForeground
)
1528 XSetForeground (display
, gc
, xgcv
->foreground
);
1529 if (mask
& GCBackground
)
1530 XSetBackground (display
, gc
, xgcv
->background
);
1532 XSetFont (display
, gc
, xgcv
->font
);
1536 /* Mac replacement for XCreateGC. */
1539 XCreateGC (display
, window
, mask
, xgcv
)
1545 GC gc
= xmalloc (sizeof (*gc
));
1547 bzero (gc
, sizeof (*gc
));
1548 XChangeGC (display
, gc
, mask
, xgcv
);
1554 /* Used in xfaces.c. */
1557 XFreeGC (display
, gc
)
1561 if (gc
->clip_region
)
1562 DisposeRgn (gc
->clip_region
);
1567 /* Mac replacement for XGetGCValues. */
1570 XGetGCValues (display
, gc
, mask
, xgcv
)
1576 if (mask
& GCForeground
)
1577 xgcv
->foreground
= gc
->xgcv
.foreground
;
1578 if (mask
& GCBackground
)
1579 xgcv
->background
= gc
->xgcv
.background
;
1581 xgcv
->font
= gc
->xgcv
.font
;
1585 /* Mac replacement for XSetForeground. */
1588 XSetForeground (display
, gc
, color
)
1591 unsigned long color
;
1593 if (gc
->xgcv
.foreground
!= color
)
1595 gc
->xgcv
.foreground
= color
;
1596 gc
->fore_color
.red
= RED16_FROM_ULONG (color
);
1597 gc
->fore_color
.green
= GREEN16_FROM_ULONG (color
);
1598 gc
->fore_color
.blue
= BLUE16_FROM_ULONG (color
);
1603 /* Mac replacement for XSetBackground. */
1606 XSetBackground (display
, gc
, color
)
1609 unsigned long color
;
1611 if (gc
->xgcv
.background
!= color
)
1613 gc
->xgcv
.background
= color
;
1614 gc
->back_color
.red
= RED16_FROM_ULONG (color
);
1615 gc
->back_color
.green
= GREEN16_FROM_ULONG (color
);
1616 gc
->back_color
.blue
= BLUE16_FROM_ULONG (color
);
1621 /* Mac replacement for XSetFont. */
1624 XSetFont (display
, gc
, font
)
1629 gc
->xgcv
.font
= font
;
1633 /* Mac replacement for XSetClipRectangles. */
1636 mac_set_clip_rectangles (display
, gc
, rectangles
, n
)
1644 xassert (n
>= 0 && n
<= MAX_CLIP_RECTS
);
1646 gc
->n_clip_rects
= n
;
1649 if (gc
->clip_region
== NULL
)
1650 gc
->clip_region
= NewRgn ();
1651 RectRgn (gc
->clip_region
, rectangles
);
1654 RgnHandle region
= NewRgn ();
1656 for (i
= 1; i
< n
; i
++)
1658 RectRgn (region
, rectangles
+ i
);
1659 UnionRgn (gc
->clip_region
, region
, gc
->clip_region
);
1661 DisposeRgn (region
);
1664 #if defined (MAC_OSX) && (USE_ATSUI || USE_CG_DRAWING)
1665 for (i
= 0; i
< n
; i
++)
1667 Rect
*rect
= rectangles
+ i
;
1669 gc
->clip_rects
[i
] = CGRectMake (rect
->left
, rect
->top
,
1670 rect
->right
- rect
->left
,
1671 rect
->bottom
- rect
->top
);
1677 /* Mac replacement for XSetClipMask. */
1680 mac_reset_clip_rectangles (display
, gc
)
1684 gc
->n_clip_rects
= 0;
1688 /* Mac replacement for XSetWindowBackground. */
1691 XSetWindowBackground (display
, w
, color
)
1694 unsigned long color
;
1696 #if !TARGET_API_MAC_CARBON
1697 AuxWinHandle aw_handle
;
1698 CTabHandle ctab_handle
;
1699 ColorSpecPtr ct_table
;
1704 bg_color
.red
= RED16_FROM_ULONG (color
);
1705 bg_color
.green
= GREEN16_FROM_ULONG (color
);
1706 bg_color
.blue
= BLUE16_FROM_ULONG (color
);
1708 #if TARGET_API_MAC_CARBON
1709 SetWindowContentColor (w
, &bg_color
);
1711 if (GetAuxWin (w
, &aw_handle
))
1713 ctab_handle
= (*aw_handle
)->awCTable
;
1714 HandToHand ((Handle
*) &ctab_handle
);
1715 ct_table
= (*ctab_handle
)->ctTable
;
1716 ct_size
= (*ctab_handle
)->ctSize
;
1717 while (ct_size
> -1)
1719 if (ct_table
->value
== 0)
1721 ct_table
->rgb
= bg_color
;
1722 CTabChanged (ctab_handle
);
1723 SetWinColor (w
, (WCTabHandle
) ctab_handle
);
1731 /* Flush display of frame F, or of all frames if F is null. */
1737 #if TARGET_API_MAC_CARBON
1740 mac_prepare_for_quickdraw (f
);
1743 QDFlushPortBuffer (GetWindowPort (FRAME_MAC_WINDOW (f
)), NULL
);
1745 QDFlushPortBuffer (GetQDGlobalsThePort (), NULL
);
1751 /* Remove calls to XFlush by defining XFlush to an empty replacement.
1752 Calls to XFlush should be unnecessary because the X output buffer
1753 is flushed automatically as needed by calls to XPending,
1754 XNextEvent, or XWindowEvent according to the XFlush man page.
1755 XTread_socket calls XPending. Removing XFlush improves
1758 #define XFlush(DISPLAY) (void) 0
1761 /* Return the struct mac_display_info corresponding to DPY. There's
1764 struct mac_display_info
*
1765 mac_display_info_for_display (dpy
)
1768 return &one_mac_display_info
;
1773 /***********************************************************************
1774 Starting and ending an update
1775 ***********************************************************************/
1777 /* Start an update of frame F. This function is installed as a hook
1778 for update_begin, i.e. it is called when update_begin is called.
1779 This function is called prior to calls to x_update_window_begin for
1780 each window being updated. */
1786 #if TARGET_API_MAC_CARBON
1787 /* During update of a frame, availability of input events is
1788 periodically checked with ReceiveNextEvent if
1789 redisplay-dont-pause is nil. That normally flushes window buffer
1790 changes for every check, and thus screen update looks waving even
1791 if no input is available. So we disable screen updates during
1792 update of a frame. */
1794 DisableScreenUpdates ();
1800 /* Start update of window W. Set the global variable updated_window
1801 to the window being updated and set output_cursor to the cursor
1805 x_update_window_begin (w
)
1808 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1809 struct mac_display_info
*display_info
= FRAME_MAC_DISPLAY_INFO (f
);
1812 set_output_cursor (&w
->cursor
);
1816 if (f
== display_info
->mouse_face_mouse_frame
)
1818 /* Don't do highlighting for mouse motion during the update. */
1819 display_info
->mouse_face_defer
= 1;
1821 /* If F needs to be redrawn, simply forget about any prior mouse
1823 if (FRAME_GARBAGED_P (f
))
1824 display_info
->mouse_face_window
= Qnil
;
1826 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
1827 their mouse_face_p flag set, which means that they are always
1828 unequal to rows in a desired matrix which never have that
1829 flag set. So, rows containing mouse-face glyphs are never
1830 scrolled, and we don't have to switch the mouse highlight off
1831 here to prevent it from being scrolled. */
1833 /* Can we tell that this update does not affect the window
1834 where the mouse highlight is? If so, no need to turn off.
1835 Likewise, don't do anything if the frame is garbaged;
1836 in that case, the frame's current matrix that we would use
1837 is all wrong, and we will redisplay that line anyway. */
1838 if (!NILP (display_info
->mouse_face_window
)
1839 && w
== XWINDOW (display_info
->mouse_face_window
))
1843 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
1844 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
1847 if (i
< w
->desired_matrix
->nrows
)
1848 clear_mouse_face (display_info
);
1857 /* Draw a vertical window border from (x,y0) to (x,y1) */
1860 mac_draw_vertical_window_border (w
, x
, y0
, y1
)
1864 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1867 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
1869 XSetForeground (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->normal_gc
,
1872 mac_draw_line (f
, f
->output_data
.mac
->normal_gc
, x
, y0
, x
, y1
);
1875 /* End update of window W (which is equal to updated_window).
1877 Draw vertical borders between horizontally adjacent windows, and
1878 display W's cursor if CURSOR_ON_P is non-zero.
1880 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
1881 glyphs in mouse-face were overwritten. In that case we have to
1882 make sure that the mouse-highlight is properly redrawn.
1884 W may be a menu bar pseudo-window in case we don't have X toolkit
1885 support. Such windows don't have a cursor, so don't display it
1889 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
1891 int cursor_on_p
, mouse_face_overwritten_p
;
1893 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (XFRAME (w
->frame
));
1895 if (!w
->pseudo_window_p
)
1900 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
1902 output_cursor
.x
, output_cursor
.y
);
1904 if (draw_window_fringes (w
, 1))
1905 x_draw_vertical_border (w
);
1910 /* If a row with mouse-face was overwritten, arrange for
1911 XTframe_up_to_date to redisplay the mouse highlight. */
1912 if (mouse_face_overwritten_p
)
1914 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
1915 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
1916 dpyinfo
->mouse_face_window
= Qnil
;
1919 updated_window
= NULL
;
1923 /* End update of frame F. This function is installed as a hook in
1930 /* Mouse highlight may be displayed again. */
1931 FRAME_MAC_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
1934 #if TARGET_API_MAC_CARBON
1935 EnableScreenUpdates ();
1937 XFlush (FRAME_MAC_DISPLAY (f
));
1942 /* This function is called from various places in xdisp.c whenever a
1943 complete update has been performed. The global variable
1944 updated_window is not available here. */
1947 XTframe_up_to_date (f
)
1950 if (FRAME_MAC_P (f
))
1952 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
1954 if (dpyinfo
->mouse_face_deferred_gc
1955 || f
== dpyinfo
->mouse_face_mouse_frame
)
1958 if (dpyinfo
->mouse_face_mouse_frame
)
1959 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
1960 dpyinfo
->mouse_face_mouse_x
,
1961 dpyinfo
->mouse_face_mouse_y
);
1962 dpyinfo
->mouse_face_deferred_gc
= 0;
1969 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
1970 arrow bitmaps, or clear the fringes if no bitmaps are required
1971 before DESIRED_ROW is made current. The window being updated is
1972 found in updated_window. This function is called from
1973 update_window_line only if it is known that there are differences
1974 between bitmaps to be drawn between current row and DESIRED_ROW. */
1977 x_after_update_window_line (desired_row
)
1978 struct glyph_row
*desired_row
;
1980 struct window
*w
= updated_window
;
1986 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
1987 desired_row
->redraw_fringe_bitmaps_p
= 1;
1989 /* When a window has disappeared, make sure that no rest of
1990 full-width rows stays visible in the internal border. Could
1991 check here if updated_window is the leftmost/rightmost window,
1992 but I guess it's not worth doing since vertically split windows
1993 are almost never used, internal border is rarely set, and the
1994 overhead is very small. */
1995 if (windows_or_buffers_changed
1996 && desired_row
->full_width_p
1997 && (f
= XFRAME (w
->frame
),
1998 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
2000 && (height
= desired_row
->visible_height
,
2003 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
2005 /* Internal border is drawn below the tool bar. */
2006 if (WINDOWP (f
->tool_bar_window
)
2007 && w
== XWINDOW (f
->tool_bar_window
))
2011 mac_clear_area (f
, 0, y
, width
, height
);
2012 mac_clear_area (f
, FRAME_PIXEL_WIDTH (f
) - width
, y
, width
, height
);
2018 /* Draw the bitmap WHICH in one of the left or right fringes of
2019 window W. ROW is the glyph row for which to display the bitmap; it
2020 determines the vertical position at which the bitmap has to be
2024 x_draw_fringe_bitmap (w
, row
, p
)
2026 struct glyph_row
*row
;
2027 struct draw_fringe_bitmap_params
*p
;
2029 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2030 Display
*display
= FRAME_MAC_DISPLAY (f
);
2031 struct face
*face
= p
->face
;
2034 /* Must clip because of partially visible lines. */
2035 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
2038 /* Adjust position of "bottom aligned" bitmap on partially
2039 visible last row. */
2041 int oldVH
= row
->visible_height
;
2042 row
->visible_height
= p
->h
;
2043 row
->y
-= rowY
- p
->y
;
2044 x_clip_to_row (w
, row
, -1, face
->gc
);
2046 row
->visible_height
= oldVH
;
2049 x_clip_to_row (w
, row
, -1, face
->gc
);
2051 if (p
->bx
>= 0 && !p
->overlay_p
)
2053 #if 0 /* MAC_TODO: stipple */
2054 /* In case the same realized face is used for fringes and
2055 for something displayed in the text (e.g. face `region' on
2056 mono-displays, the fill style may have been changed to
2057 FillSolid in x_draw_glyph_string_background. */
2059 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
2061 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
2064 mac_erase_rectangle (f
, face
->gc
, p
->bx
, p
->by
, p
->nx
, p
->ny
);
2066 #if 0 /* MAC_TODO: stipple */
2068 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
2074 && p
->which
< max_fringe_bmp
2080 XGetGCValues (display
, face
->gc
, GCForeground
, &gcv
);
2081 XSetForeground (display
, face
->gc
,
2083 ? (p
->overlay_p
? face
->background
2084 : f
->output_data
.mac
->cursor_pixel
)
2085 : face
->foreground
));
2087 mac_draw_cg_image (fringe_bmp
[p
->which
], f
, face
->gc
, 0, p
->dh
,
2088 p
->wd
, p
->h
, p
->x
, p
->y
, p
->overlay_p
);
2090 mac_draw_bitmap (f
, face
->gc
, p
->x
, p
->y
,
2091 p
->wd
, p
->h
, p
->bits
+ p
->dh
, p
->overlay_p
);
2093 XSetForeground (display
, face
->gc
, gcv
.foreground
);
2096 mac_reset_clip_rectangles (display
, face
->gc
);
2101 mac_define_fringe_bitmap (which
, bits
, h
, wd
)
2103 unsigned short *bits
;
2107 CGDataProviderRef provider
;
2109 if (which
>= max_fringe_bmp
)
2112 max_fringe_bmp
= which
+ 20;
2113 fringe_bmp
= (CGImageRef
*) xrealloc (fringe_bmp
, max_fringe_bmp
* sizeof (CGImageRef
));
2114 while (i
< max_fringe_bmp
)
2115 fringe_bmp
[i
++] = 0;
2118 for (i
= 0; i
< h
; i
++)
2120 provider
= CGDataProviderCreateWithData (NULL
, bits
,
2121 sizeof (unsigned short) * h
, NULL
);
2124 fringe_bmp
[which
] = CGImageMaskCreate (wd
, h
, 1, 1,
2125 sizeof (unsigned short),
2127 CGDataProviderRelease (provider
);
2132 mac_destroy_fringe_bitmap (which
)
2135 if (which
>= max_fringe_bmp
)
2138 if (fringe_bmp
[which
])
2139 CGImageRelease (fringe_bmp
[which
]);
2140 fringe_bmp
[which
] = 0;
2145 /* This is called when starting Emacs and when restarting after
2146 suspend. When starting Emacs, no window is mapped. And nothing
2147 must be done to Emacs's own window if it is suspended (though that
2151 XTset_terminal_modes ()
2155 /* This is called when exiting or suspending Emacs. Exiting will make
2156 the windows go away, and suspending requires no action. */
2159 XTreset_terminal_modes ()
2165 /***********************************************************************
2167 ***********************************************************************/
2169 /* Function prototypes of this page. */
2171 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
2172 static int mac_encode_char
P_ ((int, XChar2b
*, struct font_info
*, int *));
2176 pcm_init (pcm
, count
)
2180 bzero (pcm
, sizeof (XCharStruct
) * count
);
2181 while (--count
>= 0)
2183 pcm
->descent
= PCM_INVALID
;
2188 static enum pcm_status
2189 pcm_get_status (pcm
)
2192 int height
= pcm
->ascent
+ pcm
->descent
;
2194 /* Negative height means some special status. */
2195 return height
>= 0 ? PCM_VALID
: height
;
2198 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
2199 is not contained in the font. */
2201 static INLINE XCharStruct
*
2202 x_per_char_metric (font
, char2b
)
2206 /* The result metric information. */
2207 XCharStruct
*pcm
= NULL
;
2209 xassert (font
&& char2b
);
2212 if (font
->mac_style
)
2214 XCharStruct
**row
= font
->bounds
.rows
+ char2b
->byte1
;
2218 *row
= xmalloc (sizeof (XCharStruct
) * 0x100);
2219 pcm_init (*row
, 0x100);
2221 pcm
= *row
+ char2b
->byte2
;
2222 if (pcm_get_status (pcm
) != PCM_VALID
)
2225 mac_query_char_extents (font
->mac_style
,
2226 (char2b
->byte1
<< 8) + char2b
->byte2
,
2227 NULL
, NULL
, pcm
, NULL
);
2234 if (font
->bounds
.per_char
!= NULL
)
2236 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
2238 /* min_char_or_byte2 specifies the linear character index
2239 corresponding to the first element of the per_char array,
2240 max_char_or_byte2 is the index of the last character. A
2241 character with non-zero CHAR2B->byte1 is not in the font.
2242 A character with byte2 less than min_char_or_byte2 or
2243 greater max_char_or_byte2 is not in the font. */
2244 if (char2b
->byte1
== 0
2245 && char2b
->byte2
>= font
->min_char_or_byte2
2246 && char2b
->byte2
<= font
->max_char_or_byte2
)
2247 pcm
= font
->bounds
.per_char
2248 + (char2b
->byte2
- font
->min_char_or_byte2
);
2252 /* If either min_byte1 or max_byte1 are nonzero, both
2253 min_char_or_byte2 and max_char_or_byte2 are less than
2254 256, and the 2-byte character index values corresponding
2255 to the per_char array element N (counting from 0) are:
2257 byte1 = N/D + min_byte1
2258 byte2 = N\D + min_char_or_byte2
2262 D = max_char_or_byte2 - min_char_or_byte2 + 1
2263 / = integer division
2264 \ = integer modulus */
2265 if (char2b
->byte1
>= font
->min_byte1
2266 && char2b
->byte1
<= font
->max_byte1
2267 && char2b
->byte2
>= font
->min_char_or_byte2
2268 && char2b
->byte2
<= font
->max_char_or_byte2
)
2270 pcm
= (font
->bounds
.per_char
2271 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
2272 * (char2b
->byte1
- font
->min_byte1
))
2273 + (char2b
->byte2
- font
->min_char_or_byte2
));
2279 /* If the per_char pointer is null, all glyphs between the first
2280 and last character indexes inclusive have the same
2281 information, as given by both min_bounds and max_bounds. */
2282 if (char2b
->byte2
>= font
->min_char_or_byte2
2283 && char2b
->byte2
<= font
->max_char_or_byte2
)
2284 pcm
= &font
->max_bounds
;
2290 return ((pcm
== NULL
2292 #if 0 /* Show hollow boxes for zero-width glyphs such as combining diacritics. */
2293 && (pcm
->rbearing
- pcm
->lbearing
) == 0
2302 static XCharStruct
*
2303 mac_per_char_metric (font
, char2b
, font_type
)
2308 return x_per_char_metric (font
, char2b
);
2312 Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
2313 the two-byte form of C. Encoding is returned in *CHAR2B. */
2316 mac_encode_char (c
, char2b
, font_info
, two_byte_p
)
2319 struct font_info
*font_info
;
2322 int charset
= CHAR_CHARSET (c
);
2323 XFontStruct
*font
= font_info
->font
;
2325 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
2326 This may be either a program in a special encoder language or a
2328 if (font_info
->font_encoder
)
2330 /* It's a program. */
2331 struct ccl_program
*ccl
= font_info
->font_encoder
;
2333 check_ccl_update (ccl
);
2334 if (CHARSET_DIMENSION (charset
) == 1)
2336 ccl
->reg
[0] = charset
;
2337 ccl
->reg
[1] = char2b
->byte2
;
2342 ccl
->reg
[0] = charset
;
2343 ccl
->reg
[1] = char2b
->byte1
;
2344 ccl
->reg
[2] = char2b
->byte2
;
2347 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
2349 /* We assume that MSBs are appropriately set/reset by CCL
2351 if (font
->max_byte1
== 0) /* 1-byte font */
2352 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
2354 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
2356 else if (font_info
->encoding
[charset
])
2358 /* Fixed encoding scheme. See fontset.h for the meaning of the
2359 encoding numbers. */
2360 int enc
= font_info
->encoding
[charset
];
2362 if ((enc
== 1 || enc
== 2)
2363 && CHARSET_DIMENSION (charset
) == 2)
2364 char2b
->byte1
|= 0x80;
2366 if (enc
== 1 || enc
== 3)
2367 char2b
->byte2
|= 0x80;
2373 ENCODE_SJIS (char2b
->byte1
, char2b
->byte2
, sjis1
, sjis2
);
2374 char2b
->byte1
= sjis1
;
2375 char2b
->byte2
= sjis2
;
2380 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
2382 return FONT_TYPE_UNKNOWN
;
2387 /***********************************************************************
2389 ***********************************************************************/
2393 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2394 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2395 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2397 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2398 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2399 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2400 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2401 static void mac_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2402 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2403 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2404 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2405 /*static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap,
2406 unsigned long *, double, int));*/
2407 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2408 double, int, unsigned long));
2409 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2410 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2411 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2412 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2413 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2415 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2416 int, int, int, int, int, int,
2418 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2419 int, int, int, Rect
*));
2422 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2426 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2431 struct glyph_string
*s
;
2433 if (s
->font
== FRAME_FONT (s
->f
)
2434 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2435 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2437 s
->gc
= s
->f
->output_data
.mac
->cursor_gc
;
2440 /* Cursor on non-default face: must merge. */
2444 xgcv
.background
= s
->f
->output_data
.mac
->cursor_pixel
;
2445 xgcv
.foreground
= s
->face
->background
;
2447 /* If the glyph would be invisible, try a different foreground. */
2448 if (xgcv
.foreground
== xgcv
.background
)
2449 xgcv
.foreground
= s
->face
->foreground
;
2450 if (xgcv
.foreground
== xgcv
.background
)
2451 xgcv
.foreground
= s
->f
->output_data
.mac
->cursor_foreground_pixel
;
2452 if (xgcv
.foreground
== xgcv
.background
)
2453 xgcv
.foreground
= s
->face
->foreground
;
2455 /* Make sure the cursor is distinct from text in this face. */
2456 if (xgcv
.background
== s
->face
->background
2457 && xgcv
.foreground
== s
->face
->foreground
)
2459 xgcv
.background
= s
->face
->foreground
;
2460 xgcv
.foreground
= s
->face
->background
;
2463 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2464 xgcv
.font
= s
->font
;
2465 mask
= GCForeground
| GCBackground
| GCFont
;
2467 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2468 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2471 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2472 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2474 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2479 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2482 x_set_mouse_face_gc (s
)
2483 struct glyph_string
*s
;
2488 /* What face has to be used last for the mouse face? */
2489 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2490 face
= FACE_FROM_ID (s
->f
, face_id
);
2492 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2494 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2495 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2497 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2498 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2499 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2501 /* If font in this face is same as S->font, use it. */
2502 if (s
->font
== s
->face
->font
)
2503 s
->gc
= s
->face
->gc
;
2506 /* Otherwise construct scratch_cursor_gc with values from FACE
2511 xgcv
.background
= s
->face
->background
;
2512 xgcv
.foreground
= s
->face
->foreground
;
2513 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2514 xgcv
.font
= s
->font
;
2515 mask
= GCForeground
| GCBackground
| GCFont
;
2517 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2518 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2521 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2522 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2524 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2527 xassert (s
->gc
!= 0);
2531 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2532 Faces to use in the mode line have already been computed when the
2533 matrix was built, so there isn't much to do, here. */
2536 x_set_mode_line_face_gc (s
)
2537 struct glyph_string
*s
;
2539 s
->gc
= s
->face
->gc
;
2543 /* Set S->gc of glyph string S for drawing that glyph string. Set
2544 S->stippled_p to a non-zero value if the face of S has a stipple
2548 x_set_glyph_string_gc (s
)
2549 struct glyph_string
*s
;
2551 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2553 if (s
->hl
== DRAW_NORMAL_TEXT
)
2555 s
->gc
= s
->face
->gc
;
2556 s
->stippled_p
= s
->face
->stipple
!= 0;
2558 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2560 x_set_mode_line_face_gc (s
);
2561 s
->stippled_p
= s
->face
->stipple
!= 0;
2563 else if (s
->hl
== DRAW_CURSOR
)
2565 x_set_cursor_gc (s
);
2568 else if (s
->hl
== DRAW_MOUSE_FACE
)
2570 x_set_mouse_face_gc (s
);
2571 s
->stippled_p
= s
->face
->stipple
!= 0;
2573 else if (s
->hl
== DRAW_IMAGE_RAISED
2574 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2576 s
->gc
= s
->face
->gc
;
2577 s
->stippled_p
= s
->face
->stipple
!= 0;
2581 s
->gc
= s
->face
->gc
;
2582 s
->stippled_p
= s
->face
->stipple
!= 0;
2585 /* GC must have been set. */
2586 xassert (s
->gc
!= 0);
2590 /* Set clipping for output of glyph string S. S may be part of a mode
2591 line or menu if we don't have X toolkit support. */
2594 x_set_glyph_string_clipping (s
)
2595 struct glyph_string
*s
;
2597 Rect rects
[MAX_CLIP_RECTS
];
2600 n
= get_glyph_string_clip_rects (s
, rects
, MAX_CLIP_RECTS
);
2601 mac_set_clip_rectangles (s
->display
, s
->gc
, rects
, n
);
2606 Compute left and right overhang of glyph string S. If S is a glyph
2607 string for a composition, assume overhangs don't exist. */
2610 mac_compute_glyph_string_overhangs (s
)
2611 struct glyph_string
*s
;
2613 if (!(s
->cmp
== NULL
2614 && s
->first_glyph
->type
== CHAR_GLYPH
))
2619 || s
->font
->mac_style
2625 mac_text_extents_16 (s
->font
, s
->char2b
, s
->nchars
, &cs
);
2626 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2627 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2632 MacFontStruct
*font
= s
->font
;
2634 TextFont (font
->mac_fontnum
);
2635 TextSize (font
->mac_fontsize
);
2636 TextFace (font
->mac_fontface
);
2638 QDTextBounds (s
->nchars
* 2, (char *)s
->char2b
, &r
);
2640 s
->right_overhang
= r
.right
> s
->width
? r
.right
- s
->width
: 0;
2641 s
->left_overhang
= r
.left
< 0 ? -r
.left
: 0;
2646 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
2649 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
2650 struct glyph_string
*s
;
2653 mac_erase_rectangle (s
->f
, s
->gc
, x
, y
, w
, h
);
2657 /* Draw the background of glyph_string S. If S->background_filled_p
2658 is non-zero don't draw it. FORCE_P non-zero means draw the
2659 background even if it wouldn't be drawn normally. This is used
2660 when a string preceding S draws into the background of S, or S
2661 contains the first component of a composition. */
2664 x_draw_glyph_string_background (s
, force_p
)
2665 struct glyph_string
*s
;
2668 /* Nothing to do if background has already been drawn or if it
2669 shouldn't be drawn in the first place. */
2670 if (!s
->background_filled_p
)
2672 int box_line_width
= max (s
->face
->box_line_width
, 0);
2674 #if 0 /* MAC_TODO: stipple */
2677 /* Fill background with a stipple pattern. */
2678 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2679 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
2680 s
->y
+ box_line_width
,
2681 s
->background_width
,
2682 s
->height
- 2 * box_line_width
);
2683 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2684 s
->background_filled_p
= 1;
2688 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
2689 || s
->font_not_found_p
2690 || s
->extends_to_end_of_line_p
2693 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
2694 s
->background_width
,
2695 s
->height
- 2 * box_line_width
);
2696 s
->background_filled_p
= 1;
2702 /* Draw the foreground of glyph string S. */
2705 x_draw_glyph_string_foreground (s
)
2706 struct glyph_string
*s
;
2710 /* If first glyph of S has a left box line, start drawing the text
2711 of S to the right of that box line. */
2712 if (s
->face
->box
!= FACE_NO_BOX
2713 && s
->first_glyph
->left_box_line_p
)
2714 x
= s
->x
+ abs (s
->face
->box_line_width
);
2718 /* Draw characters of S as rectangles if S's font could not be
2720 if (s
->font_not_found_p
)
2722 for (i
= 0; i
< s
->nchars
; ++i
)
2724 struct glyph
*g
= s
->first_glyph
+ i
;
2725 mac_draw_rectangle (s
->f
, s
->gc
, x
, s
->y
,
2726 g
->pixel_width
- 1, s
->height
- 1);
2727 x
+= g
->pixel_width
;
2732 char *char1b
= (char *) s
->char2b
;
2733 int boff
= s
->font_info
->baseline_offset
;
2735 if (s
->font_info
->vertical_centering
)
2736 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
2738 /* If we can use 8-bit functions, condense S->char2b. */
2741 && GC_FONT (s
->gc
)->mac_style
== NULL
2744 for (i
= 0; i
< s
->nchars
; ++i
)
2745 char1b
[i
] = s
->char2b
[i
].byte2
;
2747 /* Draw text with XDrawString if background has already been
2748 filled. Otherwise, use XDrawImageString. (Note that
2749 XDrawImageString is usually faster than XDrawString.) Always
2750 use XDrawImageString when drawing the cursor so that there is
2751 no chance that characters under a box cursor are invisible. */
2753 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
2754 bg_width
= 0; /* Corresponds to XDrawString. */
2756 bg_width
= s
->background_width
; /* Corresponds to XDrawImageString. */
2760 || GC_FONT (s
->gc
)->mac_style
2763 #if USE_CG_TEXT_DRAWING
2765 && mac_draw_image_string_cg (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2766 s
->char2b
, s
->nchars
, bg_width
))
2770 mac_draw_image_string_16 (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2771 s
->char2b
, s
->nchars
, bg_width
);
2773 mac_draw_image_string (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2774 char1b
, s
->nchars
, bg_width
);
2778 /* Draw the foreground of composite glyph string S. */
2781 x_draw_composite_glyph_string_foreground (s
)
2782 struct glyph_string
*s
;
2786 /* If first glyph of S has a left box line, start drawing the text
2787 of S to the right of that box line. */
2788 if (s
->face
->box
!= FACE_NO_BOX
2789 && s
->first_glyph
->left_box_line_p
)
2790 x
= s
->x
+ abs (s
->face
->box_line_width
);
2794 /* S is a glyph string for a composition. S->gidx is the index of
2795 the first character drawn for glyphs of this composition.
2796 S->gidx == 0 means we are drawing the very first character of
2797 this composition. */
2799 /* Draw a rectangle for the composition if the font for the very
2800 first character of the composition could not be loaded. */
2801 if (s
->font_not_found_p
)
2804 mac_draw_rectangle (s
->f
, s
->gc
, x
, s
->y
,
2805 s
->width
- 1, s
->height
- 1);
2809 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
2810 mac_draw_string_16 (s
->f
, s
->gc
,
2811 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
2812 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
2818 #ifdef USE_X_TOOLKIT
2820 static struct frame
*x_frame_of_widget
P_ ((Widget
));
2823 /* Return the frame on which widget WIDGET is used.. Abort if frame
2824 cannot be determined. */
2826 static struct frame
*
2827 x_frame_of_widget (widget
)
2830 struct x_display_info
*dpyinfo
;
2834 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
2836 /* Find the top-level shell of the widget. Note that this function
2837 can be called when the widget is not yet realized, so XtWindow
2838 (widget) == 0. That's the reason we can't simply use
2839 x_any_window_to_frame. */
2840 while (!XtIsTopLevelShell (widget
))
2841 widget
= XtParent (widget
);
2843 /* Look for a frame with that top-level widget. Allocate the color
2844 on that frame to get the right gamma correction value. */
2845 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
2846 if (GC_FRAMEP (XCAR (tail
))
2847 && (f
= XFRAME (XCAR (tail
)),
2848 (f
->output_data
.nothing
!= 1
2849 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
2850 && f
->output_data
.x
->widget
== widget
)
2857 /* Allocate the color COLOR->pixel on the screen and display of
2858 widget WIDGET in colormap CMAP. If an exact match cannot be
2859 allocated, try the nearest color available. Value is non-zero
2860 if successful. This is called from lwlib. */
2863 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
2868 struct frame
*f
= x_frame_of_widget (widget
);
2869 return x_alloc_nearest_color (f
, cmap
, color
);
2873 #endif /* USE_X_TOOLKIT */
2875 #if 0 /* MAC_TODO */
2877 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
2878 CMAP. If an exact match can't be allocated, try the nearest color
2879 available. Value is non-zero if successful. Set *COLOR to the
2883 x_alloc_nearest_color (f
, cmap
, color
)
2888 Display
*display
= FRAME_X_DISPLAY (f
);
2889 Screen
*screen
= FRAME_X_SCREEN (f
);
2892 gamma_correct (f
, color
);
2893 rc
= XAllocColor (display
, cmap
, color
);
2896 /* If we got to this point, the colormap is full, so we're going
2897 to try to get the next closest color. The algorithm used is
2898 a least-squares matching, which is what X uses for closest
2899 color matching with StaticColor visuals. */
2901 unsigned long nearest_delta
= ~0;
2902 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
2903 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
2905 for (i
= 0; i
< ncells
; ++i
)
2907 XQueryColors (display
, cmap
, cells
, ncells
);
2909 for (nearest
= i
= 0; i
< ncells
; ++i
)
2911 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
2912 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
2913 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
2914 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
2916 if (delta
< nearest_delta
)
2919 nearest_delta
= delta
;
2923 color
->red
= cells
[nearest
].red
;
2924 color
->green
= cells
[nearest
].green
;
2925 color
->blue
= cells
[nearest
].blue
;
2926 rc
= XAllocColor (display
, cmap
, color
);
2929 #ifdef DEBUG_X_COLORS
2931 register_color (color
->pixel
);
2932 #endif /* DEBUG_X_COLORS */
2938 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
2939 It's necessary to do this instead of just using PIXEL directly to
2940 get color reference counts right. */
2943 x_copy_color (f
, pixel
)
2945 unsigned long pixel
;
2949 color
.pixel
= pixel
;
2951 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2952 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2954 #ifdef DEBUG_X_COLORS
2955 register_color (pixel
);
2961 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
2962 It's necessary to do this instead of just using PIXEL directly to
2963 get color reference counts right. */
2966 x_copy_dpy_color (dpy
, cmap
, pixel
)
2969 unsigned long pixel
;
2973 color
.pixel
= pixel
;
2975 XQueryColor (dpy
, cmap
, &color
);
2976 XAllocColor (dpy
, cmap
, &color
);
2978 #ifdef DEBUG_X_COLORS
2979 register_color (pixel
);
2984 #endif /* MAC_TODO */
2987 /* Brightness beyond which a color won't have its highlight brightness
2990 Nominally, highlight colors for `3d' faces are calculated by
2991 brightening an object's color by a constant scale factor, but this
2992 doesn't yield good results for dark colors, so for colors who's
2993 brightness is less than this value (on a scale of 0-255) have to
2994 use an additional additive factor.
2996 The value here is set so that the default menu-bar/mode-line color
2997 (grey75) will not have its highlights changed at all. */
2998 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
3001 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
3002 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3003 If this produces the same color as COLOR, try a color where all RGB
3004 values have DELTA added. Return the allocated color in *COLOR.
3005 DISPLAY is the X display, CMAP is the colormap to operate on.
3006 Value is non-zero if successful. */
3009 mac_alloc_lighter_color (f
, color
, factor
, delta
)
3011 unsigned long *color
;
3018 /* On Mac, RGB values are 0-255, not 0-65535, so scale delta. */
3021 /* Change RGB values by specified FACTOR. Avoid overflow! */
3022 xassert (factor
>= 0);
3023 new = RGB_TO_ULONG (min (0xff, (int) (factor
* RED_FROM_ULONG (*color
))),
3024 min (0xff, (int) (factor
* GREEN_FROM_ULONG (*color
))),
3025 min (0xff, (int) (factor
* BLUE_FROM_ULONG (*color
))));
3027 /* Calculate brightness of COLOR. */
3028 bright
= (2 * RED_FROM_ULONG (*color
) + 3 * GREEN_FROM_ULONG (*color
)
3029 + BLUE_FROM_ULONG (*color
)) / 6;
3031 /* We only boost colors that are darker than
3032 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3033 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3034 /* Make an additive adjustment to NEW, because it's dark enough so
3035 that scaling by FACTOR alone isn't enough. */
3037 /* How far below the limit this color is (0 - 1, 1 being darker). */
3038 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3039 /* The additive adjustment. */
3040 int min_delta
= delta
* dimness
* factor
/ 2;
3043 new = RGB_TO_ULONG (max (0, min (0xff, (int) (RED_FROM_ULONG (*color
)) - min_delta
)),
3044 max (0, min (0xff, (int) (GREEN_FROM_ULONG (*color
)) - min_delta
)),
3045 max (0, min (0xff, (int) (BLUE_FROM_ULONG (*color
)) - min_delta
)));
3047 new = RGB_TO_ULONG (max (0, min (0xff, (int) (min_delta
+ RED_FROM_ULONG (*color
)))),
3048 max (0, min (0xff, (int) (min_delta
+ GREEN_FROM_ULONG (*color
)))),
3049 max (0, min (0xff, (int) (min_delta
+ BLUE_FROM_ULONG (*color
)))));
3053 new = RGB_TO_ULONG (max (0, min (0xff, (int) (delta
+ RED_FROM_ULONG (*color
)))),
3054 max (0, min (0xff, (int) (delta
+ GREEN_FROM_ULONG (*color
)))),
3055 max (0, min (0xff, (int) (delta
+ BLUE_FROM_ULONG (*color
)))));
3057 /* MAC_TODO: Map to palette and retry with delta if same? */
3058 /* MAC_TODO: Free colors (if using palette)? */
3069 /* Set up the foreground color for drawing relief lines of glyph
3070 string S. RELIEF is a pointer to a struct relief containing the GC
3071 with which lines will be drawn. Use a color that is FACTOR or
3072 DELTA lighter or darker than the relief's background which is found
3073 in S->f->output_data.x->relief_background. If such a color cannot
3074 be allocated, use DEFAULT_PIXEL, instead. */
3077 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3079 struct relief
*relief
;
3082 unsigned long default_pixel
;
3085 struct mac_output
*di
= f
->output_data
.mac
;
3086 unsigned long mask
= GCForeground
;
3087 unsigned long pixel
;
3088 unsigned long background
= di
->relief_background
;
3089 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
3091 /* MAC_TODO: Free colors (if using palette)? */
3093 /* Allocate new color. */
3094 xgcv
.foreground
= default_pixel
;
3096 if (dpyinfo
->n_planes
!= 1
3097 && mac_alloc_lighter_color (f
, &pixel
, factor
, delta
))
3099 relief
->allocated_p
= 1;
3100 xgcv
.foreground
= relief
->pixel
= pixel
;
3103 if (relief
->gc
== 0)
3105 #if 0 /* MAC_TODO: stipple */
3106 xgcv
.stipple
= dpyinfo
->gray
;
3109 relief
->gc
= XCreateGC (NULL
, FRAME_MAC_WINDOW (f
), mask
, &xgcv
);
3112 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
3116 /* Set up colors for the relief lines around glyph string S. */
3119 x_setup_relief_colors (s
)
3120 struct glyph_string
*s
;
3122 struct mac_output
*di
= s
->f
->output_data
.mac
;
3123 unsigned long color
;
3125 if (s
->face
->use_box_color_for_shadows_p
)
3126 color
= s
->face
->box_color
;
3127 else if (s
->first_glyph
->type
== IMAGE_GLYPH
3129 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
3130 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
3135 /* Get the background color of the face. */
3136 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3137 color
= xgcv
.background
;
3140 if (di
->white_relief
.gc
== 0
3141 || color
!= di
->relief_background
)
3143 di
->relief_background
= color
;
3144 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3145 WHITE_PIX_DEFAULT (s
->f
));
3146 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3147 BLACK_PIX_DEFAULT (s
->f
));
3152 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3153 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3154 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3155 relief. LEFT_P non-zero means draw a relief on the left side of
3156 the rectangle. RIGHT_P non-zero means draw a relief on the right
3157 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3161 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3162 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
3164 int left_x
, top_y
, right_x
, bottom_y
, width
;
3165 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
3168 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
3173 gc
= f
->output_data
.mac
->white_relief
.gc
;
3175 gc
= f
->output_data
.mac
->black_relief
.gc
;
3176 mac_set_clip_rectangles (dpy
, gc
, clip_rect
, 1);
3180 for (i
= 0; i
< width
; ++i
)
3181 mac_draw_line (f
, gc
,
3182 left_x
+ i
* left_p
, top_y
+ i
,
3183 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3187 for (i
= 0; i
< width
; ++i
)
3188 mac_draw_line (f
, gc
,
3189 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
3191 mac_reset_clip_rectangles (dpy
, gc
);
3193 gc
= f
->output_data
.mac
->black_relief
.gc
;
3195 gc
= f
->output_data
.mac
->white_relief
.gc
;
3196 mac_set_clip_rectangles (dpy
, gc
, clip_rect
, 1);
3200 for (i
= 0; i
< width
; ++i
)
3201 mac_draw_line (f
, gc
,
3202 left_x
+ i
* left_p
, bottom_y
- i
,
3203 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3207 for (i
= 0; i
< width
; ++i
)
3208 mac_draw_line (f
, gc
,
3209 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3211 mac_reset_clip_rectangles (dpy
, gc
);
3215 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3216 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3217 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3218 left side of the rectangle. RIGHT_P non-zero means draw a line
3219 on the right side of the rectangle. CLIP_RECT is the clipping
3220 rectangle to use when drawing. */
3223 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3224 left_p
, right_p
, clip_rect
)
3225 struct glyph_string
*s
;
3226 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
3231 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3232 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3233 mac_set_clip_rectangles (s
->display
, s
->gc
, clip_rect
, 1);
3236 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, top_y
,
3237 right_x
- left_x
+ 1, width
);
3241 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, top_y
,
3242 width
, bottom_y
- top_y
+ 1);
3245 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, bottom_y
- width
+ 1,
3246 right_x
- left_x
+ 1, width
);
3250 mac_fill_rectangle (s
->f
, s
->gc
, right_x
- width
+ 1,
3251 top_y
, width
, bottom_y
- top_y
+ 1);
3253 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3254 mac_reset_clip_rectangles (s
->display
, s
->gc
);
3258 /* Draw a box around glyph string S. */
3261 x_draw_glyph_string_box (s
)
3262 struct glyph_string
*s
;
3264 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3265 int left_p
, right_p
;
3266 struct glyph
*last_glyph
;
3269 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
3270 ? WINDOW_RIGHT_EDGE_X (s
->w
)
3271 : window_box_right (s
->w
, s
->area
));
3273 /* The glyph that may have a right box line. */
3274 last_glyph
= (s
->cmp
|| s
->img
3276 : s
->first_glyph
+ s
->nchars
- 1);
3278 width
= abs (s
->face
->box_line_width
);
3279 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3281 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
3283 : min (last_x
, s
->x
+ s
->background_width
) - 1);
3285 bottom_y
= top_y
+ s
->height
- 1;
3287 left_p
= (s
->first_glyph
->left_box_line_p
3288 || (s
->hl
== DRAW_MOUSE_FACE
3290 || s
->prev
->hl
!= s
->hl
)));
3291 right_p
= (last_glyph
->right_box_line_p
3292 || (s
->hl
== DRAW_MOUSE_FACE
3294 || s
->next
->hl
!= s
->hl
)));
3296 get_glyph_string_clip_rect (s
, &clip_rect
);
3298 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3299 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3300 left_p
, right_p
, &clip_rect
);
3303 x_setup_relief_colors (s
);
3304 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3305 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
3310 /* Draw foreground of image glyph string S. */
3313 x_draw_image_foreground (s
)
3314 struct glyph_string
*s
;
3317 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
3319 /* If first glyph of S has a left box line, start drawing it to the
3320 right of that line. */
3321 if (s
->face
->box
!= FACE_NO_BOX
3322 && s
->first_glyph
->left_box_line_p
3324 x
+= abs (s
->face
->box_line_width
);
3326 /* If there is a margin around the image, adjust x- and y-position
3328 if (s
->slice
.x
== 0)
3329 x
+= s
->img
->hmargin
;
3330 if (s
->slice
.y
== 0)
3331 y
+= s
->img
->vmargin
;
3335 x_set_glyph_string_clipping (s
);
3338 mac_draw_cg_image (s
->img
->data
.ptr_val
,
3339 s
->f
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
3340 s
->slice
.width
, s
->slice
.height
, x
, y
, 1);
3344 mac_copy_area_with_mask (s
->img
->pixmap
, s
->img
->mask
,
3345 s
->f
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
3346 s
->slice
.width
, s
->slice
.height
, x
, y
);
3353 mac_copy_area (s
->img
->pixmap
,
3354 s
->f
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
3355 s
->slice
.width
, s
->slice
.height
, x
, y
);
3358 /* When the image has a mask, we can expect that at
3359 least part of a mouse highlight or a block cursor will
3360 be visible. If the image doesn't have a mask, make
3361 a block cursor visible by drawing a rectangle around
3362 the image. I believe it's looking better if we do
3363 nothing here for mouse-face. */
3364 if (s
->hl
== DRAW_CURSOR
)
3366 int r
= s
->img
->relief
;
3368 mac_draw_rectangle (s
->f
, s
->gc
, x
- r
, y
- r
,
3369 s
->slice
.width
+ r
*2 - 1,
3370 s
->slice
.height
+ r
*2 - 1);
3375 /* Draw a rectangle if image could not be loaded. */
3376 mac_draw_rectangle (s
->f
, s
->gc
, x
, y
,
3377 s
->slice
.width
- 1, s
->slice
.height
- 1);
3381 /* Draw a relief around the image glyph string S. */
3384 x_draw_image_relief (s
)
3385 struct glyph_string
*s
;
3387 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3390 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
3392 /* If first glyph of S has a left box line, start drawing it to the
3393 right of that line. */
3394 if (s
->face
->box
!= FACE_NO_BOX
3395 && s
->first_glyph
->left_box_line_p
3397 x
+= abs (s
->face
->box_line_width
);
3399 /* If there is a margin around the image, adjust x- and y-position
3401 if (s
->slice
.x
== 0)
3402 x
+= s
->img
->hmargin
;
3403 if (s
->slice
.y
== 0)
3404 y
+= s
->img
->vmargin
;
3406 if (s
->hl
== DRAW_IMAGE_SUNKEN
3407 || s
->hl
== DRAW_IMAGE_RAISED
)
3409 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3410 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3414 thick
= abs (s
->img
->relief
);
3415 raised_p
= s
->img
->relief
> 0;
3420 x1
= x
+ s
->slice
.width
+ thick
- 1;
3421 y1
= y
+ s
->slice
.height
+ thick
- 1;
3423 x_setup_relief_colors (s
);
3424 get_glyph_string_clip_rect (s
, &r
);
3425 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
3427 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
3429 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
3434 /* Draw part of the background of glyph string S. X, Y, W, and H
3435 give the rectangle to draw. */
3438 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3439 struct glyph_string
*s
;
3442 #if 0 /* MAC_TODO: stipple */
3445 /* Fill background with a stipple pattern. */
3446 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3447 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3448 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3451 #endif /* MAC_TODO */
3452 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3456 /* Draw image glyph string S.
3459 s->x +-------------------------
3462 | +-------------------------
3465 | | +-------------------
3471 x_draw_image_glyph_string (s
)
3472 struct glyph_string
*s
;
3475 int box_line_hwidth
= abs (s
->face
->box_line_width
);
3476 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
3479 height
= s
->height
- 2 * box_line_vwidth
;
3482 /* Fill background with face under the image. Do it only if row is
3483 taller than image or if image has a clip mask to reduce
3485 s
->stippled_p
= s
->face
->stipple
!= 0;
3486 if (height
> s
->slice
.height
3490 || s
->img
->pixmap
== 0
3491 || s
->width
!= s
->background_width
)
3494 if (s
->first_glyph
->left_box_line_p
3496 x
+= box_line_hwidth
;
3499 if (s
->slice
.y
== 0)
3500 y
+= box_line_vwidth
;
3502 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
3504 s
->background_filled_p
= 1;
3507 /* Draw the foreground. */
3508 x_draw_image_foreground (s
);
3510 /* If we must draw a relief around the image, do it. */
3512 || s
->hl
== DRAW_IMAGE_RAISED
3513 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3514 x_draw_image_relief (s
);
3518 /* Draw stretch glyph string S. */
3521 x_draw_stretch_glyph_string (s
)
3522 struct glyph_string
*s
;
3524 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
3525 s
->stippled_p
= s
->face
->stipple
!= 0;
3527 if (s
->hl
== DRAW_CURSOR
3528 && !x_stretch_cursor_p
)
3530 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
3531 as wide as the stretch glyph. */
3532 int width
= min (FRAME_COLUMN_WIDTH (s
->f
), s
->background_width
);
3535 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
3537 /* Clear rest using the GC of the original non-cursor face. */
3538 if (width
< s
->background_width
)
3540 int x
= s
->x
+ width
, y
= s
->y
;
3541 int w
= s
->background_width
- width
, h
= s
->height
;
3545 if (s
->row
->mouse_face_p
3546 && cursor_in_mouse_face_p (s
->w
))
3548 x_set_mouse_face_gc (s
);
3554 get_glyph_string_clip_rect (s
, &r
);
3555 mac_set_clip_rectangles (s
->display
, gc
, &r
, 1);
3557 #if 0 /* MAC_TODO: stipple */
3558 if (s
->face
->stipple
)
3560 /* Fill background with a stipple pattern. */
3561 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
3562 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3563 XSetFillStyle (s
->display
, gc
, FillSolid
);
3566 #endif /* MAC_TODO */
3567 mac_erase_rectangle (s
->f
, gc
, x
, y
, w
, h
);
3570 else if (!s
->background_filled_p
)
3571 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
3574 s
->background_filled_p
= 1;
3578 /* Draw glyph string S. */
3581 x_draw_glyph_string (s
)
3582 struct glyph_string
*s
;
3584 int relief_drawn_p
= 0;
3586 /* If S draws into the background of its successor that does not
3587 draw a cursor, draw the background of the successor first so that
3588 S can draw into it. This makes S->next use XDrawString instead
3589 of XDrawImageString. */
3590 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
3591 && s
->next
->hl
!= DRAW_CURSOR
)
3593 xassert (s
->next
->img
== NULL
);
3594 x_set_glyph_string_gc (s
->next
);
3595 x_set_glyph_string_clipping (s
->next
);
3596 x_draw_glyph_string_background (s
->next
, 1);
3599 /* Set up S->gc, set clipping and draw S. */
3600 x_set_glyph_string_gc (s
);
3602 /* Draw relief (if any) in advance for char/composition so that the
3603 glyph string can be drawn over it. */
3604 if (!s
->for_overlaps
3605 && s
->face
->box
!= FACE_NO_BOX
3606 && (s
->first_glyph
->type
== CHAR_GLYPH
3607 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
3610 x_set_glyph_string_clipping (s
);
3611 x_draw_glyph_string_background (s
, 1);
3612 x_draw_glyph_string_box (s
);
3613 x_set_glyph_string_clipping (s
);
3617 x_set_glyph_string_clipping (s
);
3619 switch (s
->first_glyph
->type
)
3622 x_draw_image_glyph_string (s
);
3626 x_draw_stretch_glyph_string (s
);
3630 if (s
->for_overlaps
)
3631 s
->background_filled_p
= 1;
3633 x_draw_glyph_string_background (s
, 0);
3634 x_draw_glyph_string_foreground (s
);
3637 case COMPOSITE_GLYPH
:
3638 if (s
->for_overlaps
|| s
->gidx
> 0)
3639 s
->background_filled_p
= 1;
3641 x_draw_glyph_string_background (s
, 1);
3642 x_draw_composite_glyph_string_foreground (s
);
3649 if (!s
->for_overlaps
)
3651 /* Draw underline. */
3652 if (s
->face
->underline_p
)
3654 unsigned long h
= 1;
3655 unsigned long dy
= s
->height
- h
;
3657 if (s
->face
->underline_defaulted_p
)
3658 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3663 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3664 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
3665 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3667 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3671 /* Draw overline. */
3672 if (s
->face
->overline_p
)
3674 unsigned long dy
= 0, h
= 1;
3676 if (s
->face
->overline_color_defaulted_p
)
3677 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3682 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3683 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
3684 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3686 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3690 /* Draw strike-through. */
3691 if (s
->face
->strike_through_p
)
3693 unsigned long h
= 1;
3694 unsigned long dy
= (s
->height
- h
) / 2;
3696 if (s
->face
->strike_through_color_defaulted_p
)
3697 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3702 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3703 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
3704 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3706 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3710 /* Draw relief if not yet drawn. */
3711 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3712 x_draw_glyph_string_box (s
);
3715 /* Reset clipping. */
3716 mac_reset_clip_rectangles (s
->display
, s
->gc
);
3719 /* Shift display to make room for inserted glyphs. */
3722 mac_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
3724 int x
, y
, width
, height
, shift_by
;
3726 mac_scroll_area (f
, f
->output_data
.mac
->normal_gc
,
3727 x
, y
, width
, height
,
3731 /* Delete N glyphs at the nominal cursor position. Not implemented
3742 /* Clear entire frame. If updating_frame is non-null, clear that
3743 frame. Otherwise clear the selected frame. */
3753 f
= SELECTED_FRAME ();
3755 /* Clearing the frame will erase any cursor, so mark them all as no
3757 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3758 output_cursor
.hpos
= output_cursor
.vpos
= 0;
3759 output_cursor
.x
= -1;
3761 /* We don't set the output cursor here because there will always
3762 follow an explicit cursor_to. */
3764 mac_clear_window (f
);
3766 /* We have to clear the scroll bars, too. If we have changed
3767 colors or something like that, then they should be notified. */
3768 x_scroll_bar_clear (f
);
3770 XFlush (FRAME_MAC_DISPLAY (f
));
3776 /* Invert the middle quarter of the frame for .15 sec. */
3778 /* We use the select system call to do the waiting, so we have to make
3779 sure it's available. If it isn't, we just won't do visual bells. */
3781 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3784 /* Subtract the `struct timeval' values X and Y, storing the result in
3785 *RESULT. Return 1 if the difference is negative, otherwise 0. */
3788 timeval_subtract (result
, x
, y
)
3789 struct timeval
*result
, x
, y
;
3791 /* Perform the carry for the later subtraction by updating y. This
3792 is safer because on some systems the tv_sec member is unsigned. */
3793 if (x
.tv_usec
< y
.tv_usec
)
3795 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
3796 y
.tv_usec
-= 1000000 * nsec
;
3800 if (x
.tv_usec
- y
.tv_usec
> 1000000)
3802 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
3803 y
.tv_usec
+= 1000000 * nsec
;
3807 /* Compute the time remaining to wait. tv_usec is certainly
3809 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
3810 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
3812 /* Return indication of whether the result should be considered
3814 return x
.tv_sec
< y
.tv_sec
;
3821 /* Get the height not including a menu bar widget. */
3822 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
3823 /* Height of each line to flash. */
3824 int flash_height
= FRAME_LINE_HEIGHT (f
);
3825 /* These will be the left and right margins of the rectangles. */
3826 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3827 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3831 /* Don't flash the area between a scroll bar and the frame
3832 edge it is next to. */
3833 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
3835 case vertical_scroll_bar_left
:
3836 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3839 case vertical_scroll_bar_right
:
3840 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3847 width
= flash_right
- flash_left
;
3851 /* If window is tall, flash top and bottom line. */
3852 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3854 mac_invert_rectangle (f
, flash_left
,
3855 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3856 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3857 width
, flash_height
);
3858 mac_invert_rectangle (f
, flash_left
,
3859 (height
- flash_height
3860 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3861 width
, flash_height
);
3864 /* If it is short, flash it all. */
3865 mac_invert_rectangle (f
, flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3866 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3871 struct timeval wakeup
;
3873 EMACS_GET_TIME (wakeup
);
3875 /* Compute time to wait until, propagating carry from usecs. */
3876 wakeup
.tv_usec
+= 150000;
3877 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
3878 wakeup
.tv_usec
%= 1000000;
3880 /* Keep waiting until past the time wakeup or any input gets
3882 while (! detect_input_pending ())
3884 struct timeval current
;
3885 struct timeval timeout
;
3887 EMACS_GET_TIME (current
);
3889 /* Break if result would be negative. */
3890 if (timeval_subtract (¤t
, wakeup
, current
))
3893 /* How long `select' should wait. */
3895 timeout
.tv_usec
= 10000;
3897 /* Try to wait that long--but we might wake up sooner. */
3898 select (0, NULL
, NULL
, NULL
, &timeout
);
3902 /* If window is tall, flash top and bottom line. */
3903 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3905 mac_invert_rectangle (f
, flash_left
,
3906 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3907 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3908 width
, flash_height
);
3909 mac_invert_rectangle (f
, flash_left
,
3910 (height
- flash_height
3911 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3912 width
, flash_height
);
3915 /* If it is short, flash it all. */
3916 mac_invert_rectangle (f
, flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3917 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3924 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3927 /* Make audible bell. */
3932 struct frame
*f
= SELECTED_FRAME ();
3934 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3942 XFlush (FRAME_MAC_DISPLAY (f
));
3948 /* Specify how many text lines, from the top of the window,
3949 should be affected by insert-lines and delete-lines operations.
3950 This, and those operations, are used only within an update
3951 that is bounded by calls to x_update_begin and x_update_end. */
3954 XTset_terminal_window (n
)
3957 /* This function intentionally left blank. */
3962 /***********************************************************************
3964 ***********************************************************************/
3966 /* Perform an insert-lines or delete-lines operation, inserting N
3967 lines or deleting -N lines at vertical position VPOS. */
3970 x_ins_del_lines (vpos
, n
)
3977 /* Scroll part of the display as described by RUN. */
3980 x_scroll_run (w
, run
)
3984 struct frame
*f
= XFRAME (w
->frame
);
3985 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3987 /* Get frame-relative bounding box of the text display area of W,
3988 without mode lines. Include in this box the left and right
3990 window_box (w
, -1, &x
, &y
, &width
, &height
);
3992 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3993 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3994 bottom_y
= y
+ height
;
3998 /* Scrolling up. Make sure we don't copy part of the mode
3999 line at the bottom. */
4000 if (from_y
+ run
->height
> bottom_y
)
4001 height
= bottom_y
- from_y
;
4003 height
= run
->height
;
4007 /* Scolling down. Make sure we don't copy over the mode line.
4009 if (to_y
+ run
->height
> bottom_y
)
4010 height
= bottom_y
- to_y
;
4012 height
= run
->height
;
4017 /* Cursor off. Will be switched on again in x_update_window_end. */
4021 mac_scroll_area (f
, f
->output_data
.mac
->normal_gc
,
4031 /***********************************************************************
4033 ***********************************************************************/
4041 ControlRef root_control
;
4044 err
= GetRootControl (FRAME_MAC_WINDOW (f
), &root_control
);
4046 ActivateControl (root_control
);
4048 x_update_cursor (f
, 1);
4052 frame_unhighlight (f
)
4056 ControlRef root_control
;
4059 err
= GetRootControl (FRAME_MAC_WINDOW (f
), &root_control
);
4061 DeactivateControl (root_control
);
4063 x_update_cursor (f
, 1);
4066 /* The focus has changed. Update the frames as necessary to reflect
4067 the new situation. Note that we can't change the selected frame
4068 here, because the Lisp code we are interrupting might become confused.
4069 Each event gets marked with the frame in which it occurred, so the
4070 Lisp code can tell when the switch took place by examining the events. */
4073 x_new_focus_frame (dpyinfo
, frame
)
4074 struct x_display_info
*dpyinfo
;
4075 struct frame
*frame
;
4077 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
4079 if (frame
!= dpyinfo
->x_focus_frame
)
4081 /* Set this before calling other routines, so that they see
4082 the correct value of x_focus_frame. */
4083 dpyinfo
->x_focus_frame
= frame
;
4085 if (old_focus
&& old_focus
->auto_lower
)
4086 x_lower_frame (old_focus
);
4089 selected_frame
= frame
;
4090 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
4092 Fselect_window (selected_frame
->selected_window
, Qnil
);
4093 choose_minibuf_frame ();
4096 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
4097 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
4099 pending_autoraise_frame
= 0;
4101 #if USE_MAC_FONT_PANEL
4103 mac_set_font_info_for_selection (frame
, DEFAULT_FACE_ID
, 0);
4107 x_frame_rehighlight (dpyinfo
);
4110 /* Handle FocusIn and FocusOut state changes for FRAME.
4111 If FRAME has focus and there exists more than one frame, puts
4112 a FOCUS_IN_EVENT into *BUFP. */
4115 mac_focus_changed (type
, dpyinfo
, frame
, bufp
)
4117 struct mac_display_info
*dpyinfo
;
4118 struct frame
*frame
;
4119 struct input_event
*bufp
;
4121 if (type
== activeFlag
)
4123 if (dpyinfo
->x_focus_event_frame
!= frame
)
4125 x_new_focus_frame (dpyinfo
, frame
);
4126 dpyinfo
->x_focus_event_frame
= frame
;
4128 /* Don't stop displaying the initial startup message
4129 for a switch-frame event we don't need. */
4130 if (GC_NILP (Vterminal_frame
)
4131 && GC_CONSP (Vframe_list
)
4132 && !GC_NILP (XCDR (Vframe_list
)))
4134 bufp
->kind
= FOCUS_IN_EVENT
;
4135 XSETFRAME (bufp
->frame_or_window
, frame
);
4141 if (dpyinfo
->x_focus_event_frame
== frame
)
4143 dpyinfo
->x_focus_event_frame
= 0;
4144 x_new_focus_frame (dpyinfo
, 0);
4149 /* The focus may have changed. Figure out if it is a real focus change,
4150 by checking both FocusIn/Out and Enter/LeaveNotify events.
4152 Returns FOCUS_IN_EVENT event in *BUFP. */
4155 x_detect_focus_change (dpyinfo
, event
, bufp
)
4156 struct mac_display_info
*dpyinfo
;
4158 struct input_event
*bufp
;
4160 struct frame
*frame
;
4162 frame
= mac_window_to_frame ((WindowPtr
) event
->message
);
4166 /* On Mac, this is only called from focus events, so no switch needed. */
4167 mac_focus_changed ((event
->modifiers
& activeFlag
),
4168 dpyinfo
, frame
, bufp
);
4172 /* Handle an event saying the mouse has moved out of an Emacs frame. */
4175 x_mouse_leave (dpyinfo
)
4176 struct x_display_info
*dpyinfo
;
4178 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
4181 /* The focus has changed, or we have redirected a frame's focus to
4182 another frame (this happens when a frame uses a surrogate
4183 mini-buffer frame). Shift the highlight as appropriate.
4185 The FRAME argument doesn't necessarily have anything to do with which
4186 frame is being highlighted or un-highlighted; we only use it to find
4187 the appropriate X display info. */
4190 XTframe_rehighlight (frame
)
4191 struct frame
*frame
;
4193 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
4197 x_frame_rehighlight (dpyinfo
)
4198 struct x_display_info
*dpyinfo
;
4200 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
4202 if (dpyinfo
->x_focus_frame
)
4204 dpyinfo
->x_highlight_frame
4205 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
4206 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
4207 : dpyinfo
->x_focus_frame
);
4208 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
4210 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
4211 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
4215 dpyinfo
->x_highlight_frame
= 0;
4217 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
4220 frame_unhighlight (old_highlight
);
4221 if (dpyinfo
->x_highlight_frame
)
4222 frame_highlight (dpyinfo
->x_highlight_frame
);
4228 /* Convert a keysym to its name. */
4231 x_get_keysym_name (keysym
)
4238 value
= XKeysymToString (keysym
);
4249 /* Function to report a mouse movement to the mainstream Emacs code.
4250 The input handler calls this.
4252 We have received a mouse movement event, which is given in *event.
4253 If the mouse is over a different glyph than it was last time, tell
4254 the mainstream emacs code by setting mouse_moved. If not, ask for
4255 another motion event, so we can check again the next time it moves. */
4257 static Point last_mouse_motion_position
;
4258 static Lisp_Object last_mouse_motion_frame
;
4261 note_mouse_movement (frame
, pos
)
4265 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (frame
);
4266 #if TARGET_API_MAC_CARBON
4270 last_mouse_movement_time
= TickCount () * (1000 / 60); /* to milliseconds */
4271 last_mouse_motion_position
= *pos
;
4272 XSETFRAME (last_mouse_motion_frame
, frame
);
4274 #if TARGET_API_MAC_CARBON
4275 if (!PtInRect (*pos
, GetWindowPortBounds (FRAME_MAC_WINDOW (frame
), &r
)))
4277 if (!PtInRect (*pos
, &FRAME_MAC_WINDOW (frame
)->portRect
))
4280 if (frame
== dpyinfo
->mouse_face_mouse_frame
)
4281 /* This case corresponds to LeaveNotify in X11. */
4283 /* If we move outside the frame, then we're certainly no
4284 longer on any text in the frame. */
4285 clear_mouse_face (dpyinfo
);
4286 dpyinfo
->mouse_face_mouse_frame
= 0;
4287 if (!dpyinfo
->grabbed
)
4288 rif
->define_frame_cursor (frame
,
4289 frame
->output_data
.mac
->nontext_cursor
);
4293 /* Has the mouse moved off the glyph it was on at the last sighting? */
4294 if (frame
!= last_mouse_glyph_frame
4295 || !PtInRect (*pos
, &last_mouse_glyph
))
4297 frame
->mouse_moved
= 1;
4298 last_mouse_scroll_bar
= Qnil
;
4299 note_mouse_highlight (frame
, pos
->h
, pos
->v
);
4300 /* Remember which glyph we're now on. */
4301 remember_mouse_glyph (frame
, pos
->h
, pos
->v
, &last_mouse_glyph
);
4302 last_mouse_glyph_frame
= frame
;
4310 /************************************************************************
4312 ************************************************************************/
4314 /* MAC TODO: This should be called from somewhere (or removed) ++KFS */
4317 redo_mouse_highlight ()
4319 if (!NILP (last_mouse_motion_frame
)
4320 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
4321 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
4322 last_mouse_motion_position
.h
,
4323 last_mouse_motion_position
.v
);
4327 static struct frame
*
4328 mac_focus_frame (dpyinfo
)
4329 struct mac_display_info
*dpyinfo
;
4331 if (dpyinfo
->x_focus_frame
)
4332 return dpyinfo
->x_focus_frame
;
4334 /* Mac version may get events, such as a menu bar click, even when
4335 all the frames are invisible. In this case, we regard the
4336 event came to the selected frame. */
4337 return SELECTED_FRAME ();
4341 /* Return the current position of the mouse.
4342 *FP should be a frame which indicates which display to ask about.
4344 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
4345 and *PART to the frame, window, and scroll bar part that the mouse
4346 is over. Set *X and *Y to the portion and whole of the mouse's
4347 position on the scroll bar.
4349 If the mouse movement started elsewhere, set *FP to the frame the
4350 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
4353 Set *TIME to the server time-stamp for the time at which the mouse
4354 was at this position.
4356 Don't store anything if we don't have a valid set of values to report.
4358 This clears the mouse_moved flag, so we can wait for the next mouse
4362 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
4365 Lisp_Object
*bar_window
;
4366 enum scroll_bar_part
*part
;
4368 unsigned long *time
;
4374 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
4375 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
4378 Lisp_Object frame
, tail
;
4380 /* Clear the mouse-moved flag for every frame on this display. */
4381 FOR_EACH_FRAME (tail
, frame
)
4382 XFRAME (frame
)->mouse_moved
= 0;
4384 last_mouse_scroll_bar
= Qnil
;
4386 if (FRAME_MAC_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
4387 && FRAME_LIVE_P (last_mouse_frame
))
4388 f1
= last_mouse_frame
;
4390 f1
= mac_focus_frame (FRAME_MAC_DISPLAY_INFO (*fp
));
4394 /* Ok, we found a frame. Store all the values.
4395 last_mouse_glyph is a rectangle used to reduce the
4396 generation of mouse events. To not miss any motion
4397 events, we must divide the frame into rectangles of the
4398 size of the smallest character that could be displayed
4399 on it, i.e. into the same rectangles that matrices on
4400 the frame are divided into. */
4403 SetPortWindowPort (FRAME_MAC_WINDOW (f1
));
4404 GetMouse (&mouse_pos
);
4405 remember_mouse_glyph (f1
, mouse_pos
.h
, mouse_pos
.v
,
4407 last_mouse_glyph_frame
= f1
;
4412 XSETINT (*x
, mouse_pos
.h
);
4413 XSETINT (*y
, mouse_pos
.v
);
4414 *time
= last_mouse_movement_time
;
4422 /************************************************************************
4424 ************************************************************************/
4426 #ifdef USE_TOOLKIT_SCROLL_BARS
4428 static pascal void scroll_bar_timer_callback
P_ ((EventLoopTimerRef
, void *));
4429 static OSStatus install_scroll_bar_timer
P_ ((void));
4430 static OSStatus set_scroll_bar_timer
P_ ((EventTimerInterval
));
4431 static int control_part_code_to_scroll_bar_part
P_ ((ControlPartCode
));
4432 static void construct_scroll_bar_click
P_ ((struct scroll_bar
*, int,
4433 struct input_event
*));
4434 static OSStatus get_control_part_bounds
P_ ((ControlHandle
, ControlPartCode
,
4436 static void x_scroll_bar_handle_press
P_ ((struct scroll_bar
*,
4438 struct input_event
*));
4439 static void x_scroll_bar_handle_release
P_ ((struct scroll_bar
*,
4440 struct input_event
*));
4441 static void x_scroll_bar_handle_drag
P_ ((WindowPtr
, struct scroll_bar
*,
4442 Point
, struct input_event
*));
4443 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
4446 /* Last scroll bar part sent in x_scroll_bar_handle_*. */
4448 static int last_scroll_bar_part
;
4450 static EventLoopTimerRef scroll_bar_timer
;
4452 static int scroll_bar_timer_event_posted_p
;
4454 #define SCROLL_BAR_FIRST_DELAY 0.5
4455 #define SCROLL_BAR_CONTINUOUS_DELAY (1.0 / 15)
4458 scroll_bar_timer_callback (timer
, data
)
4459 EventLoopTimerRef timer
;
4464 err
= mac_post_mouse_moved_event ();
4466 scroll_bar_timer_event_posted_p
= 1;
4470 install_scroll_bar_timer ()
4472 static EventLoopTimerUPP scroll_bar_timer_callbackUPP
= NULL
;
4474 if (scroll_bar_timer_callbackUPP
== NULL
)
4475 scroll_bar_timer_callbackUPP
=
4476 NewEventLoopTimerUPP (scroll_bar_timer_callback
);
4478 if (scroll_bar_timer
== NULL
)
4479 /* Mac OS X and CarbonLib 1.5 and later allow us to specify
4480 kEventDurationForever as delays. */
4482 InstallEventLoopTimer (GetCurrentEventLoop (),
4483 kEventDurationForever
, kEventDurationForever
,
4484 scroll_bar_timer_callbackUPP
, NULL
,
4489 set_scroll_bar_timer (delay
)
4490 EventTimerInterval delay
;
4492 if (scroll_bar_timer
== NULL
)
4493 install_scroll_bar_timer ();
4495 scroll_bar_timer_event_posted_p
= 0;
4497 return SetEventLoopTimerNextFireTime (scroll_bar_timer
, delay
);
4501 control_part_code_to_scroll_bar_part (part_code
)
4502 ControlPartCode part_code
;
4506 case kControlUpButtonPart
: return scroll_bar_up_arrow
;
4507 case kControlDownButtonPart
: return scroll_bar_down_arrow
;
4508 case kControlPageUpPart
: return scroll_bar_above_handle
;
4509 case kControlPageDownPart
: return scroll_bar_below_handle
;
4510 case kControlIndicatorPart
: return scroll_bar_handle
;
4517 construct_scroll_bar_click (bar
, part
, bufp
)
4518 struct scroll_bar
*bar
;
4520 struct input_event
*bufp
;
4522 bufp
->kind
= SCROLL_BAR_CLICK_EVENT
;
4523 bufp
->frame_or_window
= bar
->window
;
4527 XSETINT (bufp
->x
, 0);
4528 XSETINT (bufp
->y
, 0);
4529 bufp
->modifiers
= 0;
4533 get_control_part_bounds (ch
, part_code
, rect
)
4535 ControlPartCode part_code
;
4538 RgnHandle region
= NewRgn ();
4541 err
= GetControlRegion (ch
, part_code
, region
);
4543 GetRegionBounds (region
, rect
);
4544 DisposeRgn (region
);
4550 x_scroll_bar_handle_press (bar
, part_code
, bufp
)
4551 struct scroll_bar
*bar
;
4552 ControlPartCode part_code
;
4553 struct input_event
*bufp
;
4555 int part
= control_part_code_to_scroll_bar_part (part_code
);
4560 if (part
!= scroll_bar_handle
)
4562 construct_scroll_bar_click (bar
, part
, bufp
);
4563 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), part_code
);
4564 set_scroll_bar_timer (SCROLL_BAR_FIRST_DELAY
);
4567 last_scroll_bar_part
= part
;
4568 bar
->dragging
= Qnil
;
4569 tracked_scroll_bar
= bar
;
4573 x_scroll_bar_handle_release (bar
, bufp
)
4574 struct scroll_bar
*bar
;
4575 struct input_event
*bufp
;
4577 if (last_scroll_bar_part
!= scroll_bar_handle
4578 || !GC_NILP (bar
->dragging
))
4579 construct_scroll_bar_click (bar
, scroll_bar_end_scroll
, bufp
);
4581 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), 0);
4582 set_scroll_bar_timer (kEventDurationForever
);
4584 last_scroll_bar_part
= -1;
4585 bar
->dragging
= Qnil
;
4586 tracked_scroll_bar
= NULL
;
4590 x_scroll_bar_handle_drag (win
, bar
, mouse_pos
, bufp
)
4592 struct scroll_bar
*bar
;
4594 struct input_event
*bufp
;
4596 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4598 if (last_scroll_bar_part
== scroll_bar_handle
)
4603 get_control_part_bounds (SCROLL_BAR_CONTROL_HANDLE (bar
),
4604 kControlIndicatorPart
, &r
);
4606 if (GC_NILP (bar
->dragging
))
4607 XSETINT (bar
->dragging
, mouse_pos
.v
- r
.top
);
4609 top
= mouse_pos
.v
- XINT (bar
->dragging
) - XINT (bar
->track_top
);
4610 top_range
= (XINT (bar
->track_height
) - (r
.bottom
- r
.top
)) *
4611 (1.0 + (float) GetControlViewSize (ch
) / GetControl32BitMaximum (ch
))
4616 if (top
> top_range
)
4619 construct_scroll_bar_click (bar
, scroll_bar_handle
, bufp
);
4620 XSETINT (bufp
->x
, top
);
4621 XSETINT (bufp
->y
, top_range
);
4625 ControlPartCode part_code
;
4626 int unhilite_p
= 0, part
;
4628 if (ch
!= FindControlUnderMouse (mouse_pos
, win
, &part_code
))
4632 part
= control_part_code_to_scroll_bar_part (part_code
);
4634 switch (last_scroll_bar_part
)
4636 case scroll_bar_above_handle
:
4637 case scroll_bar_below_handle
:
4638 if (part
!= scroll_bar_above_handle
4639 && part
!= scroll_bar_below_handle
)
4643 case scroll_bar_up_arrow
:
4644 case scroll_bar_down_arrow
:
4645 if (part
!= scroll_bar_up_arrow
4646 && part
!= scroll_bar_down_arrow
)
4653 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), 0);
4654 else if (part
!= last_scroll_bar_part
4655 || scroll_bar_timer_event_posted_p
)
4657 construct_scroll_bar_click (bar
, part
, bufp
);
4658 last_scroll_bar_part
= part
;
4659 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), part_code
);
4660 set_scroll_bar_timer (SCROLL_BAR_CONTINUOUS_DELAY
);
4665 /* Set the thumb size and position of scroll bar BAR. We are currently
4666 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4669 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4670 struct scroll_bar
*bar
;
4671 int portion
, position
, whole
;
4673 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4674 int value
, viewsize
, maximum
;
4676 if (XINT (bar
->track_height
) == 0)
4680 value
= 0, viewsize
= 1, maximum
= 0;
4685 maximum
= max (0, whole
- portion
);
4690 if (GetControlViewSize (ch
) != viewsize
4691 || GetControl32BitValue (ch
) != value
4692 || GetControl32BitMaximum (ch
) != maximum
)
4694 /* Temporarily hide the scroll bar to avoid multiple redraws. */
4695 SetControlVisibility (ch
, false, false);
4697 SetControl32BitMaximum (ch
, maximum
);
4698 SetControl32BitValue (ch
, value
);
4699 SetControlViewSize (ch
, viewsize
);
4701 SetControlVisibility (ch
, true, true);
4707 #endif /* USE_TOOLKIT_SCROLL_BARS */
4711 /************************************************************************
4712 Scroll bars, general
4713 ************************************************************************/
4715 /* Create a scroll bar and return the scroll bar vector for it. W is
4716 the Emacs window on which to create the scroll bar. TOP, LEFT,
4717 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4720 static struct scroll_bar
*
4721 x_scroll_bar_create (w
, top
, left
, width
, height
, disp_top
, disp_height
)
4723 int top
, left
, width
, height
, disp_top
, disp_height
;
4725 struct frame
*f
= XFRAME (w
->frame
);
4726 struct scroll_bar
*bar
4727 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
4735 r
.right
= left
+ width
;
4736 r
.bottom
= disp_top
+ disp_height
;
4739 mac_prepare_for_quickdraw (f
);
4741 #if TARGET_API_MAC_CARBON
4742 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p",
4743 #if USE_TOOLKIT_SCROLL_BARS
4746 width
< disp_height
,
4748 0, 0, 0, kControlScrollBarProc
, (long) bar
);
4750 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p", width
< disp_height
,
4751 0, 0, 0, scrollBarProc
, (long) bar
);
4753 SET_SCROLL_BAR_CONTROL_HANDLE (bar
, ch
);
4755 XSETWINDOW (bar
->window
, w
);
4756 XSETINT (bar
->top
, top
);
4757 XSETINT (bar
->left
, left
);
4758 XSETINT (bar
->width
, width
);
4759 XSETINT (bar
->height
, height
);
4760 XSETINT (bar
->start
, 0);
4761 XSETINT (bar
->end
, 0);
4762 bar
->dragging
= Qnil
;
4763 #ifdef USE_TOOLKIT_SCROLL_BARS
4764 bar
->track_top
= Qnil
;
4765 bar
->track_height
= Qnil
;
4768 /* Add bar to its frame's list of scroll bars. */
4769 bar
->next
= FRAME_SCROLL_BARS (f
);
4771 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4772 if (!NILP (bar
->next
))
4773 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4780 /* Draw BAR's handle in the proper position.
4782 If the handle is already drawn from START to END, don't bother
4783 redrawing it, unless REBUILD is non-zero; in that case, always
4784 redraw it. (REBUILD is handy for drawing the handle after expose
4787 Normally, we want to constrain the start and end of the handle to
4788 fit inside its rectangle, but if the user is dragging the scroll
4789 bar handle, we want to let them drag it down all the way, so that
4790 the bar's top is as far down as it goes; otherwise, there's no way
4791 to move to the very end of the buffer. */
4793 #ifndef USE_TOOLKIT_SCROLL_BARS
4796 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
4797 struct scroll_bar
*bar
;
4801 int dragging
= ! NILP (bar
->dragging
);
4802 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4803 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4804 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
4805 int length
= end
- start
;
4807 /* If the display is already accurate, do nothing. */
4809 && start
== XINT (bar
->start
)
4810 && end
== XINT (bar
->end
))
4815 /* Make sure the values are reasonable, and try to preserve the
4816 distance between start and end. */
4819 else if (start
> top_range
)
4821 end
= start
+ length
;
4825 else if (end
> top_range
&& ! dragging
)
4828 /* Store the adjusted setting in the scroll bar. */
4829 XSETINT (bar
->start
, start
);
4830 XSETINT (bar
->end
, end
);
4832 /* Clip the end position, just for display. */
4833 if (end
> top_range
)
4836 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
4837 top positions, to make sure the handle is always at least that
4838 many pixels tall. */
4839 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4841 SetControlMinimum (ch
, 0);
4842 /* Don't inadvertently activate deactivated scroll bars */
4843 if (GetControlMaximum (ch
) != -1)
4844 SetControlMaximum (ch
, top_range
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
4846 SetControlValue (ch
, start
);
4847 #if TARGET_API_MAC_CARBON
4848 SetControlViewSize (ch
, end
- start
);
4854 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4856 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4860 x_scroll_bar_remove (bar
)
4861 struct scroll_bar
*bar
;
4863 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4868 mac_prepare_for_quickdraw (f
);
4870 /* Destroy the Mac scroll bar control */
4871 DisposeControl (SCROLL_BAR_CONTROL_HANDLE (bar
));
4873 /* Disassociate this scroll bar from its window. */
4874 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
4880 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4881 that we are displaying PORTION characters out of a total of WHOLE
4882 characters, starting at POSITION. If WINDOW has no scroll bar,
4886 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
4888 int portion
, whole
, position
;
4890 struct frame
*f
= XFRAME (w
->frame
);
4891 struct scroll_bar
*bar
;
4892 int top
, height
, left
, sb_left
, width
, sb_width
, disp_top
, disp_height
;
4893 int window_y
, window_height
;
4895 /* Get window dimensions. */
4896 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
4898 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
4899 height
= window_height
;
4901 /* Compute the left edge of the scroll bar area. */
4902 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
4904 /* Compute the width of the scroll bar which might be less than
4905 the width of the area reserved for the scroll bar. */
4906 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
4907 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
4911 /* Compute the left edge of the scroll bar. */
4912 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
4915 sb_left
= left
+ width
- sb_width
;
4917 /* Adjustments according to Inside Macintosh to make it look nice */
4919 disp_height
= height
;
4926 else if (disp_top
== FRAME_PIXEL_HEIGHT (f
) - 16)
4932 if (sb_left
+ sb_width
== FRAME_PIXEL_WIDTH (f
))
4936 /* Does the scroll bar exist yet? */
4937 if (NILP (w
->vertical_scroll_bar
))
4940 mac_clear_area (f
, left
, top
, width
, height
);
4942 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
, disp_top
,
4944 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
4948 /* It may just need to be moved and resized. */
4951 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
4952 ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4956 /* If already correctly positioned, do nothing. */
4957 if (!(XINT (bar
->left
) == sb_left
4958 && XINT (bar
->top
) == top
4959 && XINT (bar
->width
) == sb_width
4960 && XINT (bar
->height
) == height
))
4962 /* Since toolkit scroll bars are smaller than the space reserved
4963 for them on the frame, we have to clear "under" them. */
4964 mac_clear_area (f
, left
, top
, width
, height
);
4967 mac_prepare_for_quickdraw (f
);
4970 MoveControl (ch
, sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
, disp_top
);
4971 SizeControl (ch
, sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4973 #ifndef USE_TOOLKIT_SCROLL_BARS
4974 if (sb_width
< disp_height
)
4978 /* Remember new settings. */
4979 XSETINT (bar
->left
, sb_left
);
4980 XSETINT (bar
->top
, top
);
4981 XSETINT (bar
->width
, sb_width
);
4982 XSETINT (bar
->height
, height
);
4983 #ifdef USE_TOOLKIT_SCROLL_BARS
4984 bar
->track_top
= Qnil
;
4985 bar
->track_height
= Qnil
;
4992 #ifdef USE_TOOLKIT_SCROLL_BARS
4993 if (NILP (bar
->track_top
))
4995 if (sb_width
>= disp_height
)
4997 XSETINT (bar
->track_top
, 0);
4998 XSETINT (bar
->track_height
, 0);
5002 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
5007 SetControl32BitMinimum (ch
, 0);
5008 SetControl32BitMaximum (ch
, 1);
5009 SetControlViewSize (ch
, 1);
5011 /* Move the scroll bar thumb to the top. */
5012 SetControl32BitValue (ch
, 0);
5013 get_control_part_bounds (ch
, kControlIndicatorPart
, &r0
);
5015 /* Move the scroll bar thumb to the bottom. */
5016 SetControl32BitValue (ch
, 1);
5017 get_control_part_bounds (ch
, kControlIndicatorPart
, &r1
);
5019 UnionRect (&r0
, &r1
, &r0
);
5020 XSETINT (bar
->track_top
, r0
.top
);
5021 XSETINT (bar
->track_height
, r0
.bottom
- r0
.top
);
5023 /* Don't show the scroll bar if its height is not enough to
5024 display the scroll bar thumb. */
5025 if (r0
.bottom
- r0
.top
> 0)
5032 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5033 #else /* not USE_TOOLKIT_SCROLL_BARS */
5034 /* Set the scroll bar's current state, unless we're currently being
5036 if (NILP (bar
->dragging
))
5038 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5041 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5044 int start
= ((double) position
* top_range
) / whole
;
5045 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5046 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5049 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5053 /* The following three hooks are used when we're doing a thorough
5054 redisplay of the frame. We don't explicitly know which scroll bars
5055 are going to be deleted, because keeping track of when windows go
5056 away is a real pain - "Can you say set-window-configuration, boys
5057 and girls?" Instead, we just assert at the beginning of redisplay
5058 that *all* scroll bars are to be removed, and then save a scroll bar
5059 from the fiery pit when we actually redisplay its window. */
5061 /* Arrange for all scroll bars on FRAME to be removed at the next call
5062 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5063 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5066 XTcondemn_scroll_bars (frame
)
5069 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5070 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5073 bar
= FRAME_SCROLL_BARS (frame
);
5074 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5075 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5076 XSCROLL_BAR (bar
)->prev
= Qnil
;
5077 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5078 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5079 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5084 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5085 Note that WINDOW isn't necessarily condemned at all. */
5088 XTredeem_scroll_bar (window
)
5089 struct window
*window
;
5091 struct scroll_bar
*bar
;
5094 /* We can't redeem this window's scroll bar if it doesn't have one. */
5095 if (NILP (window
->vertical_scroll_bar
))
5098 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5100 /* Unlink it from the condemned list. */
5101 f
= XFRAME (WINDOW_FRAME (window
));
5102 if (NILP (bar
->prev
))
5104 /* If the prev pointer is nil, it must be the first in one of
5106 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5107 /* It's not condemned. Everything's fine. */
5109 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5110 window
->vertical_scroll_bar
))
5111 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5113 /* If its prev pointer is nil, it must be at the front of
5114 one or the other! */
5118 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5120 if (! NILP (bar
->next
))
5121 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5123 bar
->next
= FRAME_SCROLL_BARS (f
);
5125 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5126 if (! NILP (bar
->next
))
5127 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5130 /* Remove all scroll bars on FRAME that haven't been saved since the
5131 last call to `*condemn_scroll_bars_hook'. */
5134 XTjudge_scroll_bars (f
)
5137 Lisp_Object bar
, next
;
5139 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5141 /* Clear out the condemned list now so we won't try to process any
5142 more events on the hapless scroll bars. */
5143 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5145 for (; ! NILP (bar
); bar
= next
)
5147 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5149 x_scroll_bar_remove (b
);
5152 b
->next
= b
->prev
= Qnil
;
5155 /* Now there should be no references to the condemned scroll bars,
5156 and they should get garbage-collected. */
5160 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5161 is set to something other than NO_EVENT, it is enqueued.
5163 This may be called from a signal handler, so we have to ignore GC
5167 x_scroll_bar_handle_click (bar
, part_code
, er
, bufp
)
5168 struct scroll_bar
*bar
;
5169 ControlPartCode part_code
;
5171 struct input_event
*bufp
;
5173 int win_y
, top_range
;
5175 if (! GC_WINDOWP (bar
->window
))
5178 bufp
->kind
= SCROLL_BAR_CLICK_EVENT
;
5179 bufp
->frame_or_window
= bar
->window
;
5182 bar
->dragging
= Qnil
;
5186 case kControlUpButtonPart
:
5187 bufp
->part
= scroll_bar_up_arrow
;
5189 case kControlDownButtonPart
:
5190 bufp
->part
= scroll_bar_down_arrow
;
5192 case kControlPageUpPart
:
5193 bufp
->part
= scroll_bar_above_handle
;
5195 case kControlPageDownPart
:
5196 bufp
->part
= scroll_bar_below_handle
;
5198 #if TARGET_API_MAC_CARBON
5201 case kControlIndicatorPart
:
5203 if (er
->what
== mouseDown
)
5204 bar
->dragging
= make_number (0);
5205 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5206 bufp
->part
= scroll_bar_handle
;
5210 win_y
= XINT (bufp
->y
) - XINT (bar
->top
);
5211 top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (0/*dummy*/, XINT (bar
->height
));
5213 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5217 if (! NILP (bar
->dragging
))
5218 win_y
-= XINT (bar
->dragging
);
5222 if (win_y
> top_range
)
5225 XSETINT (bufp
->x
, win_y
);
5226 XSETINT (bufp
->y
, top_range
);
5229 #ifndef USE_TOOLKIT_SCROLL_BARS
5231 /* Handle some mouse motion while someone is dragging the scroll bar.
5233 This may be called from a signal handler, so we have to ignore GC
5237 x_scroll_bar_note_movement (bar
, y_pos
, t
)
5238 struct scroll_bar
*bar
;
5242 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5244 last_mouse_movement_time
= t
;
5247 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5249 /* If we're dragging the bar, display it. */
5250 if (! GC_NILP (bar
->dragging
))
5252 /* Where should the handle be now? */
5253 int new_start
= y_pos
- 24;
5255 if (new_start
!= XINT (bar
->start
))
5257 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
5259 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5264 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5266 /* Return information to the user about the current position of the mouse
5267 on the scroll bar. */
5270 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
5272 Lisp_Object
*bar_window
;
5273 enum scroll_bar_part
*part
;
5275 unsigned long *time
;
5277 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5278 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
5279 #if TARGET_API_MAC_CARBON
5280 WindowPtr wp
= GetControlOwner (ch
);
5282 WindowPtr wp
= (*ch
)->contrlOwner
;
5285 struct frame
*f
= mac_window_to_frame (wp
);
5286 int win_y
, top_range
;
5288 SetPortWindowPort (wp
);
5290 GetMouse (&mouse_pos
);
5292 win_y
= mouse_pos
.v
- XINT (bar
->top
);
5293 top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
5295 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5299 if (! NILP (bar
->dragging
))
5300 win_y
-= XINT (bar
->dragging
);
5304 if (win_y
> top_range
)
5308 *bar_window
= bar
->window
;
5310 if (! NILP (bar
->dragging
))
5311 *part
= scroll_bar_handle
;
5312 else if (win_y
< XINT (bar
->start
))
5313 *part
= scroll_bar_above_handle
;
5314 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5315 *part
= scroll_bar_handle
;
5317 *part
= scroll_bar_below_handle
;
5319 XSETINT (*x
, win_y
);
5320 XSETINT (*y
, top_range
);
5323 last_mouse_scroll_bar
= Qnil
;
5325 *time
= last_mouse_movement_time
;
5329 /* The screen has been cleared so we may have changed foreground or
5330 background colors, and the scroll bars may need to be redrawn.
5331 Clear out the scroll bars, and ask for expose events, so we can
5335 x_scroll_bar_clear (f
)
5338 XTcondemn_scroll_bars (f
);
5339 XTjudge_scroll_bars (f
);
5343 /***********************************************************************
5345 ***********************************************************************/
5347 /* Set clipping for output in glyph row ROW. W is the window in which
5348 we operate. GC is the graphics context to set clipping in.
5350 ROW may be a text row or, e.g., a mode line. Text rows must be
5351 clipped to the interior of the window dedicated to text display,
5352 mode lines must be clipped to the whole window. */
5355 x_clip_to_row (w
, row
, area
, gc
)
5357 struct glyph_row
*row
;
5361 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5363 int window_x
, window_y
, window_width
;
5365 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
5367 clip_rect
.left
= window_x
;
5368 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
5369 clip_rect
.top
= max (clip_rect
.top
, window_y
);
5370 clip_rect
.right
= clip_rect
.left
+ window_width
;
5371 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
5373 mac_set_clip_rectangles (FRAME_MAC_DISPLAY (f
), gc
, &clip_rect
, 1);
5377 /* Draw a hollow box cursor on window W in glyph row ROW. */
5380 x_draw_hollow_cursor (w
, row
)
5382 struct glyph_row
*row
;
5384 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5385 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
5386 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
5389 struct glyph
*cursor_glyph
;
5392 /* Get the glyph the cursor is on. If we can't tell because
5393 the current matrix is invalid or such, give up. */
5394 cursor_glyph
= get_phys_cursor_glyph (w
);
5395 if (cursor_glyph
== NULL
)
5398 /* Compute frame-relative coordinates for phys cursor. */
5399 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
5400 y
= get_phys_cursor_geometry (w
, row
, cursor_glyph
, &h
);
5401 wd
= w
->phys_cursor_width
;
5403 /* The foreground of cursor_gc is typically the same as the normal
5404 background color, which can cause the cursor box to be invisible. */
5405 xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
5406 if (dpyinfo
->scratch_cursor_gc
)
5407 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
5409 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_MAC_WINDOW (f
),
5410 GCForeground
, &xgcv
);
5411 gc
= dpyinfo
->scratch_cursor_gc
;
5413 /* Set clipping, draw the rectangle, and reset clipping again. */
5414 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
5415 mac_draw_rectangle (f
, gc
, x
, y
, wd
, h
- 1);
5416 mac_reset_clip_rectangles (dpy
, gc
);
5420 /* Draw a bar cursor on window W in glyph row ROW.
5422 Implementation note: One would like to draw a bar cursor with an
5423 angle equal to the one given by the font property XA_ITALIC_ANGLE.
5424 Unfortunately, I didn't find a font yet that has this property set.
5428 x_draw_bar_cursor (w
, row
, width
, kind
)
5430 struct glyph_row
*row
;
5432 enum text_cursor_kinds kind
;
5434 struct frame
*f
= XFRAME (w
->frame
);
5435 struct glyph
*cursor_glyph
;
5437 /* If cursor is out of bounds, don't draw garbage. This can happen
5438 in mini-buffer windows when switching between echo area glyphs
5440 cursor_glyph
= get_phys_cursor_glyph (w
);
5441 if (cursor_glyph
== NULL
)
5444 /* If on an image, draw like a normal cursor. That's usually better
5445 visible than drawing a bar, esp. if the image is large so that
5446 the bar might not be in the window. */
5447 if (cursor_glyph
->type
== IMAGE_GLYPH
)
5449 struct glyph_row
*row
;
5450 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
5451 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
5455 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
5456 Window window
= FRAME_MAC_WINDOW (f
);
5457 GC gc
= FRAME_MAC_DISPLAY_INFO (f
)->scratch_cursor_gc
;
5458 unsigned long mask
= GCForeground
| GCBackground
;
5459 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
5462 /* If the glyph's background equals the color we normally draw
5463 the bar cursor in, the bar cursor in its normal color is
5464 invisible. Use the glyph's foreground color instead in this
5465 case, on the assumption that the glyph's colors are chosen so
5466 that the glyph is legible. */
5467 if (face
->background
== f
->output_data
.mac
->cursor_pixel
)
5468 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
5470 xgcv
.background
= xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
5473 XChangeGC (dpy
, gc
, mask
, &xgcv
);
5476 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
5477 FRAME_MAC_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
5481 width
= FRAME_CURSOR_WIDTH (f
);
5482 width
= min (cursor_glyph
->pixel_width
, width
);
5484 w
->phys_cursor_width
= width
;
5485 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
5487 if (kind
== BAR_CURSOR
)
5488 mac_fill_rectangle (f
, gc
,
5489 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
5490 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
5491 width
, row
->height
);
5493 mac_fill_rectangle (f
, gc
,
5494 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
5495 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
5496 row
->height
- width
),
5497 cursor_glyph
->pixel_width
,
5500 mac_reset_clip_rectangles (dpy
, gc
);
5505 /* RIF: Define cursor CURSOR on frame F. */
5508 mac_define_frame_cursor (f
, cursor
)
5512 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
5514 if (dpyinfo
->x_focus_frame
== f
)
5515 SetThemeCursor (cursor
);
5519 /* RIF: Clear area on frame F. */
5522 mac_clear_frame_area (f
, x
, y
, width
, height
)
5524 int x
, y
, width
, height
;
5526 mac_clear_area (f
, x
, y
, width
, height
);
5530 /* RIF: Draw cursor on window W. */
5533 mac_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
5535 struct glyph_row
*glyph_row
;
5537 int cursor_type
, cursor_width
;
5542 w
->phys_cursor_type
= cursor_type
;
5543 w
->phys_cursor_on_p
= 1;
5545 if (glyph_row
->exact_window_width_line_p
5546 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
5548 glyph_row
->cursor_in_fringe_p
= 1;
5549 draw_fringe_bitmap (w
, glyph_row
, 0);
5552 switch (cursor_type
)
5554 case HOLLOW_BOX_CURSOR
:
5555 x_draw_hollow_cursor (w
, glyph_row
);
5558 case FILLED_BOX_CURSOR
:
5559 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
5563 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
5567 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
5571 w
->phys_cursor_width
= 0;
5583 #if 0 /* MAC_TODO: no icon support yet. */
5585 x_bitmap_icon (f
, icon
)
5591 if (FRAME_W32_WINDOW (f
) == 0)
5595 hicon
= LoadIcon (hinst
, EMACS_CLASS
);
5596 else if (STRINGP (icon
))
5597 hicon
= LoadImage (NULL
, (LPCTSTR
) SDATA (icon
), IMAGE_ICON
, 0, 0,
5598 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
5599 else if (SYMBOLP (icon
))
5603 if (EQ (icon
, intern ("application")))
5604 name
= (LPCTSTR
) IDI_APPLICATION
;
5605 else if (EQ (icon
, intern ("hand")))
5606 name
= (LPCTSTR
) IDI_HAND
;
5607 else if (EQ (icon
, intern ("question")))
5608 name
= (LPCTSTR
) IDI_QUESTION
;
5609 else if (EQ (icon
, intern ("exclamation")))
5610 name
= (LPCTSTR
) IDI_EXCLAMATION
;
5611 else if (EQ (icon
, intern ("asterisk")))
5612 name
= (LPCTSTR
) IDI_ASTERISK
;
5613 else if (EQ (icon
, intern ("winlogo")))
5614 name
= (LPCTSTR
) IDI_WINLOGO
;
5618 hicon
= LoadIcon (NULL
, name
);
5626 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
5631 #endif /* MAC_TODO */
5633 /************************************************************************
5635 ************************************************************************/
5637 /* Display Error Handling functions not used on W32. Listing them here
5638 helps diff stay in step when comparing w32term.c with xterm.c.
5640 x_error_catcher (display, error)
5641 x_catch_errors (dpy)
5642 x_catch_errors_unwind (old_val)
5643 x_check_errors (dpy, format)
5644 x_had_errors_p (dpy)
5645 x_clear_errors (dpy)
5646 x_uncatch_errors (dpy, count)
5648 x_connection_signal (signalnum)
5649 x_connection_closed (dpy, error_message)
5650 x_error_quitter (display, error)
5651 x_error_handler (display, error)
5652 x_io_error_quitter (display)
5657 /* Changing the font of the frame. */
5659 /* Give frame F the font named FONTNAME as its default font, and
5660 return the full name of that font. FONTNAME may be a wildcard
5661 pattern; in that case, we choose some font that fits the pattern.
5662 The return value shows which font we chose. */
5665 x_new_font (f
, fontname
)
5667 register char *fontname
;
5669 struct font_info
*fontp
5670 = FS_LOAD_FONT (f
, 0, fontname
, -1);
5675 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
5676 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
5677 FRAME_FONTSET (f
) = -1;
5679 FRAME_COLUMN_WIDTH (f
) = fontp
->average_width
;
5680 FRAME_SPACE_WIDTH (f
) = fontp
->space_width
;
5681 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (FRAME_FONT (f
));
5683 compute_fringe_widths (f
, 1);
5685 /* Compute the scroll bar width in character columns. */
5686 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
5688 int wid
= FRAME_COLUMN_WIDTH (f
);
5689 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
5690 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
5694 int wid
= FRAME_COLUMN_WIDTH (f
);
5695 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
5698 /* Now make the frame display the given font. */
5699 if (FRAME_MAC_WINDOW (f
) != 0)
5701 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->normal_gc
,
5703 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->reverse_gc
,
5705 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->cursor_gc
,
5708 /* Don't change the size of a tip frame; there's no point in
5709 doing it because it's done in Fx_show_tip, and it leads to
5710 problems because the tip frame has no widget. */
5711 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
5712 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
5715 return build_string (fontp
->full_name
);
5718 /* Give frame F the fontset named FONTSETNAME as its default font, and
5719 return the full name of that fontset. FONTSETNAME may be a wildcard
5720 pattern; in that case, we choose some fontset that fits the pattern.
5721 The return value shows which fontset we chose. */
5724 x_new_fontset (f
, fontsetname
)
5728 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
5734 if (FRAME_FONTSET (f
) == fontset
)
5735 /* This fontset is already set in frame F. There's nothing more
5737 return fontset_name (fontset
);
5739 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
5741 if (!STRINGP (result
))
5742 /* Can't load ASCII font. */
5745 /* Since x_new_font doesn't update any fontset information, do it now. */
5746 FRAME_FONTSET (f
) = fontset
;
5748 return build_string (fontsetname
);
5752 /***********************************************************************
5753 TODO: W32 Input Methods
5754 ***********************************************************************/
5755 /* Listing missing functions from xterm.c helps diff stay in step.
5757 xim_destroy_callback (xim, client_data, call_data)
5758 xim_open_dpy (dpyinfo, resource_name)
5760 xim_instantiate_callback (display, client_data, call_data)
5761 xim_initialize (dpyinfo, resource_name)
5762 xim_close_dpy (dpyinfo)
5768 mac_get_window_bounds (f
, inner
, outer
)
5770 Rect
*inner
, *outer
;
5772 #if TARGET_API_MAC_CARBON
5773 GetWindowBounds (FRAME_MAC_WINDOW (f
), kWindowContentRgn
, inner
);
5774 GetWindowBounds (FRAME_MAC_WINDOW (f
), kWindowStructureRgn
, outer
);
5775 #else /* not TARGET_API_MAC_CARBON */
5776 RgnHandle region
= NewRgn ();
5778 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowContentRgn
, region
);
5779 *inner
= (*region
)->rgnBBox
;
5780 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowStructureRgn
, region
);
5781 *outer
= (*region
)->rgnBBox
;
5782 DisposeRgn (region
);
5783 #endif /* not TARGET_API_MAC_CARBON */
5788 /* Calculate the absolute position in frame F
5789 from its current recorded position values and gravity. */
5792 x_calc_absolute_position (f
)
5795 int width_diff
= 0, height_diff
= 0;
5796 int flags
= f
->size_hint_flags
;
5799 /* We have nothing to do if the current position
5800 is already for the top-left corner. */
5801 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
5804 /* Find the offsets of the outside upper-left corner of
5805 the inner window, with respect to the outer window. */
5806 mac_get_window_bounds (f
, &inner
, &outer
);
5808 width_diff
= (outer
.right
- outer
.left
) - (inner
.right
- inner
.left
);
5809 height_diff
= (outer
.bottom
- outer
.top
) - (inner
.bottom
- inner
.top
);
5811 /* Treat negative positions as relative to the leftmost bottommost
5812 position that fits on the screen. */
5813 if (flags
& XNegative
)
5814 f
->left_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->width
5816 - FRAME_PIXEL_WIDTH (f
)
5819 if (flags
& YNegative
)
5820 f
->top_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->height
5822 - FRAME_PIXEL_HEIGHT (f
)
5825 /* The left_pos and top_pos
5826 are now relative to the top and left screen edges,
5827 so the flags should correspond. */
5828 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5831 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
5832 to really change the position, and 0 when calling from
5833 x_make_frame_visible (in that case, XOFF and YOFF are the current
5834 position values). It is -1 when calling from x_set_frame_parameters,
5835 which means, do adjust for borders but don't change the gravity. */
5838 x_set_offset (f
, xoff
, yoff
, change_gravity
)
5840 register int xoff
, yoff
;
5843 if (change_gravity
> 0)
5847 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5849 f
->size_hint_flags
|= XNegative
;
5851 f
->size_hint_flags
|= YNegative
;
5852 f
->win_gravity
= NorthWestGravity
;
5854 x_calc_absolute_position (f
);
5857 x_wm_set_size_hint (f
, (long) 0, 0);
5859 #if TARGET_API_MAC_CARBON
5860 MoveWindowStructure (FRAME_MAC_WINDOW (f
), f
->left_pos
, f
->top_pos
);
5861 /* If the title bar is completely outside the screen, adjust the
5863 ConstrainWindowToScreen (FRAME_MAC_WINDOW (f
), kWindowTitleBarRgn
,
5864 kWindowConstrainMoveRegardlessOfFit
5865 | kWindowConstrainAllowPartial
, NULL
, NULL
);
5866 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
5869 Rect inner
, outer
, screen_rect
, dummy
;
5870 RgnHandle region
= NewRgn ();
5872 mac_get_window_bounds (f
, &inner
, &outer
);
5873 f
->x_pixels_diff
= inner
.left
- outer
.left
;
5874 f
->y_pixels_diff
= inner
.top
- outer
.top
;
5875 MoveWindow (FRAME_MAC_WINDOW (f
), f
->left_pos
+ f
->x_pixels_diff
,
5876 f
->top_pos
+ f
->y_pixels_diff
, false);
5878 /* If the title bar is completely outside the screen, adjust the
5879 position. The variable `outer' holds the title bar rectangle.
5880 The variable `inner' holds slightly smaller one than `outer',
5881 so that the calculation of overlapping may not become too
5883 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowTitleBarRgn
, region
);
5884 outer
= (*region
)->rgnBBox
;
5885 DisposeRgn (region
);
5887 InsetRect (&inner
, 8, 8);
5888 screen_rect
= qd
.screenBits
.bounds
;
5889 screen_rect
.top
+= GetMBarHeight ();
5891 if (!SectRect (&inner
, &screen_rect
, &dummy
))
5893 if (inner
.right
<= screen_rect
.left
)
5894 f
->left_pos
= screen_rect
.left
;
5895 else if (inner
.left
>= screen_rect
.right
)
5896 f
->left_pos
= screen_rect
.right
- (outer
.right
- outer
.left
);
5898 if (inner
.bottom
<= screen_rect
.top
)
5899 f
->top_pos
= screen_rect
.top
;
5900 else if (inner
.top
>= screen_rect
.bottom
)
5901 f
->top_pos
= screen_rect
.bottom
- (outer
.bottom
- outer
.top
);
5903 MoveWindow (FRAME_MAC_WINDOW (f
), f
->left_pos
+ f
->x_pixels_diff
,
5904 f
->top_pos
+ f
->y_pixels_diff
, false);
5912 /* Call this to change the size of frame F's x-window.
5913 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
5914 for this size change and subsequent size changes.
5915 Otherwise we leave the window gravity unchanged. */
5918 x_set_window_size (f
, change_gravity
, cols
, rows
)
5923 int pixelwidth
, pixelheight
;
5927 check_frame_size (f
, &rows
, &cols
);
5928 f
->scroll_bar_actual_width
5929 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
5931 compute_fringe_widths (f
, 0);
5933 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
5934 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
5936 f
->win_gravity
= NorthWestGravity
;
5937 x_wm_set_size_hint (f
, (long) 0, 0);
5939 SizeWindow (FRAME_MAC_WINDOW (f
), pixelwidth
, pixelheight
, 0);
5940 #if TARGET_API_MAC_CARBON
5941 if (f
->output_data
.mac
->hourglass_control
)
5944 mac_prepare_for_quickdraw (f
);
5946 MoveControl (f
->output_data
.mac
->hourglass_control
,
5947 pixelwidth
- HOURGLASS_WIDTH
, 0);
5951 /* Now, strictly speaking, we can't be sure that this is accurate,
5952 but the window manager will get around to dealing with the size
5953 change request eventually, and we'll hear how it went when the
5954 ConfigureNotify event gets here.
5956 We could just not bother storing any of this information here,
5957 and let the ConfigureNotify event set everything up, but that
5958 might be kind of confusing to the Lisp code, since size changes
5959 wouldn't be reported in the frame parameters until some random
5960 point in the future when the ConfigureNotify event arrives.
5962 We pass 1 for DELAY since we can't run Lisp code inside of
5964 change_frame_size (f
, rows
, cols
, 0, 1, 0);
5965 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
5966 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
5968 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
5969 receive in the ConfigureNotify event; if we get what we asked
5970 for, then the event won't cause the screen to become garbaged, so
5971 we have to make sure to do it here. */
5972 SET_FRAME_GARBAGED (f
);
5974 XFlush (FRAME_X_DISPLAY (f
));
5976 /* If cursor was outside the new size, mark it as off. */
5977 mark_window_cursors_off (XWINDOW (f
->root_window
));
5979 /* Clear out any recollection of where the mouse highlighting was,
5980 since it might be in a place that's outside the new frame size.
5981 Actually checking whether it is outside is a pain in the neck,
5982 so don't try--just let the highlighting be done afresh with new size. */
5983 cancel_mouse_face (f
);
5988 /* Mouse warping. */
5990 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
5993 x_set_mouse_position (f
, x
, y
)
5999 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
6000 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
6002 if (pix_x
< 0) pix_x
= 0;
6003 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
6005 if (pix_y
< 0) pix_y
= 0;
6006 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
6008 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
6012 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
6016 #if 0 /* MAC_TODO: CursorDeviceMoveTo is non-Carbon */
6019 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
6020 0, 0, 0, 0, pix_x
, pix_y
);
6025 /* focus shifting, raising and lowering. */
6028 x_focus_on_frame (f
)
6031 #if 0 /* This proves to be unpleasant. */
6035 /* I don't think that the ICCCM allows programs to do things like this
6036 without the interaction of the window manager. Whatever you end up
6037 doing with this code, do it to x_unfocus_frame too. */
6038 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6039 RevertToPointerRoot
, CurrentTime
);
6049 /* Raise frame F. */
6055 if (f
->async_visible
)
6058 BringToFront (FRAME_MAC_WINDOW (f
));
6063 /* Lower frame F. */
6069 if (f
->async_visible
)
6072 SendBehind (FRAME_MAC_WINDOW (f
), NULL
);
6078 XTframe_raise_lower (f
, raise_flag
)
6088 /* Change of visibility. */
6091 mac_handle_visibility_change (f
)
6094 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
6095 int visible
= 0, iconified
= 0;
6096 struct input_event buf
;
6098 if (IsWindowVisible (wp
))
6100 if (IsWindowCollapsed (wp
))
6106 if (!f
->async_visible
&& visible
)
6110 /* wait_reading_process_output will notice this and update
6111 the frame's display structures. If we were made
6112 invisible, we should not set garbaged, because that stops
6113 redrawing on Update events. */
6114 SET_FRAME_GARBAGED (f
);
6117 buf
.kind
= DEICONIFY_EVENT
;
6118 XSETFRAME (buf
.frame_or_window
, f
);
6119 kbd_buffer_store_event (&buf
);
6121 else if (! NILP (Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
6122 /* Force a redisplay sooner or later to update the
6123 frame titles in case this is the second frame. */
6124 record_asynch_buffer_change ();
6126 else if (f
->async_visible
&& !visible
)
6130 buf
.kind
= ICONIFY_EVENT
;
6131 XSETFRAME (buf
.frame_or_window
, f
);
6132 kbd_buffer_store_event (&buf
);
6135 f
->async_visible
= visible
;
6136 f
->async_iconified
= iconified
;
6139 /* This tries to wait until the frame is really visible.
6140 However, if the window manager asks the user where to position
6141 the frame, this will return before the user finishes doing that.
6142 The frame will not actually be visible at that time,
6143 but it will become visible later when the window manager
6144 finishes with it. */
6147 x_make_frame_visible (f
)
6152 if (! FRAME_VISIBLE_P (f
))
6154 /* We test FRAME_GARBAGED_P here to make sure we don't
6155 call x_set_offset a second time
6156 if we get to x_make_frame_visible a second time
6157 before the window gets really visible. */
6158 if (! FRAME_ICONIFIED_P (f
)
6159 && ! f
->output_data
.mac
->asked_for_visible
)
6161 #if TARGET_API_MAC_CARBON
6162 if (!(FRAME_SIZE_HINTS (f
)->flags
& (USPosition
| PPosition
)))
6164 struct frame
*sf
= SELECTED_FRAME ();
6165 if (!FRAME_MAC_P (sf
))
6166 RepositionWindow (FRAME_MAC_WINDOW (f
), NULL
,
6167 kWindowCenterOnMainScreen
);
6169 RepositionWindow (FRAME_MAC_WINDOW (f
),
6170 FRAME_MAC_WINDOW (sf
),
6171 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
6172 kWindowCascadeStartAtParentWindowScreen
6174 kWindowCascadeOnParentWindowScreen
6177 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6181 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
6184 f
->output_data
.mac
->asked_for_visible
= 1;
6186 CollapseWindow (FRAME_MAC_WINDOW (f
), false);
6187 ShowWindow (FRAME_MAC_WINDOW (f
));
6190 XFlush (FRAME_MAC_DISPLAY (f
));
6192 /* Synchronize to ensure Emacs knows the frame is visible
6193 before we do anything else. We do this loop with input not blocked
6194 so that incoming events are handled. */
6199 /* This must come after we set COUNT. */
6202 XSETFRAME (frame
, f
);
6204 /* Wait until the frame is visible. Process X events until a
6205 MapNotify event has been seen, or until we think we won't get a
6206 MapNotify at all.. */
6207 for (count
= input_signal_count
+ 10;
6208 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
6210 /* Force processing of queued events. */
6213 /* Machines that do polling rather than SIGIO have been
6214 observed to go into a busy-wait here. So we'll fake an
6215 alarm signal to let the handler know that there's something
6216 to be read. We used to raise a real alarm, but it seems
6217 that the handler isn't always enabled here. This is
6219 if (input_polling_used ())
6221 /* It could be confusing if a real alarm arrives while
6222 processing the fake one. Turn it off and let the
6223 handler reset it. */
6224 extern void poll_for_input_1
P_ ((void));
6225 int old_poll_suppress_count
= poll_suppress_count
;
6226 poll_suppress_count
= 1;
6227 poll_for_input_1 ();
6228 poll_suppress_count
= old_poll_suppress_count
;
6231 /* See if a MapNotify event has been processed. */
6232 FRAME_SAMPLE_VISIBILITY (f
);
6237 /* Change from mapped state to withdrawn state. */
6239 /* Make the frame visible (mapped and not iconified). */
6242 x_make_frame_invisible (f
)
6245 /* A deactivate event does not occur when the last visible frame is
6246 made invisible. So if we clear the highlight here, it will not
6247 be rehighlighted when it is made visible. */
6249 /* Don't keep the highlight on an invisible frame. */
6250 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
6251 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
6256 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
6257 that the current position of the window is user-specified, rather than
6258 program-specified, so that when the window is mapped again, it will be
6259 placed at the same location, without forcing the user to position it
6260 by hand again (they have already done that once for this window.) */
6261 x_wm_set_size_hint (f
, (long) 0, 1);
6263 HideWindow (FRAME_MAC_WINDOW (f
));
6267 #if !USE_CARBON_EVENTS
6268 mac_handle_visibility_change (f
);
6272 /* Change window state from mapped to iconified. */
6280 /* A deactivate event does not occur when the last visible frame is
6281 iconified. So if we clear the highlight here, it will not be
6282 rehighlighted when it is deiconified. */
6284 /* Don't keep the highlight on an invisible frame. */
6285 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
6286 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
6289 if (f
->async_iconified
)
6294 FRAME_SAMPLE_VISIBILITY (f
);
6296 if (! FRAME_VISIBLE_P (f
))
6297 ShowWindow (FRAME_MAC_WINDOW (f
));
6299 err
= CollapseWindow (FRAME_MAC_WINDOW (f
), true);
6304 error ("Can't notify window manager of iconification");
6306 #if !USE_CARBON_EVENTS
6307 mac_handle_visibility_change (f
);
6312 /* Free X resources of frame F. */
6315 x_free_frame_resources (f
)
6318 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6319 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
6323 if (wp
!= tip_window
)
6324 remove_window_handler (wp
);
6327 if (wp
== tip_window
)
6328 /* Neither WaitNextEvent nor ReceiveNextEvent receives `window
6329 closed' event. So we reset tip_window here. */
6332 free_frame_menubar (f
);
6334 if (FRAME_FACE_CACHE (f
))
6335 free_frame_faces (f
);
6339 if (FRAME_SIZE_HINTS (f
))
6340 xfree (FRAME_SIZE_HINTS (f
));
6342 #if TARGET_API_MAC_CARBON
6343 if (FRAME_FILE_NAME (f
))
6344 xfree (FRAME_FILE_NAME (f
));
6347 xfree (f
->output_data
.mac
);
6348 f
->output_data
.mac
= NULL
;
6350 if (f
== dpyinfo
->x_focus_frame
)
6352 dpyinfo
->x_focus_frame
= 0;
6353 #if USE_MAC_FONT_PANEL
6354 mac_set_font_info_for_selection (NULL
, DEFAULT_FACE_ID
, 0);
6357 if (f
== dpyinfo
->x_focus_event_frame
)
6358 dpyinfo
->x_focus_event_frame
= 0;
6359 if (f
== dpyinfo
->x_highlight_frame
)
6360 dpyinfo
->x_highlight_frame
= 0;
6362 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6364 dpyinfo
->mouse_face_beg_row
6365 = dpyinfo
->mouse_face_beg_col
= -1;
6366 dpyinfo
->mouse_face_end_row
6367 = dpyinfo
->mouse_face_end_col
= -1;
6368 dpyinfo
->mouse_face_window
= Qnil
;
6369 dpyinfo
->mouse_face_deferred_gc
= 0;
6370 dpyinfo
->mouse_face_mouse_frame
= 0;
6377 /* Destroy the X window of frame F. */
6380 x_destroy_window (f
)
6383 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6385 x_free_frame_resources (f
);
6387 dpyinfo
->reference_count
--;
6391 /* Setting window manager hints. */
6393 /* Set the normal size hints for the window manager, for frame F.
6394 FLAGS is the flags word to use--or 0 meaning preserve the flags
6395 that the window now has.
6396 If USER_POSITION is nonzero, we set the USPosition
6397 flag (this is useful when FLAGS is 0). */
6399 x_wm_set_size_hint (f
, flags
, user_position
)
6404 int base_width
, base_height
, width_inc
, height_inc
;
6405 int min_rows
= 0, min_cols
= 0;
6406 XSizeHints
*size_hints
;
6408 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
6409 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
6410 width_inc
= FRAME_COLUMN_WIDTH (f
);
6411 height_inc
= FRAME_LINE_HEIGHT (f
);
6413 check_frame_size (f
, &min_rows
, &min_cols
);
6415 size_hints
= FRAME_SIZE_HINTS (f
);
6416 if (size_hints
== NULL
)
6418 size_hints
= FRAME_SIZE_HINTS (f
) = xmalloc (sizeof (XSizeHints
));
6419 bzero (size_hints
, sizeof (XSizeHints
));
6422 size_hints
->flags
|= PResizeInc
| PMinSize
| PBaseSize
;
6423 size_hints
->width_inc
= width_inc
;
6424 size_hints
->height_inc
= height_inc
;
6425 size_hints
->min_width
= base_width
+ min_cols
* width_inc
;
6426 size_hints
->min_height
= base_height
+ min_rows
* height_inc
;
6427 size_hints
->base_width
= base_width
;
6428 size_hints
->base_height
= base_height
;
6431 size_hints
->flags
= flags
;
6432 else if (user_position
)
6434 size_hints
->flags
&= ~ PPosition
;
6435 size_hints
->flags
|= USPosition
;
6439 #if 0 /* MAC_TODO: hide application instead of iconify? */
6440 /* Used for IconicState or NormalState */
6443 x_wm_set_window_state (f
, state
)
6447 #ifdef USE_X_TOOLKIT
6450 XtSetArg (al
[0], XtNinitialState
, state
);
6451 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6452 #else /* not USE_X_TOOLKIT */
6453 Window window
= FRAME_X_WINDOW (f
);
6455 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
6456 f
->output_data
.x
->wm_hints
.initial_state
= state
;
6458 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6459 #endif /* not USE_X_TOOLKIT */
6463 x_wm_set_icon_pixmap (f
, pixmap_id
)
6469 #ifndef USE_X_TOOLKIT
6470 Window window
= FRAME_X_WINDOW (f
);
6475 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
6476 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
6480 /* It seems there is no way to turn off use of an icon pixmap.
6481 The following line does it, only if no icon has yet been created,
6482 for some window managers. But with mwm it crashes.
6483 Some people say it should clear the IconPixmapHint bit in this case,
6484 but that doesn't work, and the X consortium said it isn't the
6485 right thing at all. Since there is no way to win,
6486 best to explicitly give up. */
6488 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
6494 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
6498 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
6499 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6502 #else /* not USE_X_TOOLKIT */
6504 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
6505 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6507 #endif /* not USE_X_TOOLKIT */
6510 #endif /* MAC_TODO */
6513 x_wm_set_icon_position (f
, icon_x
, icon_y
)
6517 #if 0 /* MAC_TODO: no icons on Mac */
6518 #ifdef USE_X_TOOLKIT
6519 Window window
= XtWindow (f
->output_data
.x
->widget
);
6521 Window window
= FRAME_X_WINDOW (f
);
6524 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
6525 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
6526 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
6528 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6529 #endif /* MAC_TODO */
6533 /***********************************************************************
6535 ***********************************************************************/
6537 /* An XLFD pattern is divided into blocks delimited by '*'. This
6538 structure holds information for each block. */
6539 struct xlfdpat_block
6541 /* Length of the pattern string in this block. Non-zero except for
6542 the first and the last blocks. */
6545 /* Pattern string except the last character in this block. The last
6546 character is replaced with NUL in order to use it as a
6548 unsigned char *pattern
;
6550 /* Last character of the pattern string. Must not be '?'. */
6551 unsigned char last_char
;
6553 /* One of the tables for the Boyer-Moore string search. It
6554 specifies the number of positions to proceed for each character
6555 with which the match fails. */
6558 /* The skip value for the last character in the above `skip' is
6559 assigned to `infinity' in order to simplify a loop condition.
6560 The original value is saved here. */
6566 /* Normalized pattern string. "Normalized" means that capital
6567 letters are lowered, blocks are not empty except the first and
6568 the last ones, and trailing '?'s in a block that is not the last
6569 one are moved to the next one. The last character in each block
6570 is replaced with NUL. */
6573 /* Number of characters except '*'s and trailing '?'s in the
6574 normalized pattern string. */
6577 /* Number of trailing '?'s in the normalized pattern string. */
6578 int trailing_anychars
;
6580 /* Number of blocks and information for each block. The latter is
6581 NULL if the pattern is exact (no '*' or '?' in it). */
6583 struct xlfdpat_block
*blocks
;
6587 xlfdpat_destroy (pat
)
6588 struct xlfdpat
*pat
;
6595 xfree (pat
->blocks
);
6602 static struct xlfdpat
*
6603 xlfdpat_create (pattern
)
6606 struct xlfdpat
*pat
;
6607 int nblocks
, i
, skip
;
6608 unsigned char last_char
, *p
, *q
, *anychar_head
;
6609 struct xlfdpat_block
*blk
;
6611 pat
= xmalloc (sizeof (struct xlfdpat
));
6612 pat
->buf
= xmalloc (strlen (pattern
) + 1);
6614 /* Normalize the pattern string and store it to `pat->buf'. */
6616 anychar_head
= NULL
;
6619 for (p
= pattern
; *p
; p
++)
6621 unsigned char c
= *p
;
6624 if (last_char
== '*')
6625 /* ...a** -> ...a* */
6629 if (last_char
== '?')
6631 if (anychar_head
> pat
->buf
&& *(anychar_head
- 1) == '*')
6632 /* ...*??* -> ...*?? */
6635 /* ...a??* -> ...a*?? */
6637 *anychar_head
++ = '*';
6645 if (last_char
!= '?')
6649 /* On Mac OS X 10.3, tolower also converts non-ASCII
6650 characters for some locales. */
6654 *q
++ = last_char
= c
;
6658 pat
->nblocks
= nblocks
;
6659 if (last_char
!= '?')
6660 pat
->trailing_anychars
= 0;
6663 pat
->trailing_anychars
= q
- anychar_head
;
6666 pat
->nchars
= q
- pat
->buf
- (nblocks
- 1);
6668 if (anychar_head
== NULL
&& nblocks
== 1)
6670 /* The pattern is exact. */
6675 pat
->blocks
= xmalloc (sizeof (struct xlfdpat_block
) * nblocks
);
6677 /* Divide the normalized pattern into blocks. */
6679 for (blk
= pat
->blocks
; blk
< pat
->blocks
+ nblocks
- 1; blk
++)
6684 blk
->len
= p
- blk
->pattern
;
6688 blk
->len
= q
- blk
->pattern
;
6690 /* Setup a table for the Boyer-Moore string search. */
6691 for (blk
= pat
->blocks
; blk
< pat
->blocks
+ nblocks
; blk
++)
6694 blk
->last_char
= blk
->pattern
[blk
->len
- 1];
6695 blk
->pattern
[blk
->len
- 1] = '\0';
6697 for (skip
= 1; skip
< blk
->len
; skip
++)
6698 if (blk
->pattern
[blk
->len
- skip
- 1] == '?')
6701 for (i
= 0; i
< 256; i
++)
6702 blk
->skip
[i
] = skip
;
6704 p
= blk
->pattern
+ (blk
->len
- skip
);
6706 blk
->skip
[*p
++] = skip
;
6708 blk
->last_char_skip
= blk
->skip
[blk
->last_char
];
6715 xlfdpat_exact_p (pat
)
6716 struct xlfdpat
*pat
;
6718 return pat
->blocks
== NULL
;
6721 /* Return the first string in STRING + 0, ..., STRING + START_MAX such
6722 that the pattern in *BLK matches with its prefix. Return NULL
6723 there is no such strings. STRING must be lowered in advance. */
6726 xlfdpat_block_match_1 (blk
, string
, start_max
)
6727 struct xlfdpat_block
*blk
;
6728 unsigned char *string
;
6731 int start
, infinity
;
6732 unsigned char *p
, *s
;
6734 xassert (blk
->len
> 0);
6735 xassert (start_max
+ blk
->len
<= strlen (string
));
6736 xassert (blk
->last_char
!= '?');
6738 /* See the comments in the function `boyer_moore' (search.c) for the
6739 use of `infinity'. */
6740 infinity
= start_max
+ blk
->len
+ 1;
6741 blk
->skip
[blk
->last_char
] = infinity
;
6746 /* Check the last character of the pattern. */
6747 s
= string
+ blk
->len
- 1;
6750 start
+= blk
->skip
[*(s
+ start
)];
6752 while (start
<= start_max
);
6754 if (start
< infinity
)
6755 /* Couldn't find the last character. */
6758 /* No less than `infinity' means we could find the last
6759 character at `s[start - infinity]'. */
6762 /* Check the remaining characters. We prefer making no-'?'
6763 cases faster because the use of '?' is really rare. */
6768 while (*p
++ == *s
++)
6771 while (*(p
- 1) == '?');
6773 if (*(p
- 1) == '\0')
6775 return string
+ start
;
6778 start
+= blk
->last_char_skip
;
6780 while (start
<= start_max
);
6785 #define xlfdpat_block_match(b, s, m) \
6786 ((b)->len == 1 ? memchr ((s), (b)->last_char, (m) + 1) \
6787 : xlfdpat_block_match_1 (b, s, m))
6789 /* Check if XLFD pattern PAT, which is generated by `xfldpat_create',
6790 matches with STRING. STRING must be lowered in advance. */
6793 xlfdpat_match (pat
, string
)
6794 struct xlfdpat
*pat
;
6795 unsigned char *string
;
6797 int str_len
, nblocks
, i
, start_max
;
6798 struct xlfdpat_block
*blk
;
6801 xassert (pat
->nblocks
> 0);
6803 if (xlfdpat_exact_p (pat
))
6804 return strcmp (pat
->buf
, string
) == 0;
6806 /* The number of the characters in the string must not be smaller
6807 than that in the pattern. */
6808 str_len
= strlen (string
);
6809 if (str_len
< pat
->nchars
+ pat
->trailing_anychars
)
6812 /* Chop off the trailing '?'s. */
6813 str_len
-= pat
->trailing_anychars
;
6815 /* The last block. When it is non-empty, it must match at the end
6817 nblocks
= pat
->nblocks
;
6818 blk
= pat
->blocks
+ (nblocks
- 1);
6820 /* The last block is also the first one. */
6821 return (str_len
== blk
->len
6822 && (blk
->len
== 0 || xlfdpat_block_match (blk
, string
, 0)));
6823 else if (blk
->len
!= 0)
6824 if (!xlfdpat_block_match (blk
, string
+ (str_len
- blk
->len
), 0))
6827 /* The first block. When it is non-empty, it must match at the
6828 beginning of the string. */
6832 s
= xlfdpat_block_match (blk
, string
, 0);
6835 string
= s
+ blk
->len
;
6838 /* The rest of the blocks. */
6839 start_max
= str_len
- pat
->nchars
;
6840 for (i
= 1, blk
++; i
< nblocks
- 1; i
++, blk
++)
6842 s
= xlfdpat_block_match (blk
, string
, start_max
);
6845 start_max
-= s
- string
;
6846 string
= s
+ blk
->len
;
6853 /***********************************************************************
6855 ***********************************************************************/
6857 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6860 x_get_font_info (f
, font_idx
)
6864 return (FRAME_MAC_FONT_TABLE (f
) + font_idx
);
6867 /* the global font name table */
6868 static char **font_name_table
= NULL
;
6869 static int font_name_table_size
= 0;
6870 static int font_name_count
= 0;
6872 /* Alist linking font family names to Font Manager font family
6873 references (which can also be used as QuickDraw font IDs). We use
6874 an alist because hash tables are not ready when the terminal frame
6875 for Mac OS Classic is created. */
6876 static Lisp_Object fm_font_family_alist
;
6878 /* Hash table linking font family names to ATSU font IDs. */
6879 static Lisp_Object atsu_font_id_hash
;
6880 static Lisp_Object Vmac_atsu_font_table
;
6881 extern Lisp_Object QCfamily
, QCweight
, QCslant
, Qnormal
, Qbold
, Qitalic
;
6884 /* Alist linking character set strings to Mac text encoding and Emacs
6886 static Lisp_Object Vmac_charset_info_alist
;
6889 create_text_encoding_info_alist ()
6891 Lisp_Object result
= Qnil
, rest
;
6893 for (rest
= Vmac_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
6895 Lisp_Object charset_info
= XCAR (rest
);
6896 Lisp_Object charset
, coding_system
, text_encoding
;
6897 Lisp_Object existing_info
;
6899 if (!(CONSP (charset_info
)
6900 && STRINGP (charset
= XCAR (charset_info
))
6901 && CONSP (XCDR (charset_info
))
6902 && INTEGERP (text_encoding
= XCAR (XCDR (charset_info
)))
6903 && CONSP (XCDR (XCDR (charset_info
)))
6904 && SYMBOLP (coding_system
= XCAR (XCDR (XCDR (charset_info
))))))
6907 existing_info
= assq_no_quit (text_encoding
, result
);
6908 if (NILP (existing_info
))
6909 result
= Fcons (list3 (text_encoding
, coding_system
, charset
),
6912 if (NILP (Fmember (charset
, XCDR (XCDR (existing_info
)))))
6913 XSETCDR (XCDR (existing_info
),
6914 Fcons (charset
, XCDR (XCDR (existing_info
))));
6922 decode_mac_font_name (name
, size
, coding_system
)
6925 Lisp_Object coding_system
;
6927 struct coding_system coding
;
6930 if (!NILP (coding_system
) && !NILP (Fcoding_system_p (coding_system
)))
6932 for (p
= name
; *p
; p
++)
6933 if (!isascii (*p
) || iscntrl (*p
))
6938 setup_coding_system (coding_system
, &coding
);
6939 coding
.src_multibyte
= 0;
6940 coding
.dst_multibyte
= 1;
6941 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6942 coding
.composing
= COMPOSITION_DISABLED
;
6943 buf
= (char *) alloca (size
);
6945 decode_coding (&coding
, name
, buf
, strlen (name
), size
- 1);
6946 bcopy (buf
, name
, coding
.produced
);
6947 name
[coding
.produced
] = '\0';
6951 /* If there's just one occurrence of '-' in the family name, it is
6952 replaced with '_'. (More than one occurrence of '-' means a
6953 "FOUNDRY-FAMILY-CHARSET"-style name.) */
6954 p
= strchr (name
, '-');
6955 if (p
&& strchr (p
+ 1, '-') == NULL
)
6958 for (p
= name
; *p
; p
++)
6959 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
6960 for some locales. */
6967 mac_to_x_fontname (name
, size
, style
, charset
)
6975 char xf
[256], *result
;
6978 if (sscanf (name
, "%31[^-]-%255[^-]-%31s", foundry
, family
, cs
) == 3)
6982 strcpy(foundry
, "Apple");
6983 strcpy(family
, name
);
6986 sprintf (xf
, "%s-%c-normal--%d-%d-%d-%d-m-%d-%s",
6987 style
& bold
? "bold" : "medium", style
& italic
? 'i' : 'r',
6988 size
, size
* 10, size
? 72 : 0, size
? 72 : 0, size
* 10, charset
);
6990 result
= xmalloc (strlen (foundry
) + strlen (family
) + strlen (xf
) + 3 + 1);
6991 sprintf (result
, "-%s-%s-%s", foundry
, family
, xf
);
6992 for (p
= result
; *p
; p
++)
6993 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
6994 for some locales. */
7001 /* Parse fully-specified and instantiated X11 font spec XF, and store
7002 the results to FAMILY, *SIZE, *STYLE, and CHARSET. Return 1 if the
7003 parsing succeeded, and 0 otherwise. For FAMILY and CHARSET, the
7004 caller must allocate at least 256 and 32 bytes respectively. For
7005 ordinary Mac fonts, the value stored to FAMILY should just be their
7006 names, like "monaco", "Taipei", etc. Fonts converted from the GNU
7007 intlfonts collection contain their charset designation in their
7008 names, like "ETL-Fixed-iso8859-1", "ETL-Fixed-koi8-r", etc. Both
7009 types of font names are handled accordingly. */
7011 const int kDefaultFontSize
= 12;
7014 parse_x_font_name (xf
, family
, size
, style
, charset
)
7020 Str31 foundry
, weight
;
7021 int point_size
, avgwidth
;
7024 if (sscanf (xf
, "-%31[^-]-%255[^-]-%31[^-]-%1[^-]-%*[^-]-%*[^-]-%d-%d-%*[^-]-%*[^-]-%*c-%d-%31s",
7025 foundry
, family
, weight
, slant
, size
,
7026 &point_size
, &avgwidth
, charset
) != 8
7027 && sscanf (xf
, "-%31[^-]-%255[^-]-%31[^-]-%1[^-]-%*[^-]--%d-%d-%*[^-]-%*[^-]-%*c-%d-%31s",
7028 foundry
, family
, weight
, slant
, size
,
7029 &point_size
, &avgwidth
, charset
) != 8)
7035 *size
= point_size
/ 10;
7036 else if (avgwidth
> 0)
7037 *size
= avgwidth
/ 10;
7040 *size
= kDefaultFontSize
;
7043 if (strcmp (weight
, "bold") == 0)
7048 if (NILP (Fassoc (build_string (charset
), Vmac_charset_info_alist
)))
7050 int foundry_len
= strlen (foundry
), family_len
= strlen (family
);
7052 if (foundry_len
+ family_len
+ strlen (charset
) + 2 < sizeof (Str255
))
7054 /* Like sprintf (family, "%s-%s-%s", foundry, family, charset),
7055 but take overlap into account. */
7056 memmove (family
+ foundry_len
+ 1, family
, family_len
);
7057 memcpy (family
, foundry
, foundry_len
);
7058 family
[foundry_len
] = '-';
7059 family
[foundry_len
+ 1 + family_len
] = '-';
7060 strcpy (family
+ foundry_len
+ 1 + family_len
+ 1, charset
);
7066 for (p
= family
; *p
; p
++)
7067 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
7068 for some locales. */
7077 add_font_name_table_entry (char *font_name
)
7079 if (font_name_table_size
== 0)
7081 font_name_table_size
= 256;
7082 font_name_table
= (char **)
7083 xmalloc (font_name_table_size
* sizeof (char *));
7085 else if (font_name_count
+ 1 >= font_name_table_size
)
7087 font_name_table_size
*= 2;
7088 font_name_table
= (char **)
7089 xrealloc (font_name_table
,
7090 font_name_table_size
* sizeof (char *));
7093 font_name_table
[font_name_count
++] = font_name
;
7097 add_mac_font_name (name
, size
, style
, charset
)
7104 add_font_name_table_entry (mac_to_x_fontname (name
, size
, style
, charset
));
7107 add_font_name_table_entry (mac_to_x_fontname (name
, 0, style
, charset
));
7108 add_font_name_table_entry (mac_to_x_fontname (name
, 0, italic
, charset
));
7109 add_font_name_table_entry (mac_to_x_fontname (name
, 0, bold
, charset
));
7110 add_font_name_table_entry (mac_to_x_fontname (name
, 0, italic
| bold
,
7115 /* Sets up the table font_name_table to contain the list of all fonts
7116 in the system the first time the table is used so that the Resource
7117 Manager need not be accessed every time this information is
7121 init_font_name_table ()
7123 #if TARGET_API_MAC_CARBON
7124 FMFontFamilyIterator ffi
;
7125 FMFontFamilyInstanceIterator ffii
;
7127 Lisp_Object text_encoding_info_alist
;
7128 struct gcpro gcpro1
;
7130 text_encoding_info_alist
= create_text_encoding_info_alist ();
7133 #if USE_CG_TEXT_DRAWING
7134 init_cg_text_anti_aliasing_threshold ();
7136 if (!NILP (assq_no_quit (make_number (kTextEncodingMacUnicode
),
7137 text_encoding_info_alist
)))
7140 struct Lisp_Hash_Table
*h
;
7142 ItemCount nfonts
, i
;
7143 ATSUFontID
*font_ids
= NULL
;
7149 make_hash_table (Qequal
, make_number (DEFAULT_HASH_SIZE
),
7150 make_float (DEFAULT_REHASH_SIZE
),
7151 make_float (DEFAULT_REHASH_THRESHOLD
),
7153 h
= XHASH_TABLE (atsu_font_id_hash
);
7155 err
= ATSUFontCount (&nfonts
);
7158 font_ids
= xmalloc (sizeof (ATSUFontID
) * nfonts
);
7159 err
= ATSUGetFontIDs (font_ids
, nfonts
, NULL
);
7162 for (i
= 0; i
< nfonts
; i
++)
7164 err
= ATSUFindFontName (font_ids
[i
], kFontFamilyName
,
7165 kFontMacintoshPlatform
, kFontNoScript
,
7166 kFontNoLanguage
, 0, NULL
, &name_len
, NULL
);
7169 name
= xmalloc (name_len
+ 1);
7170 name
[name_len
] = '\0';
7171 err
= ATSUFindFontName (font_ids
[i
], kFontFamilyName
,
7172 kFontMacintoshPlatform
, kFontNoScript
,
7173 kFontNoLanguage
, name_len
, name
,
7178 FMFontStyle style
= normal
;
7180 decode_mac_font_name (name
, name_len
+ 1, Qnil
);
7181 family
= make_unibyte_string (name
, name_len
);
7182 FMGetFontFamilyInstanceFromFont (font_ids
[i
], &ff
, &style
);
7183 Fputhash (make_unibyte_string ((char *)(font_ids
+ i
),
7184 sizeof (ATSUFontID
)),
7188 style
& bold
? Qbold
: Qnormal
,
7190 style
& italic
? Qitalic
: Qnormal
)),
7191 Vmac_atsu_font_table
);
7193 && hash_lookup (h
, family
, &hash_code
) < 0)
7195 add_mac_font_name (name
, 0, normal
, "iso10646-1");
7196 hash_put (h
, family
, long_to_cons (font_ids
[i
]),
7207 /* Create a dummy instance iterator here to avoid creating and
7208 destroying it in the loop. */
7209 if (FMCreateFontFamilyInstanceIterator (0, &ffii
) != noErr
)
7211 /* Create an iterator to enumerate the font families. */
7212 if (FMCreateFontFamilyIterator (NULL
, NULL
, kFMDefaultOptions
, &ffi
)
7215 FMDisposeFontFamilyInstanceIterator (&ffii
);
7219 GCPRO1 (text_encoding_info_alist
);
7221 while (FMGetNextFontFamily (&ffi
, &ff
) == noErr
)
7227 TextEncoding encoding
;
7228 TextEncodingBase sc
;
7229 Lisp_Object text_encoding_info
, family
;
7231 if (FMGetFontFamilyName (ff
, name
) != noErr
)
7237 if (FMGetFontFamilyTextEncoding (ff
, &encoding
) != noErr
)
7239 sc
= GetTextEncodingBase (encoding
);
7240 text_encoding_info
= assq_no_quit (make_number (sc
),
7241 text_encoding_info_alist
);
7242 if (NILP (text_encoding_info
))
7243 text_encoding_info
= assq_no_quit (make_number (kTextEncodingMacRoman
),
7244 text_encoding_info_alist
);
7245 decode_mac_font_name (name
, sizeof (name
),
7246 XCAR (XCDR (text_encoding_info
)));
7247 family
= build_string (name
);
7248 if (!NILP (Fassoc (family
, fm_font_family_alist
)))
7250 fm_font_family_alist
= Fcons (Fcons (family
, make_number (ff
)),
7251 fm_font_family_alist
);
7253 /* Point the instance iterator at the current font family. */
7254 if (FMResetFontFamilyInstanceIterator (ff
, &ffii
) != noErr
)
7257 while (FMGetNextFontFamilyInstance (&ffii
, &font
, &style
, &size
)
7260 Lisp_Object rest
= XCDR (XCDR (text_encoding_info
));
7262 if (size
> 0 || style
== normal
)
7263 for (; !NILP (rest
); rest
= XCDR (rest
))
7264 add_mac_font_name (name
, size
, style
, SDATA (XCAR (rest
)));
7270 /* Dispose of the iterators. */
7271 FMDisposeFontFamilyIterator (&ffi
);
7272 FMDisposeFontFamilyInstanceIterator (&ffii
);
7273 #else /* !TARGET_API_MAC_CARBON */
7275 SInt16 fontnum
, old_fontnum
;
7276 int num_mac_fonts
= CountResources('FOND');
7278 Handle font_handle
, font_handle_2
;
7279 short id
, scriptcode
;
7282 struct FontAssoc
*fat
;
7283 struct AsscEntry
*assc_entry
;
7284 Lisp_Object text_encoding_info_alist
, text_encoding_info
, family
;
7285 struct gcpro gcpro1
;
7287 GetPort (&port
); /* save the current font number used */
7288 old_fontnum
= port
->txFont
;
7290 text_encoding_info_alist
= create_text_encoding_info_alist ();
7292 GCPRO1 (text_encoding_info_alist
);
7294 for (i
= 1; i
<= num_mac_fonts
; i
++) /* get all available fonts */
7296 font_handle
= GetIndResource ('FOND', i
);
7300 GetResInfo (font_handle
, &id
, &type
, name
);
7301 GetFNum (name
, &fontnum
);
7303 if (fontnum
== 0 || *name
== '.')
7307 scriptcode
= FontToScript (fontnum
);
7308 text_encoding_info
= assq_no_quit (make_number (scriptcode
),
7309 text_encoding_info_alist
);
7310 if (NILP (text_encoding_info
))
7311 text_encoding_info
= assq_no_quit (make_number (smRoman
),
7312 text_encoding_info_alist
);
7313 decode_mac_font_name (name
, sizeof (name
),
7314 XCAR (XCDR (text_encoding_info
)));
7315 family
= build_string (name
);
7316 if (!NILP (Fassoc (family
, fm_font_family_alist
)))
7318 fm_font_family_alist
= Fcons (Fcons (family
, make_number (fontnum
)),
7319 fm_font_family_alist
);
7322 HLock (font_handle
);
7324 if (GetResourceSizeOnDisk (font_handle
)
7325 >= sizeof (struct FamRec
))
7327 fat
= (struct FontAssoc
*) (*font_handle
7328 + sizeof (struct FamRec
));
7330 = (struct AsscEntry
*) (*font_handle
7331 + sizeof (struct FamRec
)
7332 + sizeof (struct FontAssoc
));
7334 for (j
= 0; j
<= fat
->numAssoc
; j
++, assc_entry
++)
7336 Lisp_Object rest
= XCDR (XCDR (text_encoding_info
));
7338 for (; !NILP (rest
); rest
= XCDR (rest
))
7339 add_mac_font_name (name
, assc_entry
->fontSize
,
7340 assc_entry
->fontStyle
,
7341 SDATA (XCAR (rest
)));
7345 HUnlock (font_handle
);
7346 font_handle_2
= GetNextFOND (font_handle
);
7347 ReleaseResource (font_handle
);
7348 font_handle
= font_handle_2
;
7350 while (ResError () == noErr
&& font_handle
);
7355 TextFont (old_fontnum
);
7356 #endif /* !TARGET_API_MAC_CARBON */
7361 mac_clear_font_name_table ()
7365 for (i
= 0; i
< font_name_count
; i
++)
7366 xfree (font_name_table
[i
]);
7367 xfree (font_name_table
);
7368 font_name_table
= NULL
;
7369 font_name_table_size
= font_name_count
= 0;
7370 fm_font_family_alist
= Qnil
;
7374 enum xlfd_scalable_field_index
7376 XLFD_SCL_PIXEL_SIZE
,
7377 XLFD_SCL_POINT_SIZE
,
7382 static int xlfd_scalable_fields
[] =
7391 mac_do_list_fonts (pattern
, maxnames
)
7396 Lisp_Object font_list
= Qnil
;
7397 struct xlfdpat
*pat
;
7399 int scl_val
[XLFD_SCL_LAST
], *field
, *val
;
7402 if (font_name_table
== NULL
) /* Initialize when first used. */
7403 init_font_name_table ();
7405 for (i
= 0; i
< XLFD_SCL_LAST
; i
++)
7408 /* If the pattern contains 14 dashes and one of PIXEL_SIZE,
7409 POINT_SIZE, and AVGWIDTH fields is explicitly specified, scalable
7410 fonts are scaled according to the specified size. */
7413 field
= xlfd_scalable_fields
;
7421 if ('0' <= *ptr
&& *ptr
<= '9')
7423 *val
= *ptr
++ - '0';
7424 while ('0' <= *ptr
&& *ptr
<= '9' && *val
< 10000)
7425 *val
= *val
* 10 + *ptr
++ - '0';
7432 ptr
= strchr (ptr
, '-');
7435 while (ptr
&& i
< 14);
7437 if (i
== 14 && ptr
== NULL
)
7439 if (scl_val
[XLFD_SCL_PIXEL_SIZE
] < 0)
7440 scl_val
[XLFD_SCL_PIXEL_SIZE
] =
7441 (scl_val
[XLFD_SCL_POINT_SIZE
] > 0 ? scl_val
[XLFD_SCL_POINT_SIZE
] / 10
7442 : (scl_val
[XLFD_SCL_AVGWIDTH
] > 0 ? scl_val
[XLFD_SCL_AVGWIDTH
] / 10
7444 if (scl_val
[XLFD_SCL_POINT_SIZE
] < 0)
7445 scl_val
[XLFD_SCL_POINT_SIZE
] =
7446 (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0 ? scl_val
[XLFD_SCL_PIXEL_SIZE
] * 10
7447 : (scl_val
[XLFD_SCL_AVGWIDTH
] > 0 ? scl_val
[XLFD_SCL_AVGWIDTH
]
7449 if (scl_val
[XLFD_SCL_AVGWIDTH
] < 0)
7450 scl_val
[XLFD_SCL_AVGWIDTH
] =
7451 (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0 ? scl_val
[XLFD_SCL_PIXEL_SIZE
] * 10
7452 : (scl_val
[XLFD_SCL_POINT_SIZE
] > 0 ? scl_val
[XLFD_SCL_POINT_SIZE
]
7456 scl_val
[XLFD_SCL_PIXEL_SIZE
] = -1;
7458 pat
= xlfdpat_create (pattern
);
7462 exact
= xlfdpat_exact_p (pat
);
7464 for (i
= 0; i
< font_name_count
; i
++)
7466 if (xlfdpat_match (pat
, font_name_table
[i
]))
7468 font_list
= Fcons (build_string (font_name_table
[i
]), font_list
);
7469 if (exact
|| (maxnames
> 0 && ++n_fonts
>= maxnames
))
7472 else if (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0
7473 && (ptr
= strstr (font_name_table
[i
], "-0-0-0-0-m-0-")))
7475 int former_len
= ptr
- font_name_table
[i
];
7477 scaled
= xmalloc (strlen (font_name_table
[i
]) + 20 + 1);
7478 memcpy (scaled
, font_name_table
[i
], former_len
);
7479 sprintf (scaled
+ former_len
,
7480 "-%d-%d-72-72-m-%d-%s",
7481 scl_val
[XLFD_SCL_PIXEL_SIZE
],
7482 scl_val
[XLFD_SCL_POINT_SIZE
],
7483 scl_val
[XLFD_SCL_AVGWIDTH
],
7484 ptr
+ sizeof ("-0-0-0-0-m-0-") - 1);
7486 if (xlfdpat_match (pat
, scaled
))
7488 font_list
= Fcons (build_string (scaled
), font_list
);
7490 if (exact
|| (maxnames
> 0 && ++n_fonts
>= maxnames
))
7498 xlfdpat_destroy (pat
);
7503 /* Return a list of names of available fonts matching PATTERN on frame F.
7505 Frame F null means we have not yet created any frame on Mac, and
7506 consult the first display in x_display_list. MAXNAMES sets a limit
7507 on how many fonts to match. */
7510 x_list_fonts (f
, pattern
, size
, maxnames
)
7512 Lisp_Object pattern
;
7515 Lisp_Object list
= Qnil
, patterns
, tem
, key
;
7516 struct mac_display_info
*dpyinfo
7517 = f
? FRAME_MAC_DISPLAY_INFO (f
) : x_display_list
;
7519 xassert (size
<= 0);
7521 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
7522 if (NILP (patterns
))
7523 patterns
= Fcons (pattern
, Qnil
);
7525 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
7527 pattern
= XCAR (patterns
);
7529 if (!STRINGP (pattern
))
7532 tem
= XCAR (XCDR (dpyinfo
->name_list_element
));
7533 key
= Fcons (pattern
, make_number (maxnames
));
7535 list
= Fassoc (key
, tem
);
7538 list
= Fcdr_safe (list
);
7539 /* We have a cashed list. Don't have to get the list again. */
7544 list
= mac_do_list_fonts (SDATA (pattern
), maxnames
);
7547 /* MAC_TODO: add code for matching outline fonts here */
7549 /* Now store the result in the cache. */
7550 XSETCAR (XCDR (dpyinfo
->name_list_element
),
7551 Fcons (Fcons (key
, list
),
7552 XCAR (XCDR (dpyinfo
->name_list_element
))));
7555 if (NILP (list
)) continue; /* Try the remaining alternatives. */
7564 /* Check that FONT is valid on frame F. It is if it can be found in F's
7568 x_check_font (f
, font
)
7573 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7575 xassert (font
!= NULL
);
7577 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7578 if (dpyinfo
->font_table
[i
].name
7579 && font
== dpyinfo
->font_table
[i
].font
)
7582 xassert (i
< dpyinfo
->n_fonts
);
7585 #endif /* GLYPH_DEBUG != 0 */
7587 /* Set *W to the minimum width, *H to the minimum font height of FONT.
7588 Note: There are (broken) X fonts out there with invalid XFontStruct
7589 min_bounds contents. For example, handa@etl.go.jp reports that
7590 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
7591 have font->min_bounds.width == 0. */
7594 x_font_min_bounds (font
, w
, h
)
7595 MacFontStruct
*font
;
7598 *h
= FONT_HEIGHT (font
);
7599 *w
= font
->min_bounds
.width
;
7603 /* Compute the smallest character width and smallest font height over
7604 all fonts available on frame F. Set the members smallest_char_width
7605 and smallest_font_height in F's x_display_info structure to
7606 the values computed. Value is non-zero if smallest_font_height or
7607 smallest_char_width become smaller than they were before. */
7610 x_compute_min_glyph_bounds (f
)
7614 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7615 MacFontStruct
*font
;
7616 int old_width
= dpyinfo
->smallest_char_width
;
7617 int old_height
= dpyinfo
->smallest_font_height
;
7619 dpyinfo
->smallest_font_height
= 100000;
7620 dpyinfo
->smallest_char_width
= 100000;
7622 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
7623 if (dpyinfo
->font_table
[i
].name
)
7625 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
7628 font
= (MacFontStruct
*) fontp
->font
;
7629 xassert (font
!= (MacFontStruct
*) ~0);
7630 x_font_min_bounds (font
, &w
, &h
);
7632 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
7633 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
7636 xassert (dpyinfo
->smallest_char_width
> 0
7637 && dpyinfo
->smallest_font_height
> 0);
7639 return (dpyinfo
->n_fonts
== 1
7640 || dpyinfo
->smallest_char_width
< old_width
7641 || dpyinfo
->smallest_font_height
< old_height
);
7645 /* Determine whether given string is a fully-specified XLFD: all 14
7646 fields are present, none is '*'. */
7649 is_fully_specified_xlfd (char *p
)
7657 for (i
= 0; i
< 13; i
++)
7659 q
= strchr (p
+ 1, '-');
7662 if (q
- p
== 2 && *(p
+ 1) == '*')
7667 if (strchr (p
+ 1, '-') != NULL
)
7670 if (*(p
+ 1) == '*' && *(p
+ 2) == '\0')
7677 /* XLoadQueryFont creates and returns an internal representation for a
7678 font in a MacFontStruct struct. There is really no concept
7679 corresponding to "loading" a font on the Mac. But we check its
7680 existence and find the font number and all other information for it
7681 and store them in the returned MacFontStruct. */
7683 static MacFontStruct
*
7684 XLoadQueryFont (Display
*dpy
, char *fontname
)
7692 static ATSUFontID font_id
;
7693 ATSUStyle mac_style
= NULL
;
7696 #if TARGET_API_MAC_CARBON
7697 TextEncoding encoding
;
7702 MacFontStruct
*font
;
7703 XCharStruct
*space_bounds
= NULL
, *pcm
;
7705 if (is_fully_specified_xlfd (fontname
))
7709 Lisp_Object matched_fonts
;
7711 matched_fonts
= mac_do_list_fonts (fontname
, 1);
7712 if (NILP (matched_fonts
))
7714 name
= SDATA (XCAR (matched_fonts
));
7717 if (parse_x_font_name (name
, family
, &size
, &fontface
, charset
) == 0)
7721 if (strcmp (charset
, "iso10646-1") == 0) /* XXX */
7724 ATSUAttributeTag tags
[] = {kATSUFontTag
, kATSUSizeTag
,
7725 kATSUQDBoldfaceTag
, kATSUQDItalicTag
};
7726 ByteCount sizes
[] = {sizeof (ATSUFontID
), sizeof (Fixed
),
7727 sizeof (Boolean
), sizeof (Boolean
)};
7728 static Fixed size_fixed
;
7729 static Boolean bold_p
, italic_p
;
7730 ATSUAttributeValuePtr values
[] = {&font_id
, &size_fixed
,
7731 &bold_p
, &italic_p
};
7732 ATSUFontFeatureType types
[] = {kAllTypographicFeaturesType
,
7734 ATSUFontFeatureSelector selectors
[] = {kAllTypeFeaturesOffSelector
,
7735 kDecomposeDiacriticsSelector
};
7736 Lisp_Object font_id_cons
;
7739 font_id_cons
= Fgethash (make_unibyte_string (family
, strlen (family
)),
7740 atsu_font_id_hash
, Qnil
);
7741 if (NILP (font_id_cons
))
7743 font_id
= cons_to_long (font_id_cons
);
7744 size_fixed
= Long2Fix (size
);
7745 bold_p
= (fontface
& bold
) != 0;
7746 italic_p
= (fontface
& italic
) != 0;
7747 err
= ATSUCreateStyle (&mac_style
);
7750 err
= ATSUSetFontFeatures (mac_style
, sizeof (types
) / sizeof (types
[0]),
7754 err
= ATSUSetAttributes (mac_style
, sizeof (tags
) / sizeof (tags
[0]),
7755 tags
, sizes
, values
);
7758 err
= FMGetFontFamilyInstanceFromFont (font_id
, &fontnum
, &style
);
7761 scriptcode
= kTextEncodingMacUnicode
;
7766 Lisp_Object tmp
= Fassoc (build_string (family
), fm_font_family_alist
);
7770 fontnum
= XINT (XCDR (tmp
));
7771 #if TARGET_API_MAC_CARBON
7772 if (FMGetFontFamilyTextEncoding (fontnum
, &encoding
) != noErr
)
7774 scriptcode
= GetTextEncodingBase (encoding
);
7776 scriptcode
= FontToScript (fontnum
);
7780 font
= (MacFontStruct
*) xmalloc (sizeof (struct MacFontStruct
));
7782 font
->mac_fontnum
= fontnum
;
7783 font
->mac_fontsize
= size
;
7784 font
->mac_fontface
= fontface
;
7785 font
->mac_scriptcode
= scriptcode
;
7787 font
->mac_style
= mac_style
;
7788 #if USE_CG_TEXT_DRAWING
7789 font
->cg_font
= NULL
;
7790 font
->cg_glyphs
= NULL
;
7794 /* Apple Japanese (SJIS) font is listed as both
7795 "*-jisx0208.1983-sjis" (Japanese script) and "*-jisx0201.1976-0"
7796 (Roman script) in init_font_name_table (). The latter should be
7797 treated as a one-byte font. */
7798 if (scriptcode
== smJapanese
&& strcmp (charset
, "jisx0201.1976-0") == 0)
7799 font
->mac_scriptcode
= smRoman
;
7801 font
->full_name
= mac_to_x_fontname (family
, size
, fontface
, charset
);
7804 if (font
->mac_style
)
7809 font
->min_byte1
= 0;
7810 font
->max_byte1
= 0xff;
7811 font
->min_char_or_byte2
= 0;
7812 font
->max_char_or_byte2
= 0xff;
7814 font
->bounds
.rows
= xmalloc (sizeof (XCharStruct
*) * 0x100);
7815 bzero (font
->bounds
.rows
, sizeof (XCharStruct
*) * 0x100);
7816 font
->bounds
.rows
[0] = xmalloc (sizeof (XCharStruct
) * 0x100);
7817 pcm_init (font
->bounds
.rows
[0], 0x100);
7819 #if USE_CG_TEXT_DRAWING
7823 ATSFontRef ats_font
;
7825 err
= FMGetFontFromFontFamilyInstance (fontnum
, fontface
,
7827 /* Use CG text drawing if italic/bold is not synthesized. */
7828 if (err
== noErr
&& style
== fontface
)
7830 ats_font
= FMGetATSFontRefFromFont (font_id
);
7831 font
->cg_font
= CGFontCreateWithPlatformFont (&ats_font
);
7837 font
->cg_glyphs
= xmalloc (sizeof (CGGlyph
) * 0x100);
7838 bzero (font
->cg_glyphs
, sizeof (CGGlyph
) * 0x100);
7841 space_bounds
= font
->bounds
.rows
[0] + 0x20;
7842 err
= mac_query_char_extents (font
->mac_style
, 0x20,
7843 &font
->ascent
, &font
->descent
,
7845 #if USE_CG_TEXT_DRAWING
7846 (font
->cg_glyphs
? font
->cg_glyphs
+ 0x20
7854 mac_unload_font (&one_mac_display_info
, font
);
7858 pcm
= font
->bounds
.rows
[0];
7859 for (c
= 0x21; c
<= 0xff; c
++)
7862 /* Soft hyphen is not supported in ATSUI. */
7870 mac_query_char_extents (font
->mac_style
, c
, NULL
, NULL
, pcm
+ c
,
7871 #if USE_CG_TEXT_DRAWING
7872 (font
->cg_glyphs
? font
->cg_glyphs
+ c
7879 #if USE_CG_TEXT_DRAWING
7880 if (font
->cg_glyphs
&& font
->cg_glyphs
[c
] == 0)
7882 /* Don't use CG text drawing if font substitution occurs in
7883 ASCII or Latin-1 characters. */
7884 CGFontRelease (font
->cg_font
);
7885 font
->cg_font
= NULL
;
7886 xfree (font
->cg_glyphs
);
7887 font
->cg_glyphs
= NULL
;
7896 SInt16 old_fontnum
, old_fontsize
;
7898 FontInfo the_fontinfo
;
7899 int is_two_byte_font
;
7901 /* Save the current font number used. */
7903 #if TARGET_API_MAC_CARBON
7904 old_fontnum
= GetPortTextFont (port
);
7905 old_fontsize
= GetPortTextSize (port
);
7906 old_fontface
= GetPortTextFace (port
);
7908 old_fontnum
= port
->txFont
;
7909 old_fontsize
= port
->txSize
;
7910 old_fontface
= port
->txFace
;
7915 TextFace (fontface
);
7917 GetFontInfo (&the_fontinfo
);
7919 font
->ascent
= the_fontinfo
.ascent
;
7920 font
->descent
= the_fontinfo
.descent
;
7922 is_two_byte_font
= (font
->mac_scriptcode
== smJapanese
7923 || font
->mac_scriptcode
== smTradChinese
7924 || font
->mac_scriptcode
== smSimpChinese
7925 || font
->mac_scriptcode
== smKorean
);
7927 if (is_two_byte_font
)
7931 font
->min_byte1
= 0xa1;
7932 font
->max_byte1
= 0xfe;
7933 font
->min_char_or_byte2
= 0xa1;
7934 font
->max_char_or_byte2
= 0xfe;
7936 /* Use the width of an "ideographic space" of that font
7937 because the_fontinfo.widMax returns the wrong width for
7939 switch (font
->mac_scriptcode
)
7942 font
->min_byte1
= 0x81;
7943 font
->max_byte1
= 0xfc;
7944 font
->min_char_or_byte2
= 0x40;
7945 font
->max_char_or_byte2
= 0xfc;
7946 char_width
= StringWidth("\p\x81\x40");
7949 font
->min_char_or_byte2
= 0x40;
7950 char_width
= StringWidth("\p\xa1\x40");
7953 char_width
= StringWidth("\p\xa1\xa1");
7956 char_width
= StringWidth("\p\xa1\xa1");
7960 font
->bounds
.per_char
= NULL
;
7962 if (fontface
& italic
)
7963 font
->max_bounds
.rbearing
= char_width
+ 1;
7965 font
->max_bounds
.rbearing
= char_width
;
7966 font
->max_bounds
.lbearing
= 0;
7967 font
->max_bounds
.width
= char_width
;
7968 font
->max_bounds
.ascent
= the_fontinfo
.ascent
;
7969 font
->max_bounds
.descent
= the_fontinfo
.descent
;
7971 font
->min_bounds
= font
->max_bounds
;
7977 font
->min_byte1
= font
->max_byte1
= 0;
7978 font
->min_char_or_byte2
= 0x20;
7979 font
->max_char_or_byte2
= 0xff;
7981 font
->bounds
.per_char
=
7982 xmalloc (sizeof (XCharStruct
) * (0xff - 0x20 + 1));
7983 bzero (font
->bounds
.per_char
,
7984 sizeof (XCharStruct
) * (0xff - 0x20 + 1));
7986 space_bounds
= font
->bounds
.per_char
;
7987 mac_query_char_extents (NULL
, 0x20, &font
->ascent
, &font
->descent
,
7988 space_bounds
, NULL
);
7990 for (c
= 0x21, pcm
= space_bounds
+ 1; c
<= 0xff; c
++, pcm
++)
7991 mac_query_char_extents (NULL
, c
, NULL
, NULL
, pcm
, NULL
);
7994 /* Restore previous font number, size and face. */
7995 TextFont (old_fontnum
);
7996 TextSize (old_fontsize
);
7997 TextFace (old_fontface
);
8004 font
->min_bounds
= font
->max_bounds
= *space_bounds
;
8005 for (c
= 0x21, pcm
= space_bounds
+ 1; c
<= 0x7f; c
++, pcm
++)
8008 font
->min_bounds
.lbearing
= min (font
->min_bounds
.lbearing
,
8010 font
->min_bounds
.rbearing
= min (font
->min_bounds
.rbearing
,
8012 font
->min_bounds
.width
= min (font
->min_bounds
.width
,
8014 font
->min_bounds
.ascent
= min (font
->min_bounds
.ascent
,
8017 font
->max_bounds
.lbearing
= max (font
->max_bounds
.lbearing
,
8019 font
->max_bounds
.rbearing
= max (font
->max_bounds
.rbearing
,
8021 font
->max_bounds
.width
= max (font
->max_bounds
.width
,
8023 font
->max_bounds
.ascent
= max (font
->max_bounds
.ascent
,
8028 font
->mac_style
== NULL
&&
8030 font
->max_bounds
.width
== font
->min_bounds
.width
8031 && font
->min_bounds
.lbearing
>= 0
8032 && font
->max_bounds
.rbearing
<= font
->max_bounds
.width
)
8034 /* Fixed width and no overhangs. */
8035 xfree (font
->bounds
.per_char
);
8036 font
->bounds
.per_char
= NULL
;
8040 #if !defined (MAC_OS8) || USE_ATSUI
8041 /* AppKit and WebKit do some adjustment to the heights of Courier,
8042 Helvetica, and Times. This only works on the environments where
8043 srcCopy text transfer mode is never used. */
8045 #ifdef MAC_OS8 /* implies USE_ATSUI */
8048 (strcmp (family
, "courier") == 0 || strcmp (family
, "helvetica") == 0
8049 || strcmp (family
, "times") == 0))
8050 font
->ascent
+= (font
->ascent
+ font
->descent
) * .15 + 0.5;
8058 mac_unload_font (dpyinfo
, font
)
8059 struct mac_display_info
*dpyinfo
;
8062 xfree (font
->full_name
);
8064 if (font
->mac_style
)
8068 for (i
= font
->min_byte1
; i
<= font
->max_byte1
; i
++)
8069 if (font
->bounds
.rows
[i
])
8070 xfree (font
->bounds
.rows
[i
]);
8071 xfree (font
->bounds
.rows
);
8072 ATSUDisposeStyle (font
->mac_style
);
8076 if (font
->bounds
.per_char
)
8077 xfree (font
->bounds
.per_char
);
8078 #if USE_CG_TEXT_DRAWING
8080 CGFontRelease (font
->cg_font
);
8081 if (font
->cg_glyphs
)
8082 xfree (font
->cg_glyphs
);
8088 /* Load font named FONTNAME of the size SIZE for frame F, and return a
8089 pointer to the structure font_info while allocating it dynamically.
8090 If SIZE is 0, load any size of font.
8091 If loading is failed, return NULL. */
8094 x_load_font (f
, fontname
, size
)
8096 register char *fontname
;
8099 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
8100 Lisp_Object font_names
;
8102 /* Get a list of all the fonts that match this name. Once we
8103 have a list of matching fonts, we compare them against the fonts
8104 we already have by comparing names. */
8105 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
8107 if (!NILP (font_names
))
8112 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
8113 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
8114 if (dpyinfo
->font_table
[i
].name
8115 && (!strcmp (dpyinfo
->font_table
[i
].name
,
8116 SDATA (XCAR (tail
)))
8117 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
8118 SDATA (XCAR (tail
)))))
8119 return (dpyinfo
->font_table
+ i
);
8124 /* Load the font and add it to the table. */
8126 struct MacFontStruct
*font
;
8127 struct font_info
*fontp
;
8130 fontname
= (char *) SDATA (XCAR (font_names
));
8133 font
= (MacFontStruct
*) XLoadQueryFont (FRAME_MAC_DISPLAY (f
), fontname
);
8138 /* Find a free slot in the font table. */
8139 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
8140 if (dpyinfo
->font_table
[i
].name
== NULL
)
8143 /* If no free slot found, maybe enlarge the font table. */
8144 if (i
== dpyinfo
->n_fonts
8145 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
8148 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
8149 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
8151 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
8154 fontp
= dpyinfo
->font_table
+ i
;
8155 if (i
== dpyinfo
->n_fonts
)
8158 /* Now fill in the slots of *FONTP. */
8160 bzero (fontp
, sizeof (*fontp
));
8162 fontp
->font_idx
= i
;
8163 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
8164 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
8166 if (font
->min_bounds
.width
== font
->max_bounds
.width
)
8168 /* Fixed width font. */
8169 fontp
->average_width
= fontp
->space_width
= font
->min_bounds
.width
;
8176 char2b
.byte1
= 0x00, char2b
.byte2
= 0x20;
8177 pcm
= mac_per_char_metric (font
, &char2b
, 0);
8179 fontp
->space_width
= pcm
->width
;
8181 fontp
->space_width
= FONT_WIDTH (font
);
8185 int width
= pcm
->width
;
8186 for (char2b
.byte2
= 33; char2b
.byte2
<= 126; char2b
.byte2
++)
8187 if ((pcm
= mac_per_char_metric (font
, &char2b
, 0)) != NULL
)
8188 width
+= pcm
->width
;
8189 fontp
->average_width
= width
/ 95;
8192 fontp
->average_width
= FONT_WIDTH (font
);
8195 fontp
->full_name
= (char *) xmalloc (strlen (font
->full_name
) + 1);
8196 bcopy (font
->full_name
, fontp
->full_name
, strlen (font
->full_name
) + 1);
8198 fontp
->size
= font
->max_bounds
.width
;
8199 fontp
->height
= FONT_HEIGHT (font
);
8201 /* For some font, ascent and descent in max_bounds field is
8202 larger than the above value. */
8203 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
8204 if (max_height
> fontp
->height
)
8205 fontp
->height
= max_height
;
8208 /* The slot `encoding' specifies how to map a character
8209 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
8210 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
8211 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
8212 2:0xA020..0xFF7F). For the moment, we don't know which charset
8213 uses this font. So, we set information in fontp->encoding[1]
8214 which is never used by any charset. If mapping can't be
8215 decided, set FONT_ENCODING_NOT_DECIDED. */
8216 if (font
->mac_scriptcode
== smJapanese
)
8217 fontp
->encoding
[1] = 4;
8221 = (font
->max_byte1
== 0
8223 ? (font
->min_char_or_byte2
< 0x80
8224 ? (font
->max_char_or_byte2
< 0x80
8225 ? 0 /* 0x20..0x7F */
8226 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
8227 : 1) /* 0xA0..0xFF */
8229 : (font
->min_byte1
< 0x80
8230 ? (font
->max_byte1
< 0x80
8231 ? (font
->min_char_or_byte2
< 0x80
8232 ? (font
->max_char_or_byte2
< 0x80
8233 ? 0 /* 0x2020..0x7F7F */
8234 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
8235 : 3) /* 0x20A0..0x7FFF */
8236 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
8237 : (font
->min_char_or_byte2
< 0x80
8238 ? (font
->max_char_or_byte2
< 0x80
8239 ? 2 /* 0xA020..0xFF7F */
8240 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
8241 : 1))); /* 0xA0A0..0xFFFF */
8244 #if 0 /* MAC_TODO: fill these out with more reasonably values */
8245 fontp
->baseline_offset
8246 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
8247 ? (long) value
: 0);
8248 fontp
->relative_compose
8249 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
8250 ? (long) value
: 0);
8251 fontp
->default_ascent
8252 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
8253 ? (long) value
: 0);
8255 fontp
->baseline_offset
= 0;
8256 fontp
->relative_compose
= 0;
8257 fontp
->default_ascent
= 0;
8260 /* Set global flag fonts_changed_p to non-zero if the font loaded
8261 has a character with a smaller width than any other character
8262 before, or if the font loaded has a smaller height than any
8263 other font loaded before. If this happens, it will make a
8264 glyph matrix reallocation necessary. */
8265 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
8272 /* Return a pointer to struct font_info of a font named FONTNAME for
8273 frame F. If no such font is loaded, return NULL. */
8276 x_query_font (f
, fontname
)
8278 register char *fontname
;
8280 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
8283 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
8284 if (dpyinfo
->font_table
[i
].name
8285 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
8286 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
8287 return (dpyinfo
->font_table
+ i
);
8292 /* Find a CCL program for a font specified by FONTP, and set the member
8293 `encoder' of the structure. */
8296 x_find_ccl_program (fontp
)
8297 struct font_info
*fontp
;
8299 Lisp_Object list
, elt
;
8301 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
8305 && STRINGP (XCAR (elt
))
8306 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
8312 struct ccl_program
*ccl
8313 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
8315 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
8318 fontp
->font_encoder
= ccl
;
8322 #if USE_MAC_FONT_PANEL
8324 mac_set_font_info_for_selection (f
, face_id
, c
)
8329 EventTargetRef target
= NULL
;
8330 XFontStruct
*font
= NULL
;
8334 target
= GetWindowEventTarget (FRAME_MAC_WINDOW (f
));
8336 if (FRAME_FACE_CACHE (f
) && CHAR_VALID_P (c
, 0))
8340 face_id
= FACE_FOR_CHAR (f
, FACE_FROM_ID (f
, face_id
), c
);
8341 face
= FACE_FROM_ID (f
, face_id
);
8347 err
= SetFontInfoForSelection (kFontSelectionATSUIType
, 0, NULL
, target
);
8350 if (font
->mac_fontnum
!= -1)
8352 FontSelectionQDStyle qd_style
;
8354 qd_style
.version
= kFontSelectionQDStyleVersionZero
;
8355 qd_style
.instance
.fontFamily
= font
->mac_fontnum
;
8356 qd_style
.instance
.fontStyle
= font
->mac_fontface
;
8357 qd_style
.size
= font
->mac_fontsize
;
8358 qd_style
.hasColor
= false;
8360 err
= SetFontInfoForSelection (kFontSelectionQDType
,
8361 1, &qd_style
, target
);
8364 err
= SetFontInfoForSelection (kFontSelectionATSUIType
,
8365 1, &font
->mac_style
, target
);
8373 /* The Mac Event loop code */
8375 #if !TARGET_API_MAC_CARBON
8377 #include <Quickdraw.h>
8378 #include <Balloons.h>
8379 #include <Devices.h>
8381 #include <Gestalt.h>
8383 #include <Processes.h>
8385 #include <ToolUtils.h>
8386 #include <TextUtils.h>
8387 #include <Dialogs.h>
8390 #include <Resources.h>
8395 #endif /* ! TARGET_API_MAC_CARBON */
8400 #define WINDOW_RESOURCE 128
8401 #define TERM_WINDOW_RESOURCE 129
8403 #define DEFAULT_NUM_COLS 80
8405 #define MIN_DOC_SIZE 64
8406 #define MAX_DOC_SIZE 32767
8408 #define EXTRA_STACK_ALLOC (256 * 1024)
8410 #define ARGV_STRING_LIST_ID 129
8411 #define ABOUT_ALERT_ID 128
8412 #define RAM_TOO_LARGE_ALERT_ID 129
8414 /* Contains the string "reverse", which is a constant for mouse button emu.*/
8415 Lisp_Object Qreverse
;
8418 /* Modifier associated with the control key, or nil to ignore. */
8419 Lisp_Object Vmac_control_modifier
;
8421 /* Modifier associated with the option key, or nil to ignore. */
8422 Lisp_Object Vmac_option_modifier
;
8424 /* Modifier associated with the command key, or nil to ignore. */
8425 Lisp_Object Vmac_command_modifier
;
8427 /* Modifier associated with the function key, or nil to ignore. */
8428 Lisp_Object Vmac_function_modifier
;
8430 /* True if the option and command modifiers should be used to emulate
8431 a three button mouse */
8432 Lisp_Object Vmac_emulate_three_button_mouse
;
8434 #if USE_CARBON_EVENTS
8435 /* Non-zero if the mouse wheel button (i.e. button 4) should map to
8436 mouse-2, instead of mouse-3. */
8437 int mac_wheel_button_is_mouse_2
;
8439 /* If non-zero, the Mac "Command" key is passed on to the Mac Toolbox
8440 for processing before Emacs sees it. */
8441 int mac_pass_command_to_system
;
8443 /* If non-zero, the Mac "Control" key is passed on to the Mac Toolbox
8444 for processing before Emacs sees it. */
8445 int mac_pass_control_to_system
;
8448 /* Points to the variable `inev' in the function XTread_socket. It is
8449 used for passing an input event to the function back from
8450 Carbon/Apple event handlers. */
8451 static struct input_event
*read_socket_inev
= NULL
;
8453 Point saved_menu_event_location
;
8456 #if USE_CARBON_EVENTS
8457 static Lisp_Object Qhicommand
;
8459 extern Lisp_Object Qwindow
;
8460 static Lisp_Object Qtoolbar_switch_mode
;
8462 #if USE_MAC_FONT_PANEL
8463 extern Lisp_Object Qfont
;
8464 static Lisp_Object Qpanel_closed
, Qselection
;
8467 extern int mac_ready_for_apple_events
;
8468 extern Lisp_Object Qundefined
;
8469 extern void init_apple_event_handler
P_ ((void));
8470 extern void mac_find_apple_event_spec
P_ ((AEEventClass
, AEEventID
,
8471 Lisp_Object
*, Lisp_Object
*,
8473 extern OSErr init_coercion_handler
P_ ((void));
8476 OSErr install_drag_handler
P_ ((WindowRef
));
8477 void remove_drag_handler
P_ ((WindowRef
));
8479 #if USE_CARBON_EVENTS
8481 extern void init_service_handler ();
8482 static Lisp_Object Qservice
, Qpaste
, Qperform
;
8484 /* Window Event Handler */
8485 static pascal OSStatus
mac_handle_window_event (EventHandlerCallRef
,
8488 OSErr
install_window_handler (WindowPtr
);
8490 extern void init_emacs_passwd_dir ();
8491 extern int emacs_main (int, char **, char **);
8493 extern void initialize_applescript();
8494 extern void terminate_applescript();
8497 #if USE_CARBON_EVENTS
8498 mac_to_emacs_modifiers (UInt32 mods
)
8500 mac_to_emacs_modifiers (EventModifiers mods
)
8503 unsigned int result
= 0;
8504 if (mods
& shiftKey
)
8505 result
|= shift_modifier
;
8507 /* Deactivated to simplify configuration:
8508 if Vmac_option_modifier is non-NIL, we fully process the Option
8509 key. Otherwise, we only process it if an additional Ctrl or Command
8510 is pressed. That way the system may convert the character to a
8512 if ((mods & optionKey) &&
8513 (( !NILP(Vmac_option_modifier) ||
8514 ((mods & cmdKey) || (mods & controlKey))))) */
8516 if (!NILP (Vmac_option_modifier
) && (mods
& optionKey
)) {
8517 Lisp_Object val
= Fget(Vmac_option_modifier
, Qmodifier_value
);
8519 result
|= XUINT(val
);
8521 if (!NILP (Vmac_command_modifier
) && (mods
& cmdKey
)) {
8522 Lisp_Object val
= Fget(Vmac_command_modifier
, Qmodifier_value
);
8524 result
|= XUINT(val
);
8526 if (!NILP (Vmac_control_modifier
) && (mods
& controlKey
)) {
8527 Lisp_Object val
= Fget(Vmac_control_modifier
, Qmodifier_value
);
8529 result
|= XUINT(val
);
8533 if (!NILP (Vmac_function_modifier
) && (mods
& kEventKeyModifierFnMask
)) {
8534 Lisp_Object val
= Fget(Vmac_function_modifier
, Qmodifier_value
);
8536 result
|= XUINT(val
);
8544 mac_get_emulated_btn ( UInt32 modifiers
)
8547 if (!NILP (Vmac_emulate_three_button_mouse
)) {
8548 int cmdIs3
= !EQ (Vmac_emulate_three_button_mouse
, Qreverse
);
8549 if (modifiers
& cmdKey
)
8550 result
= cmdIs3
? 2 : 1;
8551 else if (modifiers
& optionKey
)
8552 result
= cmdIs3
? 1 : 2;
8557 #if USE_CARBON_EVENTS
8558 /* Obtains the event modifiers from the event ref and then calls
8559 mac_to_emacs_modifiers. */
8561 mac_event_to_emacs_modifiers (EventRef eventRef
)
8564 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
8565 sizeof (UInt32
), NULL
, &mods
);
8566 if (!NILP (Vmac_emulate_three_button_mouse
) &&
8567 GetEventClass(eventRef
) == kEventClassMouse
)
8569 mods
&= ~(optionKey
| cmdKey
);
8571 return mac_to_emacs_modifiers (mods
);
8574 /* Given an event ref, return the code to use for the mouse button
8575 code in the emacs input_event. */
8577 mac_get_mouse_btn (EventRef ref
)
8579 EventMouseButton result
= kEventMouseButtonPrimary
;
8580 GetEventParameter (ref
, kEventParamMouseButton
, typeMouseButton
, NULL
,
8581 sizeof (EventMouseButton
), NULL
, &result
);
8584 case kEventMouseButtonPrimary
:
8585 if (NILP (Vmac_emulate_three_button_mouse
))
8589 GetEventParameter (ref
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
8590 sizeof (UInt32
), NULL
, &mods
);
8591 return mac_get_emulated_btn(mods
);
8593 case kEventMouseButtonSecondary
:
8594 return mac_wheel_button_is_mouse_2
? 2 : 1;
8595 case kEventMouseButtonTertiary
:
8596 case 4: /* 4 is the number for the mouse wheel button */
8597 return mac_wheel_button_is_mouse_2
? 1 : 2;
8603 /* Normally, ConvertEventRefToEventRecord will correctly handle all
8604 events. However the click of the mouse wheel is not converted to a
8605 mouseDown or mouseUp event. Likewise for dead key down events.
8606 This calls ConvertEventRef, but then checks to see if it is a mouse
8607 up/down, or a dead key down carbon event that has not been
8608 converted, and if so, converts it by hand (to be picked up in the
8609 XTread_socket loop). */
8610 static Boolean
mac_convert_event_ref (EventRef eventRef
, EventRecord
*eventRec
)
8613 Boolean result
= ConvertEventRefToEventRecord (eventRef
, eventRec
);
8618 switch (GetEventClass (eventRef
))
8620 case kEventClassMouse
:
8621 switch (GetEventKind (eventRef
))
8623 case kEventMouseDown
:
8624 eventRec
->what
= mouseDown
;
8629 eventRec
->what
= mouseUp
;
8638 case kEventClassKeyboard
:
8639 switch (GetEventKind (eventRef
))
8641 case kEventRawKeyDown
:
8643 unsigned char char_codes
;
8646 err
= GetEventParameter (eventRef
, kEventParamKeyMacCharCodes
,
8647 typeChar
, NULL
, sizeof (char),
8650 err
= GetEventParameter (eventRef
, kEventParamKeyCode
,
8651 typeUInt32
, NULL
, sizeof (UInt32
),
8655 eventRec
->what
= keyDown
;
8656 eventRec
->message
= char_codes
| ((key_code
& 0xff) << 8);
8673 /* Need where and when. */
8676 GetEventParameter (eventRef
, kEventParamMouseLocation
, typeQDPoint
,
8677 NULL
, sizeof (Point
), NULL
, &eventRec
->where
);
8678 /* Use two step process because new event modifiers are 32-bit
8679 and old are 16-bit. Currently, only loss is NumLock & Fn. */
8680 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
,
8681 NULL
, sizeof (UInt32
), NULL
, &mods
);
8682 eventRec
->modifiers
= mods
;
8684 eventRec
->when
= EventTimeToTicks (GetEventTime (eventRef
));
8696 Handle menubar_handle
;
8697 MenuHandle menu_handle
;
8699 menubar_handle
= GetNewMBar (128);
8700 if(menubar_handle
== NULL
)
8702 SetMenuBar (menubar_handle
);
8705 #if !TARGET_API_MAC_CARBON
8706 menu_handle
= GetMenuHandle (M_APPLE
);
8707 if(menu_handle
!= NULL
)
8708 AppendResMenu (menu_handle
,'DRVR');
8716 do_init_managers (void)
8718 #if !TARGET_API_MAC_CARBON
8719 InitGraf (&qd
.thePort
);
8721 FlushEvents (everyEvent
, 0);
8726 #endif /* !TARGET_API_MAC_CARBON */
8729 #if !TARGET_API_MAC_CARBON
8730 /* set up some extra stack space for use by emacs */
8731 SetApplLimit ((Ptr
) ((long) GetApplLimit () - EXTRA_STACK_ALLOC
));
8733 /* MaxApplZone must be called for AppleScript to execute more
8734 complicated scripts */
8737 #endif /* !TARGET_API_MAC_CARBON */
8741 do_check_ram_size (void)
8743 SInt32 physical_ram_size
, logical_ram_size
;
8745 if (Gestalt (gestaltPhysicalRAMSize
, &physical_ram_size
) != noErr
8746 || Gestalt (gestaltLogicalRAMSize
, &logical_ram_size
) != noErr
8747 || physical_ram_size
> (1 << VALBITS
)
8748 || logical_ram_size
> (1 << VALBITS
))
8750 StopAlert (RAM_TOO_LARGE_ALERT_ID
, NULL
);
8754 #endif /* MAC_OS8 */
8757 do_window_update (WindowPtr win
)
8759 struct frame
*f
= mac_window_to_frame (win
);
8763 /* The tooltip has been drawn already. Avoid the SET_FRAME_GARBAGED
8765 if (win
!= tip_window
)
8767 if (f
->async_visible
== 0)
8769 /* Update events may occur when a frame gets iconified. */
8771 f
->async_visible
= 1;
8772 f
->async_iconified
= 0;
8773 SET_FRAME_GARBAGED (f
);
8779 #if TARGET_API_MAC_CARBON
8780 RgnHandle region
= NewRgn ();
8782 GetPortVisibleRegion (GetWindowPort (win
), region
);
8783 GetRegionBounds (region
, &r
);
8784 expose_frame (f
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
);
8785 UpdateControls (win
, region
);
8786 DisposeRgn (region
);
8788 r
= (*win
->visRgn
)->rgnBBox
;
8789 expose_frame (f
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
);
8790 UpdateControls (win
, win
->visRgn
);
8799 is_emacs_window (WindowPtr win
)
8801 Lisp_Object tail
, frame
;
8806 FOR_EACH_FRAME (tail
, frame
)
8807 if (FRAME_MAC_P (XFRAME (frame
)))
8808 if (FRAME_MAC_WINDOW (XFRAME (frame
)) == win
)
8817 /* Window-activate events will do the job. */
8823 /* Window-deactivate events will do the job. */
8828 do_apple_menu (SInt16 menu_item
)
8830 #if !TARGET_API_MAC_CARBON
8832 SInt16 da_driver_refnum
;
8834 if (menu_item
== I_ABOUT
)
8835 NoteAlert (ABOUT_ALERT_ID
, NULL
);
8838 GetMenuItemText (GetMenuHandle (M_APPLE
), menu_item
, item_name
);
8839 da_driver_refnum
= OpenDeskAcc (item_name
);
8841 #endif /* !TARGET_API_MAC_CARBON */
8845 do_menu_choice (SInt32 menu_choice
)
8847 SInt16 menu_id
, menu_item
;
8849 menu_id
= HiWord (menu_choice
);
8850 menu_item
= LoWord (menu_choice
);
8858 do_apple_menu (menu_item
);
8863 struct frame
*f
= mac_focus_frame (&one_mac_display_info
);
8864 MenuHandle menu
= GetMenuHandle (menu_id
);
8869 GetMenuItemRefCon (menu
, menu_item
, &refcon
);
8870 menubar_selection_callback (f
, refcon
);
8879 /* Handle drags in size box. Based on code contributed by Ben
8880 Mesander and IM - Window Manager A. */
8883 do_grow_window (WindowPtr w
, EventRecord
*e
)
8886 int rows
, columns
, width
, height
;
8887 struct frame
*f
= mac_window_to_frame (w
);
8888 XSizeHints
*size_hints
= FRAME_SIZE_HINTS (f
);
8889 int min_width
= MIN_DOC_SIZE
, min_height
= MIN_DOC_SIZE
;
8890 #if TARGET_API_MAC_CARBON
8896 if (size_hints
->flags
& PMinSize
)
8898 min_width
= size_hints
->min_width
;
8899 min_height
= size_hints
->min_height
;
8901 SetRect (&limit_rect
, min_width
, min_height
, MAX_DOC_SIZE
, MAX_DOC_SIZE
);
8903 #if TARGET_API_MAC_CARBON
8904 if (!ResizeWindow (w
, e
->where
, &limit_rect
, &new_rect
))
8906 height
= new_rect
.bottom
- new_rect
.top
;
8907 width
= new_rect
.right
- new_rect
.left
;
8909 grow_size
= GrowWindow (w
, e
->where
, &limit_rect
);
8910 /* see if it really changed size */
8913 height
= HiWord (grow_size
);
8914 width
= LoWord (grow_size
);
8917 if (width
!= FRAME_PIXEL_WIDTH (f
)
8918 || height
!= FRAME_PIXEL_HEIGHT (f
))
8920 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, height
);
8921 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, width
);
8923 x_set_window_size (f
, 0, columns
, rows
);
8928 /* Handle clicks in zoom box. Calculation of "standard state" based
8929 on code in IM - Window Manager A and code contributed by Ben
8930 Mesander. The standard state of an Emacs window is 80-characters
8931 wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */
8934 do_zoom_window (WindowPtr w
, int zoom_in_or_out
)
8936 Rect zoom_rect
, port_rect
;
8937 int columns
, rows
, width
, height
;
8938 struct frame
*f
= mac_window_to_frame (w
);
8939 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
8940 #if TARGET_API_MAC_CARBON
8941 Point standard_size
;
8943 standard_size
.h
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
8944 standard_size
.v
= dpyinfo
->height
;
8946 if (IsWindowInStandardState (w
, &standard_size
, &zoom_rect
))
8947 zoom_in_or_out
= inZoomIn
;
8950 /* Adjust the standard size according to character boundaries. */
8952 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, zoom_rect
.right
- zoom_rect
.left
);
8953 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, zoom_rect
.bottom
- zoom_rect
.top
);
8954 standard_size
.h
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, columns
);
8955 standard_size
.v
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
8956 GetWindowBounds (w
, kWindowContentRgn
, &port_rect
);
8957 if (IsWindowInStandardState (w
, &standard_size
, &zoom_rect
)
8958 && port_rect
.left
== zoom_rect
.left
8959 && port_rect
.top
== zoom_rect
.top
)
8960 zoom_in_or_out
= inZoomIn
;
8962 zoom_in_or_out
= inZoomOut
;
8965 ZoomWindowIdeal (w
, zoom_in_or_out
, &standard_size
);
8966 #else /* not TARGET_API_MAC_CARBON */
8971 GetPort (&save_port
);
8973 SetPortWindowPort (w
);
8975 /* Clear window to avoid flicker. */
8976 EraseRect (&(w
->portRect
));
8977 if (zoom_in_or_out
== inZoomOut
)
8979 SetPt (&top_left
, w
->portRect
.left
, w
->portRect
.top
);
8980 LocalToGlobal (&top_left
);
8982 /* calculate height of window's title bar */
8983 w_title_height
= top_left
.v
- 1
8984 - (**((WindowPeek
) w
)->strucRgn
).rgnBBox
.top
+ GetMBarHeight ();
8986 /* get maximum height of window into zoom_rect.bottom - zoom_rect.top */
8987 zoom_rect
= qd
.screenBits
.bounds
;
8988 zoom_rect
.top
+= w_title_height
;
8989 InsetRect (&zoom_rect
, 8, 4); /* not too tight */
8991 zoom_rect
.right
= zoom_rect
.left
8992 + FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
8994 /* Adjust the standard size according to character boundaries. */
8995 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, zoom_rect
.bottom
- zoom_rect
.top
);
8997 zoom_rect
.top
+ FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
8999 (**((WStateDataHandle
) ((WindowPeek
) w
)->dataHandle
)).stdState
9003 ZoomWindow (w
, zoom_in_or_out
, f
== mac_focus_frame (dpyinfo
));
9005 SetPort (save_port
);
9006 #endif /* not TARGET_API_MAC_CARBON */
9008 /* retrieve window size and update application values */
9009 #if TARGET_API_MAC_CARBON
9010 GetWindowPortBounds (w
, &port_rect
);
9012 port_rect
= w
->portRect
;
9014 height
= port_rect
.bottom
- port_rect
.top
;
9015 width
= port_rect
.right
- port_rect
.left
;
9017 if (width
!= FRAME_PIXEL_WIDTH (f
)
9018 || height
!= FRAME_PIXEL_HEIGHT (f
))
9020 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, height
);
9021 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, width
);
9023 change_frame_size (f
, rows
, columns
, 0, 1, 0);
9024 SET_FRAME_GARBAGED (f
);
9025 cancel_mouse_face (f
);
9027 FRAME_PIXEL_WIDTH (f
) = width
;
9028 FRAME_PIXEL_HEIGHT (f
) = height
;
9030 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
9034 mac_store_apple_event (class, id
, desc
)
9035 Lisp_Object
class, id
;
9038 struct input_event buf
;
9042 buf
.kind
= MAC_APPLE_EVENT
;
9045 XSETFRAME (buf
.frame_or_window
,
9046 mac_focus_frame (&one_mac_display_info
));
9047 /* Now that Lisp object allocations are protected by BLOCK_INPUT, it
9048 is safe to use them during read_socket_hook. */
9049 buf
.arg
= mac_aedesc_to_lisp (desc
);
9050 kbd_buffer_store_event (&buf
);
9053 #if TARGET_API_MAC_CARBON
9055 mac_store_event_ref_as_apple_event (class, id
, class_key
, id_key
,
9056 event
, num_params
, names
, types
)
9059 Lisp_Object class_key
, id_key
;
9062 EventParamName
*names
;
9063 EventParamType
*types
;
9065 OSStatus err
= eventNotHandledErr
;
9066 Lisp_Object binding
;
9068 mac_find_apple_event_spec (class, id
, &class_key
, &id_key
, &binding
);
9069 if (!NILP (binding
) && !EQ (binding
, Qundefined
))
9071 if (INTEGERP (binding
))
9072 err
= XINT (binding
);
9075 AppleEvent apple_event
;
9076 err
= create_apple_event_from_event_ref (event
, num_params
,
9081 mac_store_apple_event (class_key
, id_key
, &apple_event
);
9082 AEDisposeDesc (&apple_event
);
9091 mac_store_drag_event (window
, mouse_pos
, modifiers
, desc
)
9097 struct input_event buf
;
9101 buf
.kind
= DRAG_N_DROP_EVENT
;
9102 buf
.modifiers
= mac_to_emacs_modifiers (modifiers
);
9103 buf
.timestamp
= TickCount () * (1000 / 60);
9104 XSETINT (buf
.x
, mouse_pos
.h
);
9105 XSETINT (buf
.y
, mouse_pos
.v
);
9106 XSETFRAME (buf
.frame_or_window
, mac_window_to_frame (window
));
9107 buf
.arg
= mac_aedesc_to_lisp (desc
);
9108 kbd_buffer_store_event (&buf
);
9112 #if USE_CARBON_EVENTS
9113 static pascal OSStatus
9114 mac_handle_command_event (next_handler
, event
, data
)
9115 EventHandlerCallRef next_handler
;
9119 OSStatus result
, err
;
9121 static EventParamName names
[] = {kEventParamDirectObject
,
9122 kEventParamKeyModifiers
};
9123 static EventParamType types
[] = {typeHICommand
,
9125 int num_params
= sizeof (names
) / sizeof (names
[0]);
9127 result
= CallNextEventHandler (next_handler
, event
);
9128 if (result
!= eventNotHandledErr
)
9131 err
= GetEventParameter (event
, kEventParamDirectObject
, typeHICommand
,
9132 NULL
, sizeof (HICommand
), NULL
, &command
);
9134 if (err
!= noErr
|| command
.commandID
== 0)
9135 return eventNotHandledErr
;
9137 /* A HICommand event is mapped to an Apple event whose event class
9138 symbol is `hicommand' and event ID is its command ID. */
9139 err
= mac_store_event_ref_as_apple_event (0, command
.commandID
,
9141 event
, num_params
, names
, types
);
9142 return err
== noErr
? noErr
: eventNotHandledErr
;
9146 init_command_handler ()
9148 EventTypeSpec specs
[] = {{kEventClassCommand
, kEventCommandProcess
}};
9149 static EventHandlerUPP handle_command_eventUPP
= NULL
;
9151 if (handle_command_eventUPP
== NULL
)
9152 handle_command_eventUPP
= NewEventHandlerUPP (mac_handle_command_event
);
9153 return InstallApplicationEventHandler (handle_command_eventUPP
,
9154 GetEventTypeCount (specs
), specs
,
9158 static pascal OSStatus
9159 mac_handle_window_event (next_handler
, event
, data
)
9160 EventHandlerCallRef next_handler
;
9165 OSStatus result
, err
;
9167 XSizeHints
*size_hints
;
9169 err
= GetEventParameter (event
, kEventParamDirectObject
, typeWindowRef
,
9170 NULL
, sizeof (WindowPtr
), NULL
, &wp
);
9172 return eventNotHandledErr
;
9174 switch (GetEventKind (event
))
9176 case kEventWindowUpdate
:
9177 result
= CallNextEventHandler (next_handler
, event
);
9178 if (result
!= eventNotHandledErr
)
9181 do_window_update (wp
);
9184 case kEventWindowBoundsChanging
:
9185 result
= CallNextEventHandler (next_handler
, event
);
9186 if (result
!= eventNotHandledErr
)
9189 err
= GetEventParameter (event
, kEventParamAttributes
, typeUInt32
,
9190 NULL
, sizeof (UInt32
), NULL
, &attributes
);
9194 size_hints
= FRAME_SIZE_HINTS (mac_window_to_frame (wp
));
9195 if ((attributes
& kWindowBoundsChangeUserResize
)
9196 && ((size_hints
->flags
& (PResizeInc
| PBaseSize
| PMinSize
))
9197 == (PResizeInc
| PBaseSize
| PMinSize
)))
9202 err
= GetEventParameter (event
, kEventParamCurrentBounds
,
9203 typeQDRectangle
, NULL
, sizeof (Rect
),
9208 width
= bounds
.right
- bounds
.left
;
9209 height
= bounds
.bottom
- bounds
.top
;
9211 if (width
< size_hints
->min_width
)
9212 width
= size_hints
->min_width
;
9214 width
= size_hints
->base_width
9215 + (int) ((width
- size_hints
->base_width
)
9216 / (float) size_hints
->width_inc
+ .5)
9217 * size_hints
->width_inc
;
9219 if (height
< size_hints
->min_height
)
9220 height
= size_hints
->min_height
;
9222 height
= size_hints
->base_height
9223 + (int) ((height
- size_hints
->base_height
)
9224 / (float) size_hints
->height_inc
+ .5)
9225 * size_hints
->height_inc
;
9227 bounds
.right
= bounds
.left
+ width
;
9228 bounds
.bottom
= bounds
.top
+ height
;
9229 SetEventParameter (event
, kEventParamCurrentBounds
,
9230 typeQDRectangle
, sizeof (Rect
), &bounds
);
9235 case kEventWindowShown
:
9236 case kEventWindowHidden
:
9237 case kEventWindowExpanded
:
9238 case kEventWindowCollapsed
:
9239 result
= CallNextEventHandler (next_handler
, event
);
9241 mac_handle_visibility_change (mac_window_to_frame (wp
));
9247 case kEventWindowToolbarSwitchMode
:
9248 result
= CallNextEventHandler (next_handler
, event
);
9250 static EventParamName names
[] = {kEventParamDirectObject
,
9251 kEventParamWindowMouseLocation
,
9252 kEventParamKeyModifiers
,
9253 kEventParamMouseButton
,
9254 kEventParamClickCount
,
9255 kEventParamMouseChord
};
9256 static EventParamType types
[] = {typeWindowRef
,
9262 int num_params
= sizeof (names
) / sizeof (names
[0]);
9264 err
= mac_store_event_ref_as_apple_event (0, 0,
9266 Qtoolbar_switch_mode
,
9270 return err
== noErr
? noErr
: result
;
9274 return eventNotHandledErr
;
9277 static pascal OSStatus
9278 mac_handle_mouse_event (next_handler
, event
, data
)
9279 EventHandlerCallRef next_handler
;
9283 OSStatus result
, err
;
9285 switch (GetEventKind (event
))
9287 case kEventMouseWheelMoved
:
9291 EventMouseWheelAxis axis
;
9295 result
= CallNextEventHandler (next_handler
, event
);
9296 if (result
!= eventNotHandledErr
|| read_socket_inev
== NULL
)
9299 err
= GetEventParameter (event
, kEventParamWindowRef
, typeWindowRef
,
9300 NULL
, sizeof (WindowRef
), NULL
, &wp
);
9304 f
= mac_window_to_frame (wp
);
9305 if (f
!= mac_focus_frame (&one_mac_display_info
))
9308 err
= GetEventParameter (event
, kEventParamMouseWheelAxis
,
9309 typeMouseWheelAxis
, NULL
,
9310 sizeof (EventMouseWheelAxis
), NULL
, &axis
);
9311 if (err
!= noErr
|| axis
!= kEventMouseWheelAxisY
)
9314 err
= GetEventParameter (event
, kEventParamMouseWheelDelta
,
9315 typeSInt32
, NULL
, sizeof (SInt32
),
9319 err
= GetEventParameter (event
, kEventParamMouseLocation
,
9320 typeQDPoint
, NULL
, sizeof (Point
),
9324 read_socket_inev
->kind
= WHEEL_EVENT
;
9325 read_socket_inev
->code
= 0;
9326 read_socket_inev
->modifiers
=
9327 (mac_event_to_emacs_modifiers (event
)
9328 | ((delta
< 0) ? down_modifier
: up_modifier
));
9329 SetPortWindowPort (wp
);
9330 GlobalToLocal (&point
);
9331 XSETINT (read_socket_inev
->x
, point
.h
);
9332 XSETINT (read_socket_inev
->y
, point
.v
);
9333 XSETFRAME (read_socket_inev
->frame_or_window
, f
);
9343 return eventNotHandledErr
;
9346 #if USE_MAC_FONT_PANEL
9347 static pascal OSStatus
9348 mac_handle_font_event (next_handler
, event
, data
)
9349 EventHandlerCallRef next_handler
;
9353 OSStatus result
, err
;
9356 EventParamName
*names
;
9357 EventParamType
*types
;
9358 static EventParamName names_sel
[] = {kEventParamATSUFontID
,
9359 kEventParamATSUFontSize
,
9360 kEventParamFMFontFamily
,
9361 kEventParamFMFontSize
,
9362 kEventParamFontColor
};
9363 static EventParamType types_sel
[] = {typeATSUFontID
,
9369 result
= CallNextEventHandler (next_handler
, event
);
9370 if (result
!= eventNotHandledErr
)
9373 switch (GetEventKind (event
))
9375 case kEventFontPanelClosed
:
9376 id_key
= Qpanel_closed
;
9382 case kEventFontSelection
:
9383 id_key
= Qselection
;
9384 num_params
= sizeof (names_sel
) / sizeof (names_sel
[0]);
9390 err
= mac_store_event_ref_as_apple_event (0, 0, Qfont
, id_key
,
9394 return err
== noErr
? noErr
: eventNotHandledErr
;
9400 mac_store_service_event (event
)
9406 EventParamName
*names
;
9407 EventParamType
*types
;
9408 static EventParamName names_pfm
[] = {kEventParamServiceMessageName
,
9409 kEventParamServiceUserData
};
9410 static EventParamType types_pfm
[] = {typeCFStringRef
,
9413 switch (GetEventKind (event
))
9415 case kEventServicePaste
:
9422 case kEventServicePerform
:
9424 num_params
= sizeof (names_pfm
) / sizeof (names_pfm
[0]);
9433 err
= mac_store_event_ref_as_apple_event (0, 0, Qservice
, id_key
,
9439 #endif /* MAC_OSX */
9440 #endif /* USE_CARBON_EVENTS */
9444 install_window_handler (window
)
9448 #if USE_CARBON_EVENTS
9449 EventTypeSpec specs_window
[] =
9450 {{kEventClassWindow
, kEventWindowUpdate
},
9451 {kEventClassWindow
, kEventWindowBoundsChanging
},
9452 {kEventClassWindow
, kEventWindowShown
},
9453 {kEventClassWindow
, kEventWindowHidden
},
9454 {kEventClassWindow
, kEventWindowExpanded
},
9455 {kEventClassWindow
, kEventWindowCollapsed
},
9457 {kEventClassWindow
, kEventWindowToolbarSwitchMode
},
9460 EventTypeSpec specs_mouse
[] = {{kEventClassMouse
, kEventMouseWheelMoved
}};
9461 static EventHandlerUPP handle_window_eventUPP
= NULL
;
9462 static EventHandlerUPP handle_mouse_eventUPP
= NULL
;
9463 #if USE_MAC_FONT_PANEL
9464 EventTypeSpec specs_font
[] = {{kEventClassFont
, kEventFontPanelClosed
},
9465 {kEventClassFont
, kEventFontSelection
}};
9466 static EventHandlerUPP handle_font_eventUPP
= NULL
;
9469 if (handle_window_eventUPP
== NULL
)
9470 handle_window_eventUPP
= NewEventHandlerUPP (mac_handle_window_event
);
9471 if (handle_mouse_eventUPP
== NULL
)
9472 handle_mouse_eventUPP
= NewEventHandlerUPP (mac_handle_mouse_event
);
9473 #if USE_MAC_FONT_PANEL
9474 if (handle_font_eventUPP
== NULL
)
9475 handle_font_eventUPP
= NewEventHandlerUPP (mac_handle_font_event
);
9477 err
= InstallWindowEventHandler (window
, handle_window_eventUPP
,
9478 GetEventTypeCount (specs_window
),
9479 specs_window
, NULL
, NULL
);
9481 err
= InstallWindowEventHandler (window
, handle_mouse_eventUPP
,
9482 GetEventTypeCount (specs_mouse
),
9483 specs_mouse
, NULL
, NULL
);
9484 #if USE_MAC_FONT_PANEL
9486 err
= InstallWindowEventHandler (window
, handle_font_eventUPP
,
9487 GetEventTypeCount (specs_font
),
9488 specs_font
, NULL
, NULL
);
9492 err
= install_drag_handler (window
);
9498 remove_window_handler (window
)
9501 remove_drag_handler (window
);
9507 profiler_exit_proc ()
9509 ProfilerDump ("\pEmacs.prof");
9514 /* These few functions implement Emacs as a normal Mac application
9515 (almost): set up the heap and the Toolbox, handle necessary system
9516 events plus a few simple menu events. They also set up Emacs's
9517 access to functions defined in the rest of this file. Emacs uses
9518 function hooks to perform all its terminal I/O. A complete list of
9519 these functions appear in termhooks.h. For what they do, read the
9520 comments there and see also w32term.c and xterm.c. What's
9521 noticeably missing here is the event loop, which is normally
9522 present in most Mac application. After performing the necessary
9523 Mac initializations, main passes off control to emacs_main
9524 (corresponding to main in emacs.c). Emacs_main calls XTread_socket
9525 (defined further below) to read input. This is where
9526 WaitNextEvent/ReceiveNextEvent is called to process Mac events. */
9533 #if __profile__ /* is the profiler on? */
9534 if (ProfilerInit(collectDetailed
, bestTimeBase
, 5000, 200))
9539 /* set creator and type for files created by MSL */
9544 do_init_managers ();
9549 do_check_ram_size ();
9552 init_emacs_passwd_dir ();
9556 init_coercion_handler ();
9558 initialize_applescript ();
9560 init_apple_event_handler ();
9566 /* set up argv array from STR# resource */
9567 get_string_list (&argv
, ARGV_STRING_LIST_ID
);
9571 /* free up AppleScript resources on exit */
9572 atexit (terminate_applescript
);
9574 #if __profile__ /* is the profiler on? */
9575 atexit (profiler_exit_proc
);
9578 /* 3rd param "envp" never used in emacs_main */
9579 (void) emacs_main (argc
, argv
, 0);
9582 /* Never reached - real exit in Fkill_emacs */
9587 /* Table for translating Mac keycode to X keysym values. Contributed
9589 Mapping for special keys is now identical to that in Apple X11
9590 except `clear' (-> <clear>) on the KeyPad, `enter' (-> <kp-enter>)
9591 on the right of the Cmd key on laptops, and fn + `enter' (->
9593 static unsigned char keycode_to_xkeysym_table
[] = {
9594 /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9595 /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9596 /*0x20*/ 0, 0, 0, 0, 0x0d /*return*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9598 /*0x30*/ 0x09 /*tab*/, 0 /*0x0020 space*/, 0, 0x08 /*backspace*/,
9599 /*0x34*/ 0x8d /*enter on laptops*/, 0x1b /*escape*/, 0, 0,
9600 /*0x38*/ 0, 0, 0, 0,
9601 /*0x3C*/ 0, 0, 0, 0,
9603 /*0x40*/ 0, 0xae /*kp-.*/, 0, 0xaa /*kp-**/,
9604 /*0x44*/ 0, 0xab /*kp-+*/, 0, 0x0b /*clear*/,
9605 /*0x48*/ 0, 0, 0, 0xaf /*kp-/*/,
9606 /*0x4C*/ 0x8d /*kp-enter*/, 0, 0xad /*kp--*/, 0,
9608 /*0x50*/ 0, 0xbd /*kp-=*/, 0xb0 /*kp-0*/, 0xb1 /*kp-1*/,
9609 /*0x54*/ 0xb2 /*kp-2*/, 0xb3 /*kp-3*/, 0xb4 /*kp-4*/, 0xb5 /*kp-5*/,
9610 /*0x58*/ 0xb6 /*kp-6*/, 0xb7 /*kp-7*/, 0, 0xb8 /*kp-8*/,
9611 /*0x5C*/ 0xb9 /*kp-9*/, 0, 0, 0,
9613 /*0x60*/ 0xc2 /*f5*/, 0xc3 /*f6*/, 0xc4 /*f7*/, 0xc0 /*f3*/,
9614 /*0x64*/ 0xc5 /*f8*/, 0xc6 /*f9*/, 0, 0xc8 /*f11*/,
9615 /*0x68*/ 0, 0xca /*f13*/, 0, 0xcb /*f14*/,
9616 /*0x6C*/ 0, 0xc7 /*f10*/, 0x0a /*fn+enter on laptops*/, 0xc9 /*f12*/,
9618 /*0x70*/ 0, 0xcc /*f15*/, 0x6a /*help*/, 0x50 /*home*/,
9619 /*0x74*/ 0x55 /*pgup*/, 0xff /*delete*/, 0xc1 /*f4*/, 0x57 /*end*/,
9620 /*0x78*/ 0xbf /*f2*/, 0x56 /*pgdown*/, 0xbe /*f1*/, 0x51 /*left*/,
9621 /*0x7C*/ 0x53 /*right*/, 0x54 /*down*/, 0x52 /*up*/, 0
9626 keycode_to_xkeysym (int keyCode
, int *xKeySym
)
9628 *xKeySym
= keycode_to_xkeysym_table
[keyCode
& 0x7f];
9629 return *xKeySym
!= 0;
9633 /* Table for translating Mac keycode with the laptop `fn' key to that
9634 without it. Destination symbols in comments are keys on US
9635 keyboard, and they may not be the same on other types of
9637 static unsigned char fn_keycode_to_keycode_table
[] = {
9638 /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9639 /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9640 /*0x20*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9642 /*0x30*/ 0, 0, 0, 0,
9643 /*0x34*/ 0, 0, 0, 0,
9644 /*0x38*/ 0, 0, 0, 0,
9645 /*0x3C*/ 0, 0, 0, 0,
9647 /*0x40*/ 0, 0x2f /*kp-. -> '.'*/, 0, 0x23 /*kp-* -> 'p'*/,
9648 /*0x44*/ 0, 0x2c /*kp-+ -> '/'*/, 0, 0x16 /*clear -> '6'*/,
9649 /*0x48*/ 0, 0, 0, 0x1d /*kp-/ -> '0'*/,
9650 /*0x4C*/ 0x24 /*kp-enter -> return*/, 0, 0x29 /*kp-- -> ';'*/, 0,
9652 /*0x50*/ 0, 0x1b /*kp-= -> '-'*/, 0x2e /*kp-0 -> 'm'*/, 0x26 /*kp-1 -> 'j'*/,
9653 /*0x54*/ 0x28 /*kp-2 -> 'k'*/, 0x25 /*kp-3 -> 'l'*/, 0x20 /*kp-4 -> 'u'*/, 0x22 /*kp-5 ->'i'*/,
9654 /*0x58*/ 0x1f /*kp-6 -> 'o'*/, 0x1a /*kp-7 -> '7'*/, 0, 0x1c /*kp-8 -> '8'*/,
9655 /*0x5C*/ 0x19 /*kp-9 -> '9'*/, 0, 0, 0,
9657 /*0x60*/ 0, 0, 0, 0,
9658 /*0x64*/ 0, 0, 0, 0,
9659 /*0x68*/ 0, 0, 0, 0,
9660 /*0x6C*/ 0, 0, 0, 0,
9662 /*0x70*/ 0, 0, 0, 0x7b /*home -> left*/,
9663 /*0x74*/ 0x7e /*pgup -> up*/, 0x33 /*delete -> backspace*/, 0, 0x7c /*end -> right*/,
9664 /*0x78*/ 0, 0x7d /*pgdown -> down*/, 0, 0,
9667 #endif /* MAC_OSX */
9669 #if !USE_CARBON_EVENTS
9670 static RgnHandle mouse_region
= NULL
;
9673 mac_wait_next_event (er
, sleep_time
, dequeue
)
9678 static EventRecord er_buf
= {nullEvent
};
9679 UInt32 target_tick
, current_tick
;
9680 EventMask event_mask
;
9682 if (mouse_region
== NULL
)
9683 mouse_region
= NewRgn ();
9685 event_mask
= everyEvent
;
9686 if (!mac_ready_for_apple_events
)
9687 event_mask
-= highLevelEventMask
;
9689 current_tick
= TickCount ();
9690 target_tick
= current_tick
+ sleep_time
;
9692 if (er_buf
.what
== nullEvent
)
9693 while (!WaitNextEvent (event_mask
, &er_buf
,
9694 target_tick
- current_tick
, mouse_region
))
9696 current_tick
= TickCount ();
9697 if (target_tick
<= current_tick
)
9703 er_buf
.what
= nullEvent
;
9706 #endif /* not USE_CARBON_EVENTS */
9708 #if TARGET_API_MAC_CARBON
9710 mac_post_mouse_moved_event ()
9712 EventRef event
= NULL
;
9715 err
= CreateEvent (NULL
, kEventClassMouse
, kEventMouseMoved
, 0,
9716 kEventAttributeNone
, &event
);
9721 GetMouse (&mouse_pos
);
9722 LocalToGlobal (&mouse_pos
);
9723 err
= SetEventParameter (event
, kEventParamMouseLocation
, typeQDPoint
,
9724 sizeof (Point
), &mouse_pos
);
9728 UInt32 modifiers
= GetCurrentKeyModifiers ();
9730 err
= SetEventParameter (event
, kEventParamKeyModifiers
, typeUInt32
,
9731 sizeof (UInt32
), &modifiers
);
9734 err
= PostEventToQueue (GetCurrentEventQueue (), event
,
9735 kEventPriorityStandard
);
9737 ReleaseEvent (event
);
9743 mac_set_unicode_keystroke_event (code
, buf
)
9745 struct input_event
*buf
;
9747 int charset_id
, c1
, c2
;
9751 buf
->kind
= ASCII_KEYSTROKE_EVENT
;
9754 else if (code
< 0x100)
9757 charset_id
= CHARSET_8_BIT_CONTROL
;
9759 charset_id
= charset_latin_iso8859_1
;
9760 buf
->kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
9761 buf
->code
= MAKE_CHAR (charset_id
, code
, 0);
9766 charset_id
= charset_mule_unicode_0100_24ff
,
9768 else if (code
< 0x33FF)
9769 charset_id
= charset_mule_unicode_2500_33ff
,
9771 else if (code
>= 0xE000)
9772 charset_id
= charset_mule_unicode_e000_ffff
,
9774 c1
= (code
/ 96) + 32, c2
= (code
% 96) + 32;
9775 buf
->kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
9776 buf
->code
= MAKE_CHAR (charset_id
, c1
, c2
);
9781 /* Emacs calls this whenever it wants to read an input event from the
9784 XTread_socket (sd
, expected
, hold_quit
)
9786 struct input_event
*hold_quit
;
9788 struct input_event inev
;
9790 #if USE_CARBON_EVENTS
9792 EventTargetRef toolbox_dispatcher
;
9795 struct mac_display_info
*dpyinfo
= &one_mac_display_info
;
9797 if (interrupt_input_blocked
)
9799 interrupt_input_pending
= 1;
9803 interrupt_input_pending
= 0;
9806 /* So people can tell when we have read the available input. */
9807 input_signal_count
++;
9811 #if USE_CARBON_EVENTS
9812 toolbox_dispatcher
= GetEventDispatcherTarget ();
9816 mac_prepare_for_quickdraw (NULL
),
9818 !ReceiveNextEvent (0, NULL
, kEventDurationNoWait
,
9819 kEventRemoveFromQueue
, &eventRef
))
9820 #else /* !USE_CARBON_EVENTS */
9821 while (mac_wait_next_event (&er
, 0, true))
9822 #endif /* !USE_CARBON_EVENTS */
9826 unsigned long timestamp
;
9828 /* It is necessary to set this (additional) argument slot of an
9829 event to nil because keyboard.c protects incompletely
9830 processed event from being garbage collected by placing them
9831 in the kbd_buffer_gcpro vector. */
9833 inev
.kind
= NO_EVENT
;
9836 #if USE_CARBON_EVENTS
9837 timestamp
= GetEventTime (eventRef
) / kEventDurationMillisecond
;
9839 timestamp
= er
.when
* (1000 / 60); /* ticks to milliseconds */
9842 #if USE_CARBON_EVENTS
9843 /* Handle new events */
9844 if (!mac_convert_event_ref (eventRef
, &er
))
9846 /* There used to be a handler for the kEventMouseWheelMoved
9847 event here. But as of Mac OS X 10.4, this kind of event
9848 is not directly posted to the main event queue by
9849 two-finger scrolling on the trackpad. Instead, some
9850 private event is posted and it is converted to a wheel
9851 event by the default handler for the application target.
9852 The converted one can be received by a Carbon event
9853 handler installed on a window target. */
9854 read_socket_inev
= &inev
;
9855 SendEventToEventTarget (eventRef
, toolbox_dispatcher
);
9856 read_socket_inev
= NULL
;
9859 #endif /* USE_CARBON_EVENTS */
9865 WindowPtr window_ptr
;
9866 ControlPartCode part_code
;
9869 #if USE_CARBON_EVENTS
9870 /* This is needed to send mouse events like aqua window
9871 buttons to the correct handler. */
9872 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
9873 != eventNotHandledErr
)
9876 last_mouse_glyph_frame
= 0;
9878 if (dpyinfo
->grabbed
&& last_mouse_frame
9879 && FRAME_LIVE_P (last_mouse_frame
))
9881 window_ptr
= FRAME_MAC_WINDOW (last_mouse_frame
);
9882 part_code
= inContent
;
9886 part_code
= FindWindow (er
.where
, &window_ptr
);
9887 if (tip_window
&& window_ptr
== tip_window
)
9889 HideWindow (tip_window
);
9890 part_code
= FindWindow (er
.where
, &window_ptr
);
9894 if (er
.what
!= mouseDown
&&
9895 (part_code
!= inContent
|| dpyinfo
->grabbed
== 0))
9901 f
= mac_focus_frame (dpyinfo
);
9902 saved_menu_event_location
= er
.where
;
9903 inev
.kind
= MENU_BAR_ACTIVATE_EVENT
;
9904 XSETFRAME (inev
.frame_or_window
, f
);
9909 #if TARGET_API_MAC_CARBON
9910 FrontNonFloatingWindow ()
9915 SelectWindow (window_ptr
);
9918 ControlPartCode control_part_code
;
9920 Point mouse_loc
= er
.where
;
9922 ControlKind control_kind
;
9925 f
= mac_window_to_frame (window_ptr
);
9926 /* convert to local coordinates of new window */
9927 SetPortWindowPort (window_ptr
);
9929 GlobalToLocal (&mouse_loc
);
9930 #if TARGET_API_MAC_CARBON
9931 ch
= FindControlUnderMouse (mouse_loc
, window_ptr
,
9932 &control_part_code
);
9935 GetControlKind (ch
, &control_kind
);
9938 control_part_code
= FindControl (mouse_loc
, window_ptr
,
9942 #if USE_CARBON_EVENTS
9943 inev
.code
= mac_get_mouse_btn (eventRef
);
9944 inev
.modifiers
= mac_event_to_emacs_modifiers (eventRef
);
9946 inev
.code
= mac_get_emulated_btn (er
.modifiers
);
9947 inev
.modifiers
= mac_to_emacs_modifiers (er
.modifiers
);
9949 XSETINT (inev
.x
, mouse_loc
.h
);
9950 XSETINT (inev
.y
, mouse_loc
.v
);
9952 if ((dpyinfo
->grabbed
&& tracked_scroll_bar
)
9954 #ifndef USE_TOOLKIT_SCROLL_BARS
9955 /* control_part_code becomes kControlNoPart if
9956 a progress indicator is clicked. */
9957 && control_part_code
!= kControlNoPart
9958 #else /* USE_TOOLKIT_SCROLL_BARS */
9960 && control_kind
.kind
== kControlKindScrollBar
9961 #endif /* MAC_OSX */
9962 #endif /* USE_TOOLKIT_SCROLL_BARS */
9965 struct scroll_bar
*bar
;
9967 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
9969 bar
= tracked_scroll_bar
;
9970 #ifndef USE_TOOLKIT_SCROLL_BARS
9971 control_part_code
= kControlIndicatorPart
;
9975 bar
= (struct scroll_bar
*) GetControlReference (ch
);
9976 #ifdef USE_TOOLKIT_SCROLL_BARS
9977 /* Make the "Ctrl-Mouse-2 splits window" work
9978 for toolkit scroll bars. */
9979 if (er
.modifiers
& controlKey
)
9980 x_scroll_bar_handle_click (bar
, control_part_code
,
9982 else if (er
.what
== mouseDown
)
9983 x_scroll_bar_handle_press (bar
, control_part_code
,
9986 x_scroll_bar_handle_release (bar
, &inev
);
9987 #else /* not USE_TOOLKIT_SCROLL_BARS */
9988 x_scroll_bar_handle_click (bar
, control_part_code
,
9990 if (er
.what
== mouseDown
9991 && control_part_code
== kControlIndicatorPart
)
9992 tracked_scroll_bar
= bar
;
9994 tracked_scroll_bar
= NULL
;
9995 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10000 int x
= mouse_loc
.h
;
10001 int y
= mouse_loc
.v
;
10003 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
10004 if (EQ (window
, f
->tool_bar_window
))
10006 if (er
.what
== mouseDown
)
10007 handle_tool_bar_click (f
, x
, y
, 1, 0);
10009 handle_tool_bar_click (f
, x
, y
, 0,
10015 XSETFRAME (inev
.frame_or_window
, f
);
10016 inev
.kind
= MOUSE_CLICK_EVENT
;
10020 if (er
.what
== mouseDown
)
10022 dpyinfo
->grabbed
|= (1 << inev
.code
);
10023 last_mouse_frame
= f
;
10026 last_tool_bar_item
= -1;
10030 if ((dpyinfo
->grabbed
& (1 << inev
.code
)) == 0)
10031 /* If a button is released though it was not
10032 previously pressed, that would be because
10033 of multi-button emulation. */
10034 dpyinfo
->grabbed
= 0;
10036 dpyinfo
->grabbed
&= ~(1 << inev
.code
);
10039 /* Ignore any mouse motion that happened before
10040 this event; any subsequent mouse-movement Emacs
10041 events should reflect only motion after the
10044 f
->mouse_moved
= 0;
10046 #ifdef USE_TOOLKIT_SCROLL_BARS
10047 if (inev
.kind
== MOUSE_CLICK_EVENT
)
10052 inev
.modifiers
|= down_modifier
;
10055 inev
.modifiers
|= up_modifier
;
10062 #if TARGET_API_MAC_CARBON
10064 if (IsWindowPathSelectClick (window_ptr
, &er
))
10066 WindowPathSelect (window_ptr
, NULL
, NULL
);
10069 if (part_code
== inProxyIcon
10070 && (TrackWindowProxyDrag (window_ptr
, er
.where
)
10071 != errUserWantsToDragWindow
))
10073 DragWindow (window_ptr
, er
.where
, NULL
);
10074 #else /* not TARGET_API_MAC_CARBON */
10075 DragWindow (window_ptr
, er
.where
, &qd
.screenBits
.bounds
);
10076 #endif /* not TARGET_API_MAC_CARBON */
10077 /* Update the frame parameters. */
10079 struct frame
*f
= mac_window_to_frame (window_ptr
);
10081 if (f
&& !f
->async_iconified
)
10082 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
10087 if (TrackGoAway (window_ptr
, er
.where
))
10089 inev
.kind
= DELETE_WINDOW_EVENT
;
10090 XSETFRAME (inev
.frame_or_window
,
10091 mac_window_to_frame (window_ptr
));
10095 /* window resize handling added --ben */
10097 do_grow_window (window_ptr
, &er
);
10100 /* window zoom handling added --ben */
10103 if (TrackBox (window_ptr
, er
.where
, part_code
))
10104 do_zoom_window (window_ptr
, part_code
);
10114 #if USE_CARBON_EVENTS
10115 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
10116 != eventNotHandledErr
)
10119 do_window_update ((WindowPtr
) er
.message
);
10124 #if USE_CARBON_EVENTS
10125 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
10126 != eventNotHandledErr
)
10129 switch ((er
.message
>> 24) & 0x000000FF)
10131 case suspendResumeMessage
:
10132 if ((er
.message
& resumeFlag
) == 1)
10138 case mouseMovedMessage
:
10139 #if !USE_CARBON_EVENTS
10140 SetRectRgn (mouse_region
, er
.where
.h
, er
.where
.v
,
10141 er
.where
.h
+ 1, er
.where
.v
+ 1);
10143 previous_help_echo_string
= help_echo_string
;
10144 help_echo_string
= Qnil
;
10146 if (dpyinfo
->grabbed
&& last_mouse_frame
10147 && FRAME_LIVE_P (last_mouse_frame
))
10148 f
= last_mouse_frame
;
10150 f
= dpyinfo
->x_focus_frame
;
10152 if (dpyinfo
->mouse_face_hidden
)
10154 dpyinfo
->mouse_face_hidden
= 0;
10155 clear_mouse_face (dpyinfo
);
10160 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
10161 Point mouse_pos
= er
.where
;
10163 SetPortWindowPort (wp
);
10165 GlobalToLocal (&mouse_pos
);
10167 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
10168 #ifdef USE_TOOLKIT_SCROLL_BARS
10169 x_scroll_bar_handle_drag (wp
, tracked_scroll_bar
,
10171 #else /* not USE_TOOLKIT_SCROLL_BARS */
10172 x_scroll_bar_note_movement (tracked_scroll_bar
,
10174 - XINT (tracked_scroll_bar
->top
),
10175 er
.when
* (1000 / 60));
10176 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10179 /* Generate SELECT_WINDOW_EVENTs when needed. */
10180 if (mouse_autoselect_window
)
10182 Lisp_Object window
;
10184 window
= window_from_coordinates (f
,
10189 /* Window will be selected only when it is
10190 not selected now and last mouse movement
10191 event was not in it. Minibuffer window
10192 will be selected iff it is active. */
10193 if (WINDOWP (window
)
10194 && !EQ (window
, last_window
)
10195 && !EQ (window
, selected_window
))
10197 inev
.kind
= SELECT_WINDOW_EVENT
;
10198 inev
.frame_or_window
= window
;
10201 last_window
=window
;
10203 if (!note_mouse_movement (f
, &mouse_pos
))
10204 help_echo_string
= previous_help_echo_string
;
10208 /* If the contents of the global variable
10209 help_echo_string has changed, generate a
10211 if (!NILP (help_echo_string
) || !NILP (previous_help_echo_string
))
10219 WindowPtr window_ptr
= (WindowPtr
) er
.message
;
10221 #if USE_CARBON_EVENTS
10222 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
10223 != eventNotHandledErr
)
10226 if (window_ptr
== tip_window
)
10228 HideWindow (tip_window
);
10232 if (!is_emacs_window (window_ptr
))
10235 if ((er
.modifiers
& activeFlag
) != 0)
10237 /* A window has been activated */
10238 Point mouse_loc
= er
.where
;
10240 x_detect_focus_change (dpyinfo
, &er
, &inev
);
10242 SetPortWindowPort (window_ptr
);
10243 GlobalToLocal (&mouse_loc
);
10244 /* Window-activated event counts as mouse movement,
10245 so update things that depend on mouse position. */
10246 note_mouse_movement (mac_window_to_frame (window_ptr
),
10251 /* A window has been deactivated */
10252 #if USE_TOOLKIT_SCROLL_BARS
10253 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
10255 struct input_event event
;
10257 EVENT_INIT (event
);
10258 event
.kind
= NO_EVENT
;
10259 x_scroll_bar_handle_release (tracked_scroll_bar
, &event
);
10260 if (event
.kind
!= NO_EVENT
)
10262 event
.timestamp
= timestamp
;
10263 kbd_buffer_store_event_hold (&event
, hold_quit
);
10268 dpyinfo
->grabbed
= 0;
10270 x_detect_focus_change (dpyinfo
, &er
, &inev
);
10272 f
= mac_window_to_frame (window_ptr
);
10273 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10275 /* If we move outside the frame, then we're
10276 certainly no longer on any text in the
10278 clear_mouse_face (dpyinfo
);
10279 dpyinfo
->mouse_face_mouse_frame
= 0;
10282 /* Generate a nil HELP_EVENT to cancel a help-echo.
10283 Do it only if there's something to cancel.
10284 Otherwise, the startup message is cleared when the
10285 mouse leaves the frame. */
10286 if (any_help_event_p
)
10296 int keycode
= (er
.message
& keyCodeMask
) >> 8;
10298 static SInt16 last_key_script
= -1;
10299 SInt16 current_key_script
;
10300 UInt32 modifiers
= er
.modifiers
, mapped_modifiers
;
10303 (NILP (Vmac_control_modifier
) ? 0 : controlKey
)
10304 | (NILP (Vmac_option_modifier
) ? 0 : optionKey
)
10305 | (NILP (Vmac_command_modifier
) ? 0 : cmdKey
);
10307 #if USE_CARBON_EVENTS && defined (MAC_OSX)
10308 mapped_modifiers
|=
10309 (NILP (Vmac_function_modifier
) ? 0 : kEventKeyModifierFnMask
);
10311 GetEventParameter (eventRef
, kEventParamKeyModifiers
,
10313 sizeof (UInt32
), NULL
, &modifiers
);
10315 /* When using Carbon Events, we need to pass raw keyboard
10316 events to the TSM ourselves. If TSM handles it, it
10317 will pass back noErr, otherwise it will pass back
10318 "eventNotHandledErr" and we can process it
10322 & ~(mac_pass_command_to_system
? cmdKey
: 0)
10323 & ~(mac_pass_control_to_system
? controlKey
: 0)))
10324 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
10325 != eventNotHandledErr
)
10328 if (er
.what
== keyUp
)
10333 f
= mac_focus_frame (dpyinfo
);
10335 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
10336 && !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
))
10338 clear_mouse_face (dpyinfo
);
10339 dpyinfo
->mouse_face_hidden
= 1;
10342 current_key_script
= GetScriptManagerVariable (smKeyScript
);
10343 if (last_key_script
!= current_key_script
)
10345 struct input_event event
;
10347 EVENT_INIT (event
);
10348 event
.kind
= LANGUAGE_CHANGE_EVENT
;
10350 event
.code
= current_key_script
;
10351 event
.timestamp
= timestamp
;
10352 kbd_buffer_store_event (&event
);
10354 last_key_script
= current_key_script
;
10358 if (modifiers
& kEventKeyModifierFnMask
10360 && fn_keycode_to_keycode_table
[keycode
])
10361 keycode
= fn_keycode_to_keycode_table
[keycode
];
10363 if (keycode_to_xkeysym (keycode
, &xkeysym
))
10365 inev
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
10366 inev
.code
= 0xff00 | xkeysym
;
10368 else if (modifiers
& mapped_modifiers
)
10370 /* translate the keycode back to determine the
10373 static SInt16 last_key_layout_id
= 0;
10374 static Handle uchr_handle
= (Handle
)-1;
10375 SInt16 current_key_layout_id
=
10376 GetScriptVariable (current_key_script
, smScriptKeys
);
10378 if (uchr_handle
== (Handle
)-1
10379 || last_key_layout_id
!= current_key_layout_id
)
10381 uchr_handle
= GetResource ('uchr', current_key_layout_id
);
10382 last_key_layout_id
= current_key_layout_id
;
10388 UInt16 key_action
= er
.what
- keyDown
;
10389 UInt32 modifier_key_state
=
10390 (modifiers
& ~mapped_modifiers
) >> 8;
10391 UInt32 keyboard_type
= LMGetKbdType ();
10392 SInt32 dead_key_state
= 0;
10394 UniCharCount actual_length
;
10396 status
= UCKeyTranslate ((UCKeyboardLayout
*)*uchr_handle
,
10397 keycode
, key_action
,
10398 modifier_key_state
,
10400 kUCKeyTranslateNoDeadKeysMask
,
10402 1, &actual_length
, &code
);
10403 if (status
== noErr
&& actual_length
== 1)
10404 mac_set_unicode_keystroke_event (code
, &inev
);
10406 #endif /* MAC_OSX */
10408 if (inev
.kind
== NO_EVENT
)
10410 /* This code comes from Keyboard Resource,
10411 Appendix C of IM - Text. This is necessary
10412 since shift is ignored in KCHR table
10413 translation when option or command is pressed.
10414 It also does not translate correctly
10415 control-shift chars like C-% so mask off shift
10417 /* Mask off modifier keys that are mapped to some
10418 Emacs modifiers. */
10419 int new_modifiers
= er
.modifiers
& ~mapped_modifiers
;
10420 /* set high byte of keycode to modifier high byte*/
10421 int new_keycode
= keycode
| new_modifiers
;
10422 Ptr kchr_ptr
= (Ptr
) GetScriptManagerVariable (smKCHRCache
);
10423 unsigned long some_state
= 0;
10424 UInt32 new_char_code
;
10426 new_char_code
= KeyTranslate (kchr_ptr
, new_keycode
,
10428 if (new_char_code
== 0)
10429 /* Seems like a dead key. Append up-stroke. */
10430 new_char_code
= KeyTranslate (kchr_ptr
,
10431 new_keycode
| 0x80,
10435 inev
.kind
= ASCII_KEYSTROKE_EVENT
;
10436 inev
.code
= new_char_code
& 0xff;
10441 if (inev
.kind
== NO_EVENT
)
10443 inev
.kind
= ASCII_KEYSTROKE_EVENT
;
10444 inev
.code
= er
.message
& charCodeMask
;
10447 #if USE_CARBON_EVENTS
10448 inev
.modifiers
= mac_event_to_emacs_modifiers (eventRef
);
10450 inev
.modifiers
= mac_to_emacs_modifiers (er
.modifiers
);
10452 inev
.modifiers
|= (extra_keyboard_modifiers
10453 & (meta_modifier
| alt_modifier
10454 | hyper_modifier
| super_modifier
));
10455 XSETFRAME (inev
.frame_or_window
, f
);
10457 #if TARGET_API_MAC_CARBON
10458 if (inev
.kind
== ASCII_KEYSTROKE_EVENT
10459 && inev
.code
>= 0x80 && inev
.modifiers
)
10462 TextEncoding encoding
= kTextEncodingMacRoman
;
10463 TextToUnicodeInfo ttu_info
;
10465 UpgradeScriptInfoToTextEncoding (current_key_script
,
10466 kTextLanguageDontCare
,
10467 kTextRegionDontCare
,
10469 err
= CreateTextToUnicodeInfoByEncoding (encoding
, &ttu_info
);
10474 ByteCount unicode_len
;
10477 pstr
[1] = inev
.code
;
10478 err
= ConvertFromPStringToUnicode (ttu_info
, pstr
,
10480 &unicode_len
, &code
);
10481 if (err
== noErr
&& unicode_len
== sizeof (UniChar
))
10482 mac_set_unicode_keystroke_event (code
, &inev
);
10483 DisposeTextToUnicodeInfo (&ttu_info
);
10490 case kHighLevelEvent
:
10491 AEProcessAppleEvent (&er
);
10497 #if USE_CARBON_EVENTS
10498 ReleaseEvent (eventRef
);
10501 if (inev
.kind
!= NO_EVENT
)
10503 inev
.timestamp
= timestamp
;
10504 kbd_buffer_store_event_hold (&inev
, hold_quit
);
10509 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
10514 XSETFRAME (frame
, f
);
10520 any_help_event_p
= 1;
10521 gen_help_event (help_echo_string
, frame
, help_echo_window
,
10522 help_echo_object
, help_echo_pos
);
10526 help_echo_string
= Qnil
;
10527 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
10534 /* If the focus was just given to an autoraising frame,
10536 /* ??? This ought to be able to handle more than one such frame. */
10537 if (pending_autoraise_frame
)
10539 x_raise_frame (pending_autoraise_frame
);
10540 pending_autoraise_frame
= 0;
10543 #if !USE_CARBON_EVENTS
10544 /* Check which frames are still visible. We do this here because
10545 there doesn't seem to be any direct notification from the Window
10546 Manager that the visibility of a window has changed (at least,
10547 not in all cases). */
10549 Lisp_Object tail
, frame
;
10551 FOR_EACH_FRAME (tail
, frame
)
10553 struct frame
*f
= XFRAME (frame
);
10555 /* The tooltip has been drawn already. Avoid the
10556 SET_FRAME_GARBAGED in mac_handle_visibility_change. */
10557 if (EQ (frame
, tip_frame
))
10560 if (FRAME_MAC_P (f
))
10561 mac_handle_visibility_change (f
);
10572 /* Need to override CodeWarrior's input function so no conversion is
10573 done on newlines Otherwise compiled functions in .elc files will be
10574 read incorrectly. Defined in ...:MSL C:MSL
10575 Common:Source:buffer_io.c. */
10578 __convert_to_newlines (unsigned char * p
, size_t * n
)
10580 #pragma unused(p,n)
10584 __convert_from_newlines (unsigned char * p
, size_t * n
)
10586 #pragma unused(p,n)
10592 make_mac_terminal_frame (struct frame
*f
)
10597 XSETFRAME (frame
, f
);
10599 f
->output_method
= output_mac
;
10600 f
->output_data
.mac
= (struct mac_output
*)
10601 xmalloc (sizeof (struct mac_output
));
10602 bzero (f
->output_data
.mac
, sizeof (struct mac_output
));
10604 XSETFRAME (FRAME_KBOARD (f
)->Vdefault_minibuffer_frame
, f
);
10606 FRAME_COLS (f
) = 96;
10607 FRAME_LINES (f
) = 4;
10609 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
10610 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_right
;
10612 FRAME_DESIRED_CURSOR (f
) = FILLED_BOX_CURSOR
;
10614 f
->output_data
.mac
->cursor_pixel
= 0;
10615 f
->output_data
.mac
->border_pixel
= 0x00ff00;
10616 f
->output_data
.mac
->mouse_pixel
= 0xff00ff;
10617 f
->output_data
.mac
->cursor_foreground_pixel
= 0x0000ff;
10619 f
->output_data
.mac
->text_cursor
= kThemeIBeamCursor
;
10620 f
->output_data
.mac
->nontext_cursor
= kThemeArrowCursor
;
10621 f
->output_data
.mac
->modeline_cursor
= kThemeArrowCursor
;
10622 f
->output_data
.mac
->hand_cursor
= kThemePointingHandCursor
;
10623 f
->output_data
.mac
->hourglass_cursor
= kThemeWatchCursor
;
10624 f
->output_data
.mac
->horizontal_drag_cursor
= kThemeResizeLeftRightCursor
;
10626 FRAME_FONTSET (f
) = -1;
10627 f
->output_data
.mac
->explicit_parent
= 0;
10630 f
->border_width
= 0;
10632 f
->internal_border_width
= 0;
10637 f
->new_text_cols
= 0;
10638 f
->new_text_lines
= 0;
10640 SetRect (&r
, f
->left_pos
, f
->top_pos
,
10641 f
->left_pos
+ FRAME_PIXEL_WIDTH (f
),
10642 f
->top_pos
+ FRAME_PIXEL_HEIGHT (f
));
10646 if (!(FRAME_MAC_WINDOW (f
) =
10647 NewCWindow (NULL
, &r
, "\p", true, dBoxProc
,
10648 (WindowPtr
) -1, 1, (long) f
->output_data
.mac
)))
10650 /* so that update events can find this mac_output struct */
10651 f
->output_data
.mac
->mFP
= f
; /* point back to emacs frame */
10657 /* Need to be initialized for unshow_buffer in window.c. */
10658 selected_window
= f
->selected_window
;
10660 Fmodify_frame_parameters (frame
,
10661 Fcons (Fcons (Qfont
,
10662 build_string ("-*-monaco-medium-r-*--*-90-*-*-*-*-mac-roman")), Qnil
));
10663 Fmodify_frame_parameters (frame
,
10664 Fcons (Fcons (Qforeground_color
,
10665 build_string ("black")), Qnil
));
10666 Fmodify_frame_parameters (frame
,
10667 Fcons (Fcons (Qbackground_color
,
10668 build_string ("white")), Qnil
));
10673 /***********************************************************************
10675 ***********************************************************************/
10677 int mac_initialized
= 0;
10680 mac_initialize_display_info ()
10682 struct mac_display_info
*dpyinfo
= &one_mac_display_info
;
10683 GDHandle main_device_handle
;
10685 bzero (dpyinfo
, sizeof (*dpyinfo
));
10688 dpyinfo
->mac_id_name
10689 = (char *) xmalloc (SCHARS (Vinvocation_name
)
10690 + SCHARS (Vsystem_name
)
10692 sprintf (dpyinfo
->mac_id_name
, "%s@%s",
10693 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
10695 dpyinfo
->mac_id_name
= (char *) xmalloc (strlen ("Mac Display") + 1);
10696 strcpy (dpyinfo
->mac_id_name
, "Mac Display");
10699 main_device_handle
= LMGetMainDevice();
10701 dpyinfo
->reference_count
= 0;
10702 dpyinfo
->resx
= 72.0;
10703 dpyinfo
->resy
= 72.0;
10704 dpyinfo
->color_p
= TestDeviceAttribute (main_device_handle
, gdDevType
);
10706 /* HasDepth returns true if it is possible to have a 32 bit display,
10707 but this may not be what is actually used. Mac OSX can do better.
10708 CGMainDisplayID is only available on OSX 10.2 and higher, but the
10709 header for CGGetActiveDisplayList says that the first display returned
10710 is the active one, so we use that. */
10712 CGDirectDisplayID disp_id
[1];
10713 CGDisplayCount disp_count
;
10714 CGDisplayErr error_code
;
10716 error_code
= CGGetActiveDisplayList (1, disp_id
, &disp_count
);
10717 if (error_code
!= 0)
10718 error ("No display found, CGGetActiveDisplayList error %d", error_code
);
10720 dpyinfo
->n_planes
= CGDisplayBitsPerPixel (disp_id
[0]);
10723 for (dpyinfo
->n_planes
= 32; dpyinfo
->n_planes
> 0; dpyinfo
->n_planes
>>= 1)
10724 if (HasDepth (main_device_handle
, dpyinfo
->n_planes
,
10725 gdDevType
, dpyinfo
->color_p
))
10728 dpyinfo
->height
= (**main_device_handle
).gdRect
.bottom
;
10729 dpyinfo
->width
= (**main_device_handle
).gdRect
.right
;
10730 dpyinfo
->grabbed
= 0;
10731 dpyinfo
->root_window
= NULL
;
10732 dpyinfo
->image_cache
= make_image_cache ();
10734 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
10735 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10736 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10737 dpyinfo
->mouse_face_window
= Qnil
;
10738 dpyinfo
->mouse_face_overlay
= Qnil
;
10739 dpyinfo
->mouse_face_hidden
= 0;
10744 mac_make_rdb (xrm_option
)
10747 XrmDatabase database
;
10749 database
= xrm_get_preference_database (NULL
);
10751 xrm_merge_string_database (database
, xrm_option
);
10756 struct mac_display_info
*
10757 mac_term_init (display_name
, xrm_option
, resource_name
)
10758 Lisp_Object display_name
;
10760 char *resource_name
;
10762 struct mac_display_info
*dpyinfo
;
10766 if (!mac_initialized
)
10769 mac_initialized
= 1;
10772 if (x_display_list
)
10773 error ("Sorry, this version can only handle one display");
10775 mac_initialize_display_info ();
10777 dpyinfo
= &one_mac_display_info
;
10779 dpyinfo
->xrdb
= mac_make_rdb (xrm_option
);
10781 /* Put this display on the chain. */
10782 dpyinfo
->next
= x_display_list
;
10783 x_display_list
= dpyinfo
;
10785 /* Put it on x_display_name_list. */
10786 x_display_name_list
= Fcons (Fcons (display_name
,
10787 Fcons (Qnil
, dpyinfo
->xrdb
)),
10788 x_display_name_list
);
10789 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
10795 /* Get rid of display DPYINFO, assuming all frames are already gone. */
10798 x_delete_display (dpyinfo
)
10799 struct mac_display_info
*dpyinfo
;
10803 /* Discard this display from x_display_name_list and x_display_list.
10804 We can't use Fdelq because that can quit. */
10805 if (! NILP (x_display_name_list
)
10806 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10807 x_display_name_list
= XCDR (x_display_name_list
);
10812 tail
= x_display_name_list
;
10813 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10815 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10817 XSETCDR (tail
, XCDR (XCDR (tail
)));
10820 tail
= XCDR (tail
);
10824 if (x_display_list
== dpyinfo
)
10825 x_display_list
= dpyinfo
->next
;
10828 struct x_display_info
*tail
;
10830 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10831 if (tail
->next
== dpyinfo
)
10832 tail
->next
= tail
->next
->next
;
10835 /* Free the font names in the font table. */
10836 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10837 if (dpyinfo
->font_table
[i
].name
)
10839 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
10840 xfree (dpyinfo
->font_table
[i
].full_name
);
10841 xfree (dpyinfo
->font_table
[i
].name
);
10844 if (dpyinfo
->font_table
->font_encoder
)
10845 xfree (dpyinfo
->font_table
->font_encoder
);
10847 xfree (dpyinfo
->font_table
);
10848 xfree (dpyinfo
->mac_id_name
);
10850 if (x_display_list
== 0)
10852 mac_clear_font_name_table ();
10853 bzero (dpyinfo
, sizeof (*dpyinfo
));
10862 extern int inhibit_window_system
;
10863 extern int noninteractive
;
10864 CFBundleRef appsBundle
;
10866 /* No need to test if already -nw*/
10867 if (inhibit_window_system
|| noninteractive
)
10870 appsBundle
= CFBundleGetMainBundle();
10871 if (appsBundle
!= NULL
)
10873 CFStringRef cfBI
= CFSTR("CFBundleIdentifier");
10874 CFTypeRef res
= CFBundleGetValueForInfoDictionaryKey(appsBundle
, cfBI
);
10875 /* We found the bundle identifier, now we know we are valid. */
10882 /* MAC_TODO: Have this start the bundled executable */
10884 /* For now, prevent the fatal error by bringing it up in the terminal */
10885 inhibit_window_system
= 1;
10889 MakeMeTheFrontProcess ()
10891 ProcessSerialNumber psn
;
10894 err
= GetCurrentProcess (&psn
);
10896 (void) SetFrontProcess (&psn
);
10899 /***** Code to handle C-g testing *****/
10901 /* Contains the Mac modifier formed from quit_char */
10902 int mac_quit_char_modifiers
= 0;
10903 int mac_quit_char_keycode
;
10904 extern int quit_char
;
10907 mac_determine_quit_char_modifiers()
10909 /* Todo: Determine modifiers from quit_char. */
10910 UInt32 qc_modifiers
= ctrl_modifier
;
10912 /* Map modifiers */
10913 mac_quit_char_modifiers
= 0;
10914 if (qc_modifiers
& ctrl_modifier
) mac_quit_char_modifiers
|= controlKey
;
10915 if (qc_modifiers
& shift_modifier
) mac_quit_char_modifiers
|= shiftKey
;
10916 if (qc_modifiers
& alt_modifier
) mac_quit_char_modifiers
|= optionKey
;
10920 init_quit_char_handler ()
10922 /* TODO: Let this support keys other the 'g' */
10923 mac_quit_char_keycode
= 5;
10924 /* Look at <architecture/adb_kb_map.h> for details */
10925 /* http://gemma.apple.com/techpubs/mac/Toolbox/Toolbox-40.html#MARKER-9-184*/
10927 mac_determine_quit_char_modifiers();
10929 #endif /* MAC_OSX */
10937 MenuItemIndex menu_index
;
10939 err
= GetIndMenuItemWithCommandID (NULL
, kHICommandQuit
, 1,
10940 &menu
, &menu_index
);
10942 SetMenuItemCommandKey (menu
, menu_index
, false, 0);
10943 #if USE_CARBON_EVENTS
10944 EnableMenuCommand (NULL
, kHICommandPreferences
);
10945 err
= GetIndMenuItemWithCommandID (NULL
, kHICommandPreferences
, 1,
10946 &menu
, &menu_index
);
10949 SetMenuItemCommandKey (menu
, menu_index
, false, 0);
10950 InsertMenuItemTextWithCFString (menu
, NULL
,
10951 0, kMenuItemAttrSeparator
, 0);
10952 InsertMenuItemTextWithCFString (menu
, CFSTR ("About Emacs"),
10953 0, 0, kHICommandAbout
);
10955 #endif /* USE_CARBON_EVENTS */
10956 #else /* !MAC_OSX */
10957 #if USE_CARBON_EVENTS
10958 SetMenuItemCommandID (GetMenuHandle (M_APPLE
), I_ABOUT
, kHICommandAbout
);
10964 /* Set up use of X before we make the first connection. */
10966 extern frame_parm_handler mac_frame_parm_handlers
[];
10968 static struct redisplay_interface x_redisplay_interface
=
10970 mac_frame_parm_handlers
,
10974 x_clear_end_of_line
,
10976 x_after_update_window_line
,
10977 x_update_window_begin
,
10978 x_update_window_end
,
10981 0, /* flush_display_optional */
10982 x_clear_window_mouse_face
,
10983 x_get_glyph_overhangs
,
10984 x_fix_overlapping_area
,
10985 x_draw_fringe_bitmap
,
10987 mac_define_fringe_bitmap
,
10988 mac_destroy_fringe_bitmap
,
10990 0, /* define_fringe_bitmap */
10991 0, /* destroy_fringe_bitmap */
10993 mac_per_char_metric
,
10995 mac_compute_glyph_string_overhangs
,
10996 x_draw_glyph_string
,
10997 mac_define_frame_cursor
,
10998 mac_clear_frame_area
,
10999 mac_draw_window_cursor
,
11000 mac_draw_vertical_window_border
,
11001 mac_shift_glyphs_for_insert
11007 rif
= &x_redisplay_interface
;
11009 clear_frame_hook
= x_clear_frame
;
11010 ins_del_lines_hook
= x_ins_del_lines
;
11011 delete_glyphs_hook
= x_delete_glyphs
;
11012 ring_bell_hook
= XTring_bell
;
11013 reset_terminal_modes_hook
= XTreset_terminal_modes
;
11014 set_terminal_modes_hook
= XTset_terminal_modes
;
11015 update_begin_hook
= x_update_begin
;
11016 update_end_hook
= x_update_end
;
11017 set_terminal_window_hook
= XTset_terminal_window
;
11018 read_socket_hook
= XTread_socket
;
11019 frame_up_to_date_hook
= XTframe_up_to_date
;
11020 mouse_position_hook
= XTmouse_position
;
11021 frame_rehighlight_hook
= XTframe_rehighlight
;
11022 frame_raise_lower_hook
= XTframe_raise_lower
;
11024 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
11025 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
11026 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
11027 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
11029 TTY_SCROLL_REGION_OK (CURTTY ()) = 1; /* we'll scroll partial frames */
11030 TTY_CHAR_INS_DEL_OK (CURTTY ()) = 1;
11031 TTY_LINE_INS_DEL_OK (CURTTY ()) = 1; /* we'll just blt 'em */
11032 TTY_FAST_CLEAR_END_OF_LINE (CURTTY ()) = 1; /* X does this well */
11033 TTY_MEMORY_BELOW_FRAME (CURTTY ()) = 0; /* we don't remember what
11038 last_tool_bar_item
= -1;
11039 any_help_event_p
= 0;
11041 /* Try to use interrupt input; if we can't, then start polling. */
11042 Fset_input_interrupt_mode (Qt
);
11046 #if TARGET_API_MAC_CARBON
11048 #if USE_CARBON_EVENTS
11050 init_service_handler ();
11052 init_quit_char_handler ();
11053 #endif /* MAC_OSX */
11055 init_command_handler ();
11058 #endif /* USE_CARBON_EVENTS */
11061 init_coercion_handler ();
11063 init_apple_event_handler ();
11065 if (!inhibit_window_system
)
11066 MakeMeTheFrontProcess ();
11071 mac_init_fringe ();
11082 staticpro (&x_error_message_string
);
11083 x_error_message_string
= Qnil
;
11086 Qcontrol
= intern ("control"); staticpro (&Qcontrol
);
11087 Qmeta
= intern ("meta"); staticpro (&Qmeta
);
11088 Qalt
= intern ("alt"); staticpro (&Qalt
);
11089 Qhyper
= intern ("hyper"); staticpro (&Qhyper
);
11090 Qsuper
= intern ("super"); staticpro (&Qsuper
);
11091 Qmodifier_value
= intern ("modifier-value");
11092 staticpro (&Qmodifier_value
);
11094 Fput (Qcontrol
, Qmodifier_value
, make_number (ctrl_modifier
));
11095 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
11096 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
11097 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
11098 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
11100 #if USE_CARBON_EVENTS
11101 Qhicommand
= intern ("hicommand"); staticpro (&Qhicommand
);
11103 Qtoolbar_switch_mode
= intern ("toolbar-switch-mode");
11104 staticpro (&Qtoolbar_switch_mode
);
11105 #if USE_MAC_FONT_PANEL
11106 Qpanel_closed
= intern ("panel-closed"); staticpro (&Qpanel_closed
);
11107 Qselection
= intern ("selection"); staticpro (&Qselection
);
11110 Qservice
= intern ("service"); staticpro (&Qservice
);
11111 Qpaste
= intern ("paste"); staticpro (&Qpaste
);
11112 Qperform
= intern ("perform"); staticpro (&Qperform
);
11117 Fprovide (intern ("mac-carbon"), Qnil
);
11120 staticpro (&Qreverse
);
11121 Qreverse
= intern ("reverse");
11123 staticpro (&x_display_name_list
);
11124 x_display_name_list
= Qnil
;
11126 staticpro (&last_mouse_scroll_bar
);
11127 last_mouse_scroll_bar
= Qnil
;
11129 staticpro (&fm_font_family_alist
);
11130 fm_font_family_alist
= Qnil
;
11133 staticpro (&atsu_font_id_hash
);
11134 atsu_font_id_hash
= Qnil
;
11137 /* We don't yet support this, but defining this here avoids whining
11138 from cus-start.el and other places, like "M-x set-variable". */
11139 DEFVAR_BOOL ("x-use-underline-position-properties",
11140 &x_use_underline_position_properties
,
11141 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
11142 nil means ignore them. If you encounter fonts with bogus
11143 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
11144 to 4.1, set this to nil.
11146 NOTE: Not supported on Mac yet. */);
11147 x_use_underline_position_properties
= 0;
11149 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
11150 doc
: /* If not nil, Emacs uses toolkit scroll bars. */);
11151 #ifdef USE_TOOLKIT_SCROLL_BARS
11152 Vx_toolkit_scroll_bars
= Qt
;
11154 Vx_toolkit_scroll_bars
= Qnil
;
11157 staticpro (&last_mouse_motion_frame
);
11158 last_mouse_motion_frame
= Qnil
;
11160 /* Variables to configure modifier key assignment. */
11162 DEFVAR_LISP ("mac-control-modifier", &Vmac_control_modifier
,
11163 doc
: /* *Modifier key assumed when the Mac control key is pressed.
11164 The value can be `control', `meta', `alt', `hyper', or `super' for the
11165 respective modifier. The default is `control'. */);
11166 Vmac_control_modifier
= Qcontrol
;
11168 DEFVAR_LISP ("mac-option-modifier", &Vmac_option_modifier
,
11169 doc
: /* *Modifier key assumed when the Mac alt/option key is pressed.
11170 The value can be `control', `meta', `alt', `hyper', or `super' for the
11171 respective modifier. If the value is nil then the key will act as the
11172 normal Mac control modifier, and the option key can be used to compose
11173 characters depending on the chosen Mac keyboard setting. */);
11174 Vmac_option_modifier
= Qnil
;
11176 DEFVAR_LISP ("mac-command-modifier", &Vmac_command_modifier
,
11177 doc
: /* *Modifier key assumed when the Mac command key is pressed.
11178 The value can be `control', `meta', `alt', `hyper', or `super' for the
11179 respective modifier. The default is `meta'. */);
11180 Vmac_command_modifier
= Qmeta
;
11182 DEFVAR_LISP ("mac-function-modifier", &Vmac_function_modifier
,
11183 doc
: /* *Modifier key assumed when the Mac function key is pressed.
11184 The value can be `control', `meta', `alt', `hyper', or `super' for the
11185 respective modifier. Note that remapping the function key may lead to
11186 unexpected results for some keys on non-US/GB keyboards. */);
11187 Vmac_function_modifier
= Qnil
;
11189 DEFVAR_LISP ("mac-emulate-three-button-mouse",
11190 &Vmac_emulate_three_button_mouse
,
11191 doc
: /* *Specify a way of three button mouse emulation.
11192 The value can be nil, t, or the symbol `reverse'.
11193 nil means that no emulation should be done and the modifiers should be
11194 placed on the mouse-1 event.
11195 t means that when the option-key is held down while pressing the mouse
11196 button, the click will register as mouse-2 and while the command-key
11197 is held down, the click will register as mouse-3.
11198 The symbol `reverse' means that the option-key will register for
11199 mouse-3 and the command-key will register for mouse-2. */);
11200 Vmac_emulate_three_button_mouse
= Qnil
;
11202 #if USE_CARBON_EVENTS
11203 DEFVAR_BOOL ("mac-wheel-button-is-mouse-2", &mac_wheel_button_is_mouse_2
,
11204 doc
: /* *Non-nil if the wheel button is mouse-2 and the right click mouse-3.
11205 Otherwise, the right click will be treated as mouse-2 and the wheel
11206 button will be mouse-3. */);
11207 mac_wheel_button_is_mouse_2
= 1;
11209 DEFVAR_BOOL ("mac-pass-command-to-system", &mac_pass_command_to_system
,
11210 doc
: /* *Non-nil if command key presses are passed on to the Mac Toolbox. */);
11211 mac_pass_command_to_system
= 1;
11213 DEFVAR_BOOL ("mac-pass-control-to-system", &mac_pass_control_to_system
,
11214 doc
: /* *Non-nil if control key presses are passed on to the Mac Toolbox. */);
11215 mac_pass_control_to_system
= 1;
11219 DEFVAR_BOOL ("mac-allow-anti-aliasing", &mac_use_core_graphics
,
11220 doc
: /* *If non-nil, allow anti-aliasing.
11221 The text will be rendered using Core Graphics text rendering which
11222 may anti-alias the text. */);
11224 mac_use_core_graphics
= 1;
11226 mac_use_core_graphics
= 0;
11229 /* Register an entry for `mac-roman' so that it can be used when
11230 creating the terminal frame on Mac OS 9 before loading
11231 term/mac-win.elc. */
11232 DEFVAR_LISP ("mac-charset-info-alist", &Vmac_charset_info_alist
,
11233 doc
: /* Alist of Emacs character sets vs text encodings and coding systems.
11234 Each entry should be of the form:
11236 (CHARSET-NAME TEXT-ENCODING CODING-SYSTEM)
11238 where CHARSET-NAME is a string used in font names to identify the
11239 charset, TEXT-ENCODING is a TextEncodingBase value in Mac, and
11240 CODING_SYSTEM is a coding system corresponding to TEXT-ENCODING. */);
11241 Vmac_charset_info_alist
=
11242 Fcons (list3 (build_string ("mac-roman"),
11243 make_number (smRoman
), Qnil
), Qnil
);
11246 DEFVAR_LISP ("mac-atsu-font-table", &Vmac_atsu_font_table
,
11247 doc
: /* Hash table of ATSU font IDs vs plist of attributes and values.
11248 Each font ID is represented as a four-byte string in native byte
11250 Vmac_atsu_font_table
=
11251 make_hash_table (Qequal
, make_number (DEFAULT_HASH_SIZE
),
11252 make_float (DEFAULT_REHASH_SIZE
),
11253 make_float (DEFAULT_REHASH_THRESHOLD
),
11258 /* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b
11259 (do not change this comment) */