1 /* Implementation of GUI terminal on the Mac OS.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004,
3 2005 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* Contributed by Andrew Choi (akochoi@mac.com). */
30 #include "blockinput.h"
38 #if TARGET_API_MAC_CARBON
39 /* USE_CARBON_EVENTS determines if the Carbon Event Manager is used to
40 obtain events from the event queue. If set to 0, WaitNextEvent is
42 #define USE_CARBON_EVENTS 1
43 #else /* not TARGET_API_MAC_CARBON */
44 #include <Quickdraw.h>
45 #include <ToolUtils.h>
49 #include <Resources.h>
51 #include <TextUtils.h>
55 #if defined (__MRC__) || (__MSL__ >= 0x6000)
56 #include <ControlDefinitions.h>
62 #endif /* not TARGET_API_MAC_CARBON */
71 #include <sys/param.h>
76 #include "dispextern.h"
78 #include "termhooks.h"
86 #include "intervals.h"
92 /* Non-nil means Emacs uses toolkit scroll bars. */
94 Lisp_Object Vx_toolkit_scroll_bars
;
96 /* If non-zero, the text will be rendered using Core Graphics text
97 rendering which may anti-alias the text. */
98 int mac_use_core_graphics
;
101 /* Non-zero means that a HELP_EVENT has been generated since Emacs
104 static int any_help_event_p
;
106 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
107 static Lisp_Object last_window
;
109 /* Non-zero means make use of UNDERLINE_POSITION font properties.
110 (Not yet supported.) */
111 int x_use_underline_position_properties
;
113 /* This is a chain of structures for all the X displays currently in
116 struct x_display_info
*x_display_list
;
118 /* This is a list of cons cells, each of the form (NAME
119 FONT-LIST-CACHE . RESOURCE-DATABASE), one for each element of
120 x_display_list and in the same order. NAME is the name of the
121 frame. FONT-LIST-CACHE records previous values returned by
122 x-list-fonts. RESOURCE-DATABASE preserves the X Resource Database
123 equivalent, which is implemented with a Lisp object, for the
126 Lisp_Object x_display_name_list
;
128 /* This is display since Mac does not support multiple ones. */
129 struct mac_display_info one_mac_display_info
;
131 /* Frame being updated by update_frame. This is declared in term.c.
132 This is set by update_begin and looked at by all the XT functions.
133 It is zero while not inside an update. In that case, the XT
134 functions assume that `selected_frame' is the frame to apply to. */
136 extern struct frame
*updating_frame
;
138 /* This is a frame waiting to be auto-raised, within XTread_socket. */
140 struct frame
*pending_autoraise_frame
;
144 Formerly, we used PointerMotionHintMask (in standard_event_mask)
145 so that we would have to call XQueryPointer after each MotionNotify
146 event to ask for another such event. However, this made mouse tracking
147 slow, and there was a bug that made it eventually stop.
149 Simply asking for MotionNotify all the time seems to work better.
151 In order to avoid asking for motion events and then throwing most
152 of them away or busy-polling the server for mouse positions, we ask
153 the server for pointer motion hints. This means that we get only
154 one event per group of mouse movements. "Groups" are delimited by
155 other kinds of events (focus changes and button clicks, for
156 example), or by XQueryPointer calls; when one of these happens, we
157 get another MotionNotify event the next time the mouse moves. This
158 is at least as efficient as getting motion events when mouse
159 tracking is on, and I suspect only negligibly worse when tracking
162 /* Where the mouse was last time we reported a mouse event. */
164 static Rect last_mouse_glyph
;
165 static FRAME_PTR last_mouse_glyph_frame
;
167 /* The scroll bar in which the last X motion event occurred.
169 If the last X motion event occurred in a scroll bar, we set this so
170 XTmouse_position can know whether to report a scroll bar motion or
173 If the last X motion event didn't occur in a scroll bar, we set
174 this to Qnil, to tell XTmouse_position to return an ordinary motion
177 static Lisp_Object last_mouse_scroll_bar
;
179 /* This is a hack. We would really prefer that XTmouse_position would
180 return the time associated with the position it returns, but there
181 doesn't seem to be any way to wrest the time-stamp from the server
182 along with the position query. So, we just keep track of the time
183 of the last movement we received, and return that in hopes that
184 it's somewhat accurate. */
186 static Time last_mouse_movement_time
;
188 struct scroll_bar
*tracked_scroll_bar
= NULL
;
190 /* Incremented by XTread_socket whenever it really tries to read
194 static int volatile input_signal_count
;
196 static int input_signal_count
;
199 extern Lisp_Object Vsystem_name
;
201 /* A mask of extra modifier bits to put into every keyboard char. */
203 extern EMACS_INT extra_keyboard_modifiers
;
205 /* The keysyms to use for the various modifiers. */
207 static Lisp_Object Qalt
, Qhyper
, Qsuper
, Qcontrol
, Qmeta
, Qmodifier_value
;
209 extern int inhibit_window_system
;
211 #if __MRC__ && !TARGET_API_MAC_CARBON
212 QDGlobals qd
; /* QuickDraw global information structure. */
215 #define mac_window_to_frame(wp) (((mac_output *) GetWRefCon (wp))->mFP)
217 struct mac_display_info
*mac_display_info_for_display (Display
*);
218 static void x_update_window_end
P_ ((struct window
*, int, int));
219 static int x_io_error_quitter
P_ ((Display
*));
220 int x_catch_errors
P_ ((Display
*));
221 void x_uncatch_errors
P_ ((Display
*, int));
222 void x_lower_frame
P_ ((struct frame
*));
223 void x_scroll_bar_clear
P_ ((struct frame
*));
224 int x_had_errors_p
P_ ((Display
*));
225 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
226 void x_raise_frame
P_ ((struct frame
*));
227 void x_set_window_size
P_ ((struct frame
*, int, int, int));
228 void x_wm_set_window_state
P_ ((struct frame
*, int));
229 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
230 void mac_initialize
P_ ((void));
231 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
232 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
233 static void x_update_end
P_ ((struct frame
*));
234 static void XTframe_up_to_date
P_ ((struct frame
*));
235 static void XTset_terminal_modes
P_ ((void));
236 static void XTreset_terminal_modes
P_ ((void));
237 static void x_clear_frame
P_ ((void));
238 static void frame_highlight
P_ ((struct frame
*));
239 static void frame_unhighlight
P_ ((struct frame
*));
240 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
241 static void mac_focus_changed
P_ ((int, struct mac_display_info
*,
242 struct frame
*, struct input_event
*));
243 static void x_detect_focus_change
P_ ((struct mac_display_info
*,
244 EventRecord
*, struct input_event
*));
245 static void XTframe_rehighlight
P_ ((struct frame
*));
246 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
247 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
248 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
249 enum text_cursor_kinds
));
251 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*, int, GC
));
252 static void x_flush
P_ ((struct frame
*f
));
253 static void x_update_begin
P_ ((struct frame
*));
254 static void x_update_window_begin
P_ ((struct window
*));
255 static void x_after_update_window_line
P_ ((struct glyph_row
*));
256 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
257 enum scroll_bar_part
*,
258 Lisp_Object
*, Lisp_Object
*,
261 static int is_emacs_window
P_ ((WindowPtr
));
262 static XCharStruct
*mac_per_char_metric
P_ ((XFontStruct
*, XChar2b
*, int));
263 static void XSetFont
P_ ((Display
*, GC
, XFontStruct
*));
265 /* Defined in macmenu.h. */
266 extern void menubar_selection_callback (FRAME_PTR
, int);
268 #define GC_FORE_COLOR(gc) (&(gc)->fore_color)
269 #define GC_BACK_COLOR(gc) (&(gc)->back_color)
270 #define GC_FONT(gc) ((gc)->xgcv.font)
271 #define GC_CLIP_REGION(gc) ((gc)->clip_region)
272 #define FRAME_NORMAL_GC(f) ((f)->output_data.mac->normal_gc)
274 static RgnHandle saved_port_clip_region
= NULL
;
277 mac_begin_clip (region
)
280 static RgnHandle new_region
= NULL
;
282 if (saved_port_clip_region
== NULL
)
283 saved_port_clip_region
= NewRgn ();
284 if (new_region
== NULL
)
285 new_region
= NewRgn ();
289 GetClip (saved_port_clip_region
);
290 SectRgn (saved_port_clip_region
, region
, new_region
);
291 SetClip (new_region
);
296 mac_end_clip (region
)
300 SetClip (saved_port_clip_region
);
304 /* X display function emulation */
307 XFreePixmap (display
, pixmap
)
308 Display
*display
; /* not used */
311 DisposeGWorld (pixmap
);
315 /* Mac version of XDrawLine. */
318 mac_draw_line (f
, gc
, x1
, y1
, x2
, y2
)
323 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
325 RGBForeColor (GC_FORE_COLOR (gc
));
327 mac_begin_clip (GC_CLIP_REGION (gc
));
330 mac_end_clip (GC_CLIP_REGION (gc
));
334 mac_draw_line_to_pixmap (display
, p
, gc
, x1
, y1
, x2
, y2
)
343 GetGWorld (&old_port
, &old_gdh
);
346 RGBForeColor (GC_FORE_COLOR (gc
));
348 LockPixels (GetGWorldPixMap (p
));
351 UnlockPixels (GetGWorldPixMap (p
));
353 SetGWorld (old_port
, old_gdh
);
358 mac_erase_rectangle (f
, gc
, x
, y
, width
, height
)
362 unsigned int width
, height
;
366 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
368 RGBBackColor (GC_BACK_COLOR (gc
));
369 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
371 mac_begin_clip (GC_CLIP_REGION (gc
));
373 mac_end_clip (GC_CLIP_REGION (gc
));
375 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
379 /* Mac version of XClearArea. */
382 mac_clear_area (f
, x
, y
, width
, height
)
385 unsigned int width
, height
;
387 mac_erase_rectangle (f
, FRAME_NORMAL_GC (f
), x
, y
, width
, height
);
390 /* Mac version of XClearWindow. */
396 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
398 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
400 #if TARGET_API_MAC_CARBON
404 GetWindowPortBounds (FRAME_MAC_WINDOW (f
), &r
);
407 #else /* not TARGET_API_MAC_CARBON */
408 EraseRect (&(FRAME_MAC_WINDOW (f
)->portRect
));
409 #endif /* not TARGET_API_MAC_CARBON */
413 /* Mac replacement for XCopyArea. */
416 mac_draw_bitmap (f
, gc
, x
, y
, width
, height
, bits
, overlay_p
)
419 int x
, y
, width
, height
;
420 unsigned short *bits
;
426 bitmap
.rowBytes
= sizeof(unsigned short);
427 bitmap
.baseAddr
= (char *)bits
;
428 SetRect (&(bitmap
.bounds
), 0, 0, width
, height
);
430 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
432 RGBForeColor (GC_FORE_COLOR (gc
));
433 RGBBackColor (GC_BACK_COLOR (gc
));
434 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
436 mac_begin_clip (GC_CLIP_REGION (gc
));
437 #if TARGET_API_MAC_CARBON
443 CopyBits (&bitmap
, GetPortBitMapForCopyBits (port
),
444 &(bitmap
.bounds
), &r
, overlay_p
? srcOr
: srcCopy
, 0);
445 UnlockPortBits (port
);
447 #else /* not TARGET_API_MAC_CARBON */
448 CopyBits (&bitmap
, &(FRAME_MAC_WINDOW (f
)->portBits
), &(bitmap
.bounds
), &r
,
449 overlay_p
? srcOr
: srcCopy
, 0);
450 #endif /* not TARGET_API_MAC_CARBON */
451 mac_end_clip (GC_CLIP_REGION (gc
));
453 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
457 /* Mac replacement for XCreateBitmapFromBitmapData. */
460 mac_create_bitmap_from_bitmap_data (bitmap
, bits
, w
, h
)
465 static unsigned char swap_nibble
[16]
466 = { 0x0, 0x8, 0x4, 0xc, /* 0000 1000 0100 1100 */
467 0x2, 0xa, 0x6, 0xe, /* 0010 1010 0110 1110 */
468 0x1, 0x9, 0x5, 0xd, /* 0001 1001 0101 1101 */
469 0x3, 0xb, 0x7, 0xf }; /* 0011 1011 0111 1111 */
473 w1
= (w
+ 7) / 8; /* nb of 8bits elt in X bitmap */
474 bitmap
->rowBytes
= ((w
+ 15) / 16) * 2; /* nb of 16bits elt in Mac bitmap */
475 bitmap
->baseAddr
= xmalloc (bitmap
->rowBytes
* h
);
476 bzero (bitmap
->baseAddr
, bitmap
->rowBytes
* h
);
477 for (i
= 0; i
< h
; i
++)
479 p
= bitmap
->baseAddr
+ i
* bitmap
->rowBytes
;
480 for (j
= 0; j
< w1
; j
++)
482 /* Bitswap XBM bytes to match how Mac does things. */
483 unsigned char c
= *bits
++;
484 *p
++ = (unsigned char)((swap_nibble
[c
& 0xf] << 4)
485 | (swap_nibble
[(c
>>4) & 0xf]));;
489 SetRect (&(bitmap
->bounds
), 0, 0, w
, h
);
494 mac_free_bitmap (bitmap
)
497 xfree (bitmap
->baseAddr
);
502 XCreatePixmap (display
, w
, width
, height
, depth
)
503 Display
*display
; /* not used */
505 unsigned int width
, height
;
512 SetPortWindowPort (w
);
514 SetRect (&r
, 0, 0, width
, height
);
515 err
= NewGWorld (&pixmap
, depth
, &r
, NULL
, NULL
, 0);
523 XCreatePixmapFromBitmapData (display
, w
, data
, width
, height
, fg
, bg
, depth
)
524 Display
*display
; /* not used */
527 unsigned int width
, height
;
528 unsigned long fg
, bg
;
535 static GC gc
= NULL
; /* not reentrant */
538 gc
= XCreateGC (display
, w
, 0, NULL
);
540 pixmap
= XCreatePixmap (display
, w
, width
, height
, depth
);
544 GetGWorld (&old_port
, &old_gdh
);
545 SetGWorld (pixmap
, NULL
);
546 mac_create_bitmap_from_bitmap_data (&bitmap
, data
, width
, height
);
547 XSetForeground (display
, gc
, fg
);
548 XSetBackground (display
, gc
, bg
);
549 RGBForeColor (GC_FORE_COLOR (gc
));
550 RGBBackColor (GC_BACK_COLOR (gc
));
551 LockPixels (GetGWorldPixMap (pixmap
));
552 #if TARGET_API_MAC_CARBON
553 CopyBits (&bitmap
, GetPortBitMapForCopyBits (pixmap
),
554 &bitmap
.bounds
, &bitmap
.bounds
, srcCopy
, 0);
555 #else /* not TARGET_API_MAC_CARBON */
556 CopyBits (&bitmap
, &(((GrafPtr
)pixmap
)->portBits
),
557 &bitmap
.bounds
, &bitmap
.bounds
, srcCopy
, 0);
558 #endif /* not TARGET_API_MAC_CARBON */
559 UnlockPixels (GetGWorldPixMap (pixmap
));
560 SetGWorld (old_port
, old_gdh
);
561 mac_free_bitmap (&bitmap
);
567 /* Mac replacement for XFillRectangle. */
570 mac_fill_rectangle (f
, gc
, x
, y
, width
, height
)
574 unsigned int width
, height
;
578 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
580 RGBForeColor (GC_FORE_COLOR (gc
));
581 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
583 mac_begin_clip (GC_CLIP_REGION (gc
));
584 PaintRect (&r
); /* using foreground color of gc */
585 mac_end_clip (GC_CLIP_REGION (gc
));
589 /* Mac replacement for XDrawRectangle: dest is a window. */
592 mac_draw_rectangle (f
, gc
, x
, y
, width
, height
)
596 unsigned int width
, height
;
600 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
602 RGBForeColor (GC_FORE_COLOR (gc
));
603 SetRect (&r
, x
, y
, x
+ width
+ 1, y
+ height
+ 1);
605 mac_begin_clip (GC_CLIP_REGION (gc
));
606 FrameRect (&r
); /* using foreground color of gc */
607 mac_end_clip (GC_CLIP_REGION (gc
));
613 atsu_get_text_layout_with_text_ptr (text
, text_length
, style
, text_layout
)
614 ConstUniCharArrayPtr text
;
615 UniCharCount text_length
;
617 ATSUTextLayout
*text_layout
;
620 static ATSUTextLayout saved_text_layout
= NULL
; /* not reentrant */
622 if (saved_text_layout
== NULL
)
624 UniCharCount lengths
[] = {kATSUToTextEnd
};
625 ATSUAttributeTag tags
[] = {kATSULineLayoutOptionsTag
};
626 ByteCount sizes
[] = {sizeof (ATSLineLayoutOptions
)};
627 static ATSLineLayoutOptions line_layout
=
628 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
629 kATSLineDisableAllLayoutOperations
| kATSLineUseDeviceMetrics
631 kATSLineIsDisplayOnly
| kATSLineFractDisable
634 ATSUAttributeValuePtr values
[] = {&line_layout
};
636 err
= ATSUCreateTextLayoutWithTextPtr (text
,
637 kATSUFromTextBeginning
,
643 err
= ATSUSetLayoutControls (saved_text_layout
,
644 sizeof (tags
) / sizeof (tags
[0]),
645 tags
, sizes
, values
);
646 /* XXX: Should we do this? */
648 err
= ATSUSetTransientFontMatching (saved_text_layout
, true);
652 err
= ATSUSetRunStyle (saved_text_layout
, style
,
653 kATSUFromTextBeginning
, kATSUToTextEnd
);
655 err
= ATSUSetTextPointerLocation (saved_text_layout
, text
,
656 kATSUFromTextBeginning
,
662 *text_layout
= saved_text_layout
;
669 mac_invert_rectangle (f
, x
, y
, width
, height
)
672 unsigned int width
, height
;
676 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
678 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
685 mac_draw_string_common (f
, gc
, x
, y
, buf
, nchars
, mode
, bytes_per_char
)
690 int nchars
, mode
, bytes_per_char
;
692 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
693 UInt32 textFlags
, savedFlags
;
694 if (mac_use_core_graphics
) {
695 textFlags
= kQDUseCGTextRendering
;
696 savedFlags
= SwapQDTextFlags(textFlags
);
700 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
702 RGBForeColor (GC_FORE_COLOR (gc
));
704 RGBBackColor (GC_BACK_COLOR (gc
));
707 if (GC_FONT (gc
)->mac_style
)
710 ATSUTextLayout text_layout
;
712 xassert (bytes_per_char
== 2);
714 #ifndef WORDS_BIG_ENDIAN
717 UniChar
*text
= (UniChar
*)buf
;
719 for (i
= 0; i
< nchars
; i
++)
720 text
[i
] = EndianU16_BtoN (text
[i
]);
723 err
= atsu_get_text_layout_with_text_ptr ((ConstUniCharArrayPtr
)buf
,
725 GC_FONT (gc
)->mac_style
,
730 if (!mac_use_core_graphics
)
733 mac_begin_clip (GC_CLIP_REGION (gc
));
735 ATSUDrawText (text_layout
,
736 kATSUFromTextBeginning
, kATSUToTextEnd
,
737 kATSUUseGrafPortPenLoc
, kATSUUseGrafPortPenLoc
);
738 mac_end_clip (GC_CLIP_REGION (gc
));
744 CGContextRef context
;
745 float port_height
= FRAME_PIXEL_HEIGHT (f
);
746 ATSUAttributeTag tags
[] = {kATSUCGContextTag
};
747 ByteCount sizes
[] = {sizeof (CGContextRef
)};
748 ATSUAttributeValuePtr values
[] = {&context
};
751 QDBeginCGContext (port
, &context
);
752 if (gc
->n_clip_rects
)
754 CGContextTranslateCTM (context
, 0, port_height
);
755 CGContextScaleCTM (context
, 1, -1);
756 CGContextClipToRects (context
, gc
->clip_rects
,
758 CGContextScaleCTM (context
, 1, -1);
759 CGContextTranslateCTM (context
, 0, -port_height
);
761 CGContextSetRGBFillColor
763 RED_FROM_ULONG (gc
->xgcv
.foreground
) / 255.0,
764 GREEN_FROM_ULONG (gc
->xgcv
.foreground
) / 255.0,
765 BLUE_FROM_ULONG (gc
->xgcv
.foreground
) / 255.0,
767 err
= ATSUSetLayoutControls (text_layout
,
768 sizeof (tags
) / sizeof (tags
[0]),
769 tags
, sizes
, values
);
771 ATSUDrawText (text_layout
,
772 kATSUFromTextBeginning
, kATSUToTextEnd
,
773 Long2Fix (x
), Long2Fix (port_height
- y
));
774 CGContextSynchronize (context
);
775 QDEndCGContext (port
, &context
);
777 /* This doesn't work on Mac OS X 10.1. */
778 ATSUClearLayoutControls (text_layout
,
779 sizeof (tags
) / sizeof (tags
[0]),
782 ATSUSetLayoutControls (text_layout
,
783 sizeof (tags
) / sizeof (tags
[0]),
784 tags
, sizes
, values
);
793 TextFont (GC_FONT (gc
)->mac_fontnum
);
794 TextSize (GC_FONT (gc
)->mac_fontsize
);
795 TextFace (GC_FONT (gc
)->mac_fontface
);
798 mac_begin_clip (GC_CLIP_REGION (gc
));
800 DrawText (buf
, 0, nchars
* bytes_per_char
);
801 mac_end_clip (GC_CLIP_REGION (gc
));
807 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
808 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
809 if (mac_use_core_graphics
)
810 SwapQDTextFlags(savedFlags
);
815 /* Mac replacement for XDrawString. */
818 mac_draw_string (f
, gc
, x
, y
, buf
, nchars
)
825 mac_draw_string_common (f
, gc
, x
, y
, buf
, nchars
, srcOr
, 1);
829 /* Mac replacement for XDrawString16. */
832 mac_draw_string_16 (f
, gc
, x
, y
, buf
, nchars
)
839 mac_draw_string_common (f
, gc
, x
, y
, (char *) buf
, nchars
, srcOr
, 2);
843 /* Mac replacement for XDrawImageString. */
846 mac_draw_image_string (f
, gc
, x
, y
, buf
, nchars
)
853 mac_draw_string_common (f
, gc
, x
, y
, buf
, nchars
, srcCopy
, 1);
857 /* Mac replacement for XDrawString16. */
860 mac_draw_image_string_16 (f
, gc
, x
, y
, buf
, nchars
)
867 mac_draw_string_common (f
, gc
, x
, y
, (char *) buf
, nchars
, srcCopy
, 2);
871 /* Mac replacement for XQueryTextExtents, but takes a character. If
872 STYLE is NULL, measurement is done by QuickDraw Text routines for
873 the font of the current graphics port. If CG_GLYPH is not NULL,
874 *CG_GLYPH is set to the glyph ID or 0 if it cannot be obtained. */
877 mac_query_char_extents (style
, c
,
878 font_ascent_return
, font_descent_return
,
879 overall_return
, cg_glyph
)
886 int *font_ascent_return
, *font_descent_return
;
887 XCharStruct
*overall_return
;
888 #if USE_CG_TEXT_DRAWING
901 ATSUTextLayout text_layout
;
904 err
= atsu_get_text_layout_with_text_ptr (&ch
, 1, style
, &text_layout
);
907 ATSTrapezoid glyph_bounds
;
909 err
= ATSUGetGlyphBounds (text_layout
, 0, 0,
910 kATSUFromTextBeginning
, kATSUToTextEnd
,
911 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
912 kATSUseFractionalOrigins
,
914 kATSUseDeviceOrigins
,
916 1, &glyph_bounds
, NULL
);
919 xassert (glyph_bounds
.lowerRight
.x
- glyph_bounds
.lowerLeft
.x
920 == glyph_bounds
.upperRight
.x
- glyph_bounds
.upperLeft
.x
);
922 width
= Fix2Long (glyph_bounds
.upperRight
.x
923 - glyph_bounds
.upperLeft
.x
);
924 if (font_ascent_return
)
925 *font_ascent_return
= -Fix2Long (glyph_bounds
.upperLeft
.y
);
926 if (font_descent_return
)
927 *font_descent_return
= Fix2Long (glyph_bounds
.lowerLeft
.y
);
930 if (err
== noErr
&& overall_return
)
932 err
= ATSUMeasureTextImage (text_layout
,
933 kATSUFromTextBeginning
, kATSUToTextEnd
,
936 STORE_XCHARSTRUCT (*overall_return
, width
, char_bounds
);
937 #if USE_CG_TEXT_DRAWING
938 if (err
== noErr
&& cg_glyph
)
941 ATSUGlyphInfoArray glyph_info_array
;
942 ByteCount count
= sizeof (ATSUGlyphInfoArray
);
944 err1
= ATSUMatchFontsToText (text_layout
, kATSUFromTextBeginning
,
945 kATSUToTextEnd
, NULL
, NULL
, NULL
);
947 err1
= ATSUGetGlyphInfo (text_layout
, kATSUFromTextBeginning
,
948 kATSUToTextEnd
, &count
,
952 xassert (glyph_info_array
.glyphs
[0].glyphID
);
953 *cg_glyph
= glyph_info_array
.glyphs
[0].glyphID
;
964 if (font_ascent_return
|| font_descent_return
)
968 GetFontInfo (&font_info
);
969 if (font_ascent_return
)
970 *font_ascent_return
= font_info
.ascent
;
971 if (font_descent_return
)
972 *font_descent_return
= font_info
.descent
;
978 width
= CharWidth (ch
);
979 QDTextBounds (1, &ch
, &char_bounds
);
980 STORE_XCHARSTRUCT (*overall_return
, width
, char_bounds
);
988 /* Mac replacement for XTextExtents16. Only sets horizontal metrics. */
991 mac_text_extents_16 (font_struct
, string
, nchars
, overall_return
)
992 XFontStruct
*font_struct
;
995 XCharStruct
*overall_return
;
998 short width
= 0, lbearing
= 0, rbearing
= 0;
1001 for (i
= 0; i
< nchars
; i
++)
1003 pcm
= mac_per_char_metric (font_struct
, string
, 0);
1005 width
+= FONT_WIDTH (font_struct
);
1008 lbearing
= min (lbearing
, width
+ pcm
->lbearing
);
1009 rbearing
= max (rbearing
, width
+ pcm
->rbearing
);
1010 width
+= pcm
->width
;
1015 overall_return
->lbearing
= lbearing
;
1016 overall_return
->rbearing
= rbearing
;
1017 overall_return
->width
= width
;
1019 /* What's the meaning of the return value of XTextExtents16? */
1023 #if USE_CG_TEXT_DRAWING
1024 static int cg_text_anti_aliasing_threshold
= 8;
1027 init_cg_text_anti_aliasing_threshold ()
1030 Fmac_get_preference (build_string ("AppleAntiAliasingThreshold"),
1034 cg_text_anti_aliasing_threshold
= XINT (val
);
1038 mac_draw_string_cg (f
, gc
, x
, y
, buf
, nchars
)
1046 float port_height
, gx
, gy
;
1048 CGContextRef context
;
1052 if (!mac_use_core_graphics
|| GC_FONT (gc
)->cg_font
== NULL
)
1055 port
= GetWindowPort (FRAME_MAC_WINDOW (f
));
1056 port_height
= FRAME_PIXEL_HEIGHT (f
);
1058 gy
= port_height
- y
;
1059 glyphs
= (CGGlyph
*)buf
;
1060 advances
= xmalloc (sizeof (CGSize
) * nchars
);
1061 for (i
= 0; i
< nchars
; i
++)
1063 XCharStruct
*pcm
= mac_per_char_metric (GC_FONT (gc
), buf
, 0);
1065 advances
[i
].width
= pcm
->width
;
1066 advances
[i
].height
= 0;
1067 glyphs
[i
] = GC_FONT (gc
)->cg_glyphs
[buf
->byte2
];
1071 QDBeginCGContext (port
, &context
);
1072 if (gc
->n_clip_rects
)
1074 CGContextTranslateCTM (context
, 0, port_height
);
1075 CGContextScaleCTM (context
, 1, -1);
1076 CGContextClipToRects (context
, gc
->clip_rects
, gc
->n_clip_rects
);
1077 CGContextScaleCTM (context
, 1, -1);
1078 CGContextTranslateCTM (context
, 0, -port_height
);
1080 CGContextSetRGBFillColor (context
,
1081 RED_FROM_ULONG (gc
->xgcv
.foreground
) / 255.0,
1082 GREEN_FROM_ULONG (gc
->xgcv
.foreground
) / 255.0,
1083 BLUE_FROM_ULONG (gc
->xgcv
.foreground
) / 255.0,
1085 CGContextSetFont (context
, GC_FONT (gc
)->cg_font
);
1086 CGContextSetFontSize (context
, GC_FONT (gc
)->mac_fontsize
);
1087 if (GC_FONT (gc
)->mac_fontsize
<= cg_text_anti_aliasing_threshold
)
1088 CGContextSetShouldAntialias (context
, false);
1089 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
1090 CGContextSetTextPosition (context
, gx
, gy
);
1091 CGContextShowGlyphsWithAdvances (context
, glyphs
, advances
, nchars
);
1093 for (i
= 0; i
< nchars
; i
++)
1095 CGContextShowGlyphsAtPoint (context
, gx
, gy
, glyphs
+ i
, 1);
1096 gx
+= advances
[i
].width
;
1099 CGContextSynchronize (context
);
1100 QDEndCGContext (port
, &context
);
1109 /* Mac replacement for XCopyArea: dest must be window. */
1112 mac_copy_area (src
, f
, gc
, src_x
, src_y
, width
, height
, dest_x
, dest_y
)
1117 unsigned int width
, height
;
1122 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
1124 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1125 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1127 ForeColor (blackColor
);
1128 BackColor (whiteColor
);
1130 mac_begin_clip (GC_CLIP_REGION (gc
));
1131 LockPixels (GetGWorldPixMap (src
));
1132 #if TARGET_API_MAC_CARBON
1137 LockPortBits (port
);
1138 CopyBits (GetPortBitMapForCopyBits (src
),
1139 GetPortBitMapForCopyBits (port
),
1140 &src_r
, &dest_r
, srcCopy
, 0);
1141 UnlockPortBits (port
);
1143 #else /* not TARGET_API_MAC_CARBON */
1144 CopyBits (&(((GrafPtr
)src
)->portBits
), &(FRAME_MAC_WINDOW (f
)->portBits
),
1145 &src_r
, &dest_r
, srcCopy
, 0);
1146 #endif /* not TARGET_API_MAC_CARBON */
1147 UnlockPixels (GetGWorldPixMap (src
));
1148 mac_end_clip (GC_CLIP_REGION (gc
));
1150 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1155 mac_copy_area_with_mask (src
, mask
, f
, gc
, src_x
, src_y
,
1156 width
, height
, dest_x
, dest_y
)
1161 unsigned int width
, height
;
1166 SetPortWindowPort (FRAME_MAC_WINDOW (f
));
1168 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1169 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1171 ForeColor (blackColor
);
1172 BackColor (whiteColor
);
1174 mac_begin_clip (GC_CLIP_REGION (gc
));
1175 LockPixels (GetGWorldPixMap (src
));
1176 LockPixels (GetGWorldPixMap (mask
));
1177 #if TARGET_API_MAC_CARBON
1182 LockPortBits (port
);
1183 CopyMask (GetPortBitMapForCopyBits (src
), GetPortBitMapForCopyBits (mask
),
1184 GetPortBitMapForCopyBits (port
),
1185 &src_r
, &src_r
, &dest_r
);
1186 UnlockPortBits (port
);
1188 #else /* not TARGET_API_MAC_CARBON */
1189 CopyMask (&(((GrafPtr
)src
)->portBits
), &(((GrafPtr
)mask
)->portBits
),
1190 &(FRAME_MAC_WINDOW (f
)->portBits
), &src_r
, &src_r
, &dest_r
);
1191 #endif /* not TARGET_API_MAC_CARBON */
1192 UnlockPixels (GetGWorldPixMap (mask
));
1193 UnlockPixels (GetGWorldPixMap (src
));
1194 mac_end_clip (GC_CLIP_REGION (gc
));
1196 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1200 /* Mac replacement for XCopyArea: used only for scrolling. */
1203 mac_scroll_area (f
, gc
, src_x
, src_y
, width
, height
, dest_x
, dest_y
)
1207 unsigned int width
, height
;
1210 #if TARGET_API_MAC_CARBON
1212 RgnHandle dummy
= NewRgn (); /* For avoiding update events. */
1214 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1215 ScrollWindowRect (FRAME_MAC_WINDOW (f
),
1216 &src_r
, dest_x
- src_x
, dest_y
- src_y
,
1217 kScrollWindowNoOptions
, dummy
);
1219 #else /* not TARGET_API_MAC_CARBON */
1221 WindowPtr w
= FRAME_MAC_WINDOW (f
);
1225 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
1226 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
1228 /* In Color QuickDraw, set ForeColor and BackColor as follows to avoid
1229 color mapping in CopyBits. Otherwise, it will be slow. */
1230 ForeColor (blackColor
);
1231 BackColor (whiteColor
);
1232 mac_begin_clip (GC_CLIP_REGION (gc
));
1233 CopyBits (&(w
->portBits
), &(w
->portBits
), &src_r
, &dest_r
, srcCopy
, 0);
1234 mac_end_clip (GC_CLIP_REGION (gc
));
1236 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f
)));
1237 #endif /* not TARGET_API_MAC_CARBON */
1241 /* Mac replacement for XChangeGC. */
1244 XChangeGC (display
, gc
, mask
, xgcv
)
1250 if (mask
& GCForeground
)
1251 XSetForeground (display
, gc
, xgcv
->foreground
);
1252 if (mask
& GCBackground
)
1253 XSetBackground (display
, gc
, xgcv
->background
);
1255 XSetFont (display
, gc
, xgcv
->font
);
1259 /* Mac replacement for XCreateGC. */
1262 XCreateGC (display
, window
, mask
, xgcv
)
1268 GC gc
= xmalloc (sizeof (*gc
));
1272 bzero (gc
, sizeof (*gc
));
1273 XChangeGC (display
, gc
, mask
, xgcv
);
1280 /* Used in xfaces.c. */
1283 XFreeGC (display
, gc
)
1287 if (gc
->clip_region
)
1288 DisposeRgn (gc
->clip_region
);
1293 /* Mac replacement for XGetGCValues. */
1296 XGetGCValues (display
, gc
, mask
, xgcv
)
1302 if (mask
& GCForeground
)
1303 xgcv
->foreground
= gc
->xgcv
.foreground
;
1304 if (mask
& GCBackground
)
1305 xgcv
->background
= gc
->xgcv
.background
;
1307 xgcv
->font
= gc
->xgcv
.font
;
1311 /* Mac replacement for XSetForeground. */
1314 XSetForeground (display
, gc
, color
)
1317 unsigned long color
;
1319 if (gc
->xgcv
.foreground
!= color
)
1321 gc
->xgcv
.foreground
= color
;
1322 gc
->fore_color
.red
= RED16_FROM_ULONG (color
);
1323 gc
->fore_color
.green
= GREEN16_FROM_ULONG (color
);
1324 gc
->fore_color
.blue
= BLUE16_FROM_ULONG (color
);
1329 /* Mac replacement for XSetBackground. */
1332 XSetBackground (display
, gc
, color
)
1335 unsigned long color
;
1337 if (gc
->xgcv
.background
!= color
)
1339 gc
->xgcv
.background
= color
;
1340 gc
->back_color
.red
= RED16_FROM_ULONG (color
);
1341 gc
->back_color
.green
= GREEN16_FROM_ULONG (color
);
1342 gc
->back_color
.blue
= BLUE16_FROM_ULONG (color
);
1347 /* Mac replacement for XSetFont. */
1350 XSetFont (display
, gc
, font
)
1355 gc
->xgcv
.font
= font
;
1359 /* Mac replacement for XSetClipRectangles. */
1362 mac_set_clip_rectangles (display
, gc
, rectangles
, n
)
1370 if (n
< 0 || n
> MAX_CLIP_RECTS
)
1374 if (gc
->clip_region
)
1376 DisposeRgn (gc
->clip_region
);
1377 gc
->clip_region
= NULL
;
1382 if (gc
->clip_region
== NULL
)
1383 gc
->clip_region
= NewRgn ();
1384 RectRgn (gc
->clip_region
, rectangles
);
1387 RgnHandle region
= NewRgn ();
1389 for (i
= 1; i
< n
; i
++)
1391 RectRgn (region
, rectangles
+ i
);
1392 UnionRgn (gc
->clip_region
, region
, gc
->clip_region
);
1394 DisposeRgn (region
);
1397 #if defined (MAC_OSX) && USE_ATSUI
1398 gc
->n_clip_rects
= n
;
1400 for (i
= 0; i
< n
; i
++)
1402 Rect
*rect
= rectangles
+ i
;
1404 gc
->clip_rects
[i
] = CGRectMake (rect
->left
, rect
->top
,
1405 rect
->right
- rect
->left
,
1406 rect
->bottom
- rect
->top
);
1412 /* Mac replacement for XSetClipMask. */
1415 mac_reset_clip_rectangles (display
, gc
)
1419 mac_set_clip_rectangles (display
, gc
, NULL
, 0);
1423 /* Mac replacement for XSetWindowBackground. */
1426 XSetWindowBackground (display
, w
, color
)
1429 unsigned long color
;
1431 #if !TARGET_API_MAC_CARBON
1432 AuxWinHandle aw_handle
;
1433 CTabHandle ctab_handle
;
1434 ColorSpecPtr ct_table
;
1439 bg_color
.red
= RED16_FROM_ULONG (color
);
1440 bg_color
.green
= GREEN16_FROM_ULONG (color
);
1441 bg_color
.blue
= BLUE16_FROM_ULONG (color
);
1443 #if TARGET_API_MAC_CARBON
1444 SetWindowContentColor (w
, &bg_color
);
1446 if (GetAuxWin (w
, &aw_handle
))
1448 ctab_handle
= (*aw_handle
)->awCTable
;
1449 HandToHand ((Handle
*) &ctab_handle
);
1450 ct_table
= (*ctab_handle
)->ctTable
;
1451 ct_size
= (*ctab_handle
)->ctSize
;
1452 while (ct_size
> -1)
1454 if (ct_table
->value
== 0)
1456 ct_table
->rgb
= bg_color
;
1457 CTabChanged (ctab_handle
);
1458 SetWinColor (w
, (WCTabHandle
) ctab_handle
);
1466 /* x_sync is a no-op on Mac. */
1474 /* Flush display of frame F, or of all frames if F is null. */
1480 #if TARGET_API_MAC_CARBON
1483 QDFlushPortBuffer (GetWindowPort (FRAME_MAC_WINDOW (f
)), NULL
);
1485 QDFlushPortBuffer (GetQDGlobalsThePort (), NULL
);
1491 /* Remove calls to XFlush by defining XFlush to an empty replacement.
1492 Calls to XFlush should be unnecessary because the X output buffer
1493 is flushed automatically as needed by calls to XPending,
1494 XNextEvent, or XWindowEvent according to the XFlush man page.
1495 XTread_socket calls XPending. Removing XFlush improves
1498 #define XFlush(DISPLAY) (void) 0
1501 /* Return the struct mac_display_info corresponding to DPY. There's
1504 struct mac_display_info
*
1505 mac_display_info_for_display (dpy
)
1508 return &one_mac_display_info
;
1513 /***********************************************************************
1514 Starting and ending an update
1515 ***********************************************************************/
1517 /* Start an update of frame F. This function is installed as a hook
1518 for update_begin, i.e. it is called when update_begin is called.
1519 This function is called prior to calls to x_update_window_begin for
1520 each window being updated. */
1526 #if TARGET_API_MAC_CARBON
1527 /* During update of a frame, availability of input events is
1528 periodically checked with ReceiveNextEvent if
1529 redisplay-dont-pause is nil. That normally flushes window buffer
1530 changes for every check, and thus screen update looks waving even
1531 if no input is available. So we disable screen updates during
1532 update of a frame. */
1534 DisableScreenUpdates ();
1540 /* Start update of window W. Set the global variable updated_window
1541 to the window being updated and set output_cursor to the cursor
1545 x_update_window_begin (w
)
1548 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1549 struct mac_display_info
*display_info
= FRAME_MAC_DISPLAY_INFO (f
);
1552 set_output_cursor (&w
->cursor
);
1556 if (f
== display_info
->mouse_face_mouse_frame
)
1558 /* Don't do highlighting for mouse motion during the update. */
1559 display_info
->mouse_face_defer
= 1;
1561 /* If F needs to be redrawn, simply forget about any prior mouse
1563 if (FRAME_GARBAGED_P (f
))
1564 display_info
->mouse_face_window
= Qnil
;
1566 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
1567 their mouse_face_p flag set, which means that they are always
1568 unequal to rows in a desired matrix which never have that
1569 flag set. So, rows containing mouse-face glyphs are never
1570 scrolled, and we don't have to switch the mouse highlight off
1571 here to prevent it from being scrolled. */
1573 /* Can we tell that this update does not affect the window
1574 where the mouse highlight is? If so, no need to turn off.
1575 Likewise, don't do anything if the frame is garbaged;
1576 in that case, the frame's current matrix that we would use
1577 is all wrong, and we will redisplay that line anyway. */
1578 if (!NILP (display_info
->mouse_face_window
)
1579 && w
== XWINDOW (display_info
->mouse_face_window
))
1583 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
1584 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
1587 if (i
< w
->desired_matrix
->nrows
)
1588 clear_mouse_face (display_info
);
1597 /* Draw a vertical window border from (x,y0) to (x,y1) */
1600 mac_draw_vertical_window_border (w
, x
, y0
, y1
)
1604 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1607 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
1609 XSetForeground (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->normal_gc
,
1612 mac_draw_line (f
, f
->output_data
.mac
->normal_gc
, x
, y0
, x
, y1
);
1615 /* End update of window W (which is equal to updated_window).
1617 Draw vertical borders between horizontally adjacent windows, and
1618 display W's cursor if CURSOR_ON_P is non-zero.
1620 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
1621 glyphs in mouse-face were overwritten. In that case we have to
1622 make sure that the mouse-highlight is properly redrawn.
1624 W may be a menu bar pseudo-window in case we don't have X toolkit
1625 support. Such windows don't have a cursor, so don't display it
1629 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
1631 int cursor_on_p
, mouse_face_overwritten_p
;
1633 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (XFRAME (w
->frame
));
1635 if (!w
->pseudo_window_p
)
1640 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
1642 output_cursor
.x
, output_cursor
.y
);
1644 if (draw_window_fringes (w
, 1))
1645 x_draw_vertical_border (w
);
1650 /* If a row with mouse-face was overwritten, arrange for
1651 XTframe_up_to_date to redisplay the mouse highlight. */
1652 if (mouse_face_overwritten_p
)
1654 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
1655 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
1656 dpyinfo
->mouse_face_window
= Qnil
;
1659 updated_window
= NULL
;
1663 /* End update of frame F. This function is installed as a hook in
1670 /* Mouse highlight may be displayed again. */
1671 FRAME_MAC_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
1674 #if TARGET_API_MAC_CARBON
1675 EnableScreenUpdates ();
1677 XFlush (FRAME_MAC_DISPLAY (f
));
1682 /* This function is called from various places in xdisp.c whenever a
1683 complete update has been performed. The global variable
1684 updated_window is not available here. */
1687 XTframe_up_to_date (f
)
1690 if (FRAME_MAC_P (f
))
1692 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
1694 if (dpyinfo
->mouse_face_deferred_gc
1695 || f
== dpyinfo
->mouse_face_mouse_frame
)
1698 if (dpyinfo
->mouse_face_mouse_frame
)
1699 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
1700 dpyinfo
->mouse_face_mouse_x
,
1701 dpyinfo
->mouse_face_mouse_y
);
1702 dpyinfo
->mouse_face_deferred_gc
= 0;
1709 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
1710 arrow bitmaps, or clear the fringes if no bitmaps are required
1711 before DESIRED_ROW is made current. The window being updated is
1712 found in updated_window. This function is called from
1713 update_window_line only if it is known that there are differences
1714 between bitmaps to be drawn between current row and DESIRED_ROW. */
1717 x_after_update_window_line (desired_row
)
1718 struct glyph_row
*desired_row
;
1720 struct window
*w
= updated_window
;
1726 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
1727 desired_row
->redraw_fringe_bitmaps_p
= 1;
1729 /* When a window has disappeared, make sure that no rest of
1730 full-width rows stays visible in the internal border. Could
1731 check here if updated_window is the leftmost/rightmost window,
1732 but I guess it's not worth doing since vertically split windows
1733 are almost never used, internal border is rarely set, and the
1734 overhead is very small. */
1735 if (windows_or_buffers_changed
1736 && desired_row
->full_width_p
1737 && (f
= XFRAME (w
->frame
),
1738 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
1740 && (height
= desired_row
->visible_height
,
1743 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
1745 /* Internal border is drawn below the tool bar. */
1746 if (WINDOWP (f
->tool_bar_window
)
1747 && w
== XWINDOW (f
->tool_bar_window
))
1751 mac_clear_area (f
, 0, y
, width
, height
);
1752 mac_clear_area (f
, FRAME_PIXEL_WIDTH (f
) - width
, y
, width
, height
);
1758 /* Draw the bitmap WHICH in one of the left or right fringes of
1759 window W. ROW is the glyph row for which to display the bitmap; it
1760 determines the vertical position at which the bitmap has to be
1764 x_draw_fringe_bitmap (w
, row
, p
)
1766 struct glyph_row
*row
;
1767 struct draw_fringe_bitmap_params
*p
;
1769 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1770 Display
*display
= FRAME_MAC_DISPLAY (f
);
1771 struct face
*face
= p
->face
;
1774 /* Must clip because of partially visible lines. */
1775 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
1778 /* Adjust position of "bottom aligned" bitmap on partially
1779 visible last row. */
1781 int oldVH
= row
->visible_height
;
1782 row
->visible_height
= p
->h
;
1783 row
->y
-= rowY
- p
->y
;
1784 x_clip_to_row (w
, row
, -1, face
->gc
);
1786 row
->visible_height
= oldVH
;
1789 x_clip_to_row (w
, row
, -1, face
->gc
);
1791 if (p
->bx
>= 0 && !p
->overlay_p
)
1793 #if 0 /* MAC_TODO: stipple */
1794 /* In case the same realized face is used for fringes and
1795 for something displayed in the text (e.g. face `region' on
1796 mono-displays, the fill style may have been changed to
1797 FillSolid in x_draw_glyph_string_background. */
1799 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
1801 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
1804 mac_erase_rectangle (f
, face
->gc
, p
->bx
, p
->by
, p
->nx
, p
->ny
);
1806 #if 0 /* MAC_TODO: stipple */
1808 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
1814 unsigned short *bits
= p
->bits
+ p
->dh
;
1817 XGetGCValues (display
, face
->gc
, GCForeground
, &gcv
);
1818 XSetForeground (display
, face
->gc
,
1820 ? (p
->overlay_p
? face
->background
1821 : f
->output_data
.mac
->cursor_pixel
)
1822 : face
->foreground
));
1823 mac_draw_bitmap (f
, face
->gc
, p
->x
, p
->y
,
1824 p
->wd
, p
->h
, bits
, p
->overlay_p
);
1825 XSetForeground (display
, face
->gc
, gcv
.foreground
);
1828 mac_reset_clip_rectangles (display
, face
->gc
);
1833 /* This is called when starting Emacs and when restarting after
1834 suspend. When starting Emacs, no window is mapped. And nothing
1835 must be done to Emacs's own window if it is suspended (though that
1839 XTset_terminal_modes ()
1843 /* This is called when exiting or suspending Emacs. Exiting will make
1844 the windows go away, and suspending requires no action. */
1847 XTreset_terminal_modes ()
1853 /***********************************************************************
1855 ***********************************************************************/
1857 /* Function prototypes of this page. */
1859 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1860 static int mac_encode_char
P_ ((int, XChar2b
*, struct font_info
*, int *));
1863 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1864 is not contained in the font. */
1866 static INLINE XCharStruct
*
1867 x_per_char_metric (font
, char2b
)
1871 /* The result metric information. */
1872 XCharStruct
*pcm
= NULL
;
1874 xassert (font
&& char2b
);
1877 if (font
->mac_style
)
1879 XCharStructRow
**row
= font
->bounds
.rows
+ char2b
->byte1
;
1883 *row
= xmalloc (sizeof (XCharStructRow
));
1885 bzero (*row
, sizeof (XCharStructRow
));
1889 pcm
= (*row
)->per_char
+ char2b
->byte2
;
1890 if (!XCHARSTRUCTROW_CHAR_VALID_P (*row
, char2b
->byte2
))
1893 mac_query_char_extents (font
->mac_style
,
1894 (char2b
->byte1
<< 8) + char2b
->byte2
,
1895 NULL
, NULL
, pcm
, NULL
);
1897 XCHARSTRUCTROW_SET_CHAR_VALID (*row
, char2b
->byte2
);
1904 if (font
->bounds
.per_char
!= NULL
)
1906 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1908 /* min_char_or_byte2 specifies the linear character index
1909 corresponding to the first element of the per_char array,
1910 max_char_or_byte2 is the index of the last character. A
1911 character with non-zero CHAR2B->byte1 is not in the font.
1912 A character with byte2 less than min_char_or_byte2 or
1913 greater max_char_or_byte2 is not in the font. */
1914 if (char2b
->byte1
== 0
1915 && char2b
->byte2
>= font
->min_char_or_byte2
1916 && char2b
->byte2
<= font
->max_char_or_byte2
)
1917 pcm
= font
->bounds
.per_char
1918 + (char2b
->byte2
- font
->min_char_or_byte2
);
1922 /* If either min_byte1 or max_byte1 are nonzero, both
1923 min_char_or_byte2 and max_char_or_byte2 are less than
1924 256, and the 2-byte character index values corresponding
1925 to the per_char array element N (counting from 0) are:
1927 byte1 = N/D + min_byte1
1928 byte2 = N\D + min_char_or_byte2
1932 D = max_char_or_byte2 - min_char_or_byte2 + 1
1933 / = integer division
1934 \ = integer modulus */
1935 if (char2b
->byte1
>= font
->min_byte1
1936 && char2b
->byte1
<= font
->max_byte1
1937 && char2b
->byte2
>= font
->min_char_or_byte2
1938 && char2b
->byte2
<= font
->max_char_or_byte2
)
1940 pcm
= (font
->bounds
.per_char
1941 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1942 * (char2b
->byte1
- font
->min_byte1
))
1943 + (char2b
->byte2
- font
->min_char_or_byte2
));
1949 /* If the per_char pointer is null, all glyphs between the first
1950 and last character indexes inclusive have the same
1951 information, as given by both min_bounds and max_bounds. */
1952 if (char2b
->byte2
>= font
->min_char_or_byte2
1953 && char2b
->byte2
<= font
->max_char_or_byte2
)
1954 pcm
= &font
->max_bounds
;
1960 return ((pcm
== NULL
1961 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1968 static XCharStruct
*
1969 mac_per_char_metric (font
, char2b
, font_type
)
1974 return x_per_char_metric (font
, char2b
);
1978 Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1979 the two-byte form of C. Encoding is returned in *CHAR2B. */
1982 mac_encode_char (c
, char2b
, font_info
, two_byte_p
)
1985 struct font_info
*font_info
;
1988 int charset
= CHAR_CHARSET (c
);
1989 XFontStruct
*font
= font_info
->font
;
1991 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1992 This may be either a program in a special encoder language or a
1994 if (font_info
->font_encoder
)
1996 /* It's a program. */
1997 struct ccl_program
*ccl
= font_info
->font_encoder
;
1999 check_ccl_update (ccl
);
2000 if (CHARSET_DIMENSION (charset
) == 1)
2002 ccl
->reg
[0] = charset
;
2003 ccl
->reg
[1] = char2b
->byte2
;
2008 ccl
->reg
[0] = charset
;
2009 ccl
->reg
[1] = char2b
->byte1
;
2010 ccl
->reg
[2] = char2b
->byte2
;
2013 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
2015 /* We assume that MSBs are appropriately set/reset by CCL
2017 if (font
->max_byte1
== 0) /* 1-byte font */
2018 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
2020 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
2022 else if (font_info
->encoding
[charset
])
2024 /* Fixed encoding scheme. See fontset.h for the meaning of the
2025 encoding numbers. */
2026 int enc
= font_info
->encoding
[charset
];
2028 if ((enc
== 1 || enc
== 2)
2029 && CHARSET_DIMENSION (charset
) == 2)
2030 char2b
->byte1
|= 0x80;
2032 if (enc
== 1 || enc
== 3)
2033 char2b
->byte2
|= 0x80;
2039 ENCODE_SJIS (char2b
->byte1
, char2b
->byte2
, sjis1
, sjis2
);
2040 char2b
->byte1
= sjis1
;
2041 char2b
->byte2
= sjis2
;
2046 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
2048 return FONT_TYPE_UNKNOWN
;
2053 /***********************************************************************
2055 ***********************************************************************/
2059 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2060 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2061 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2063 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2064 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2065 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2066 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2067 static void mac_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2068 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2069 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2070 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2071 /*static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap,
2072 unsigned long *, double, int));*/
2073 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2074 double, int, unsigned long));
2075 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2076 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2077 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2078 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2079 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2080 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2082 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2083 int, int, int, int, int, int,
2085 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2086 int, int, int, Rect
*));
2089 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2093 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2098 struct glyph_string
*s
;
2100 if (s
->font
== FRAME_FONT (s
->f
)
2101 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2102 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2104 s
->gc
= s
->f
->output_data
.mac
->cursor_gc
;
2107 /* Cursor on non-default face: must merge. */
2111 xgcv
.background
= s
->f
->output_data
.mac
->cursor_pixel
;
2112 xgcv
.foreground
= s
->face
->background
;
2114 /* If the glyph would be invisible, try a different foreground. */
2115 if (xgcv
.foreground
== xgcv
.background
)
2116 xgcv
.foreground
= s
->face
->foreground
;
2117 if (xgcv
.foreground
== xgcv
.background
)
2118 xgcv
.foreground
= s
->f
->output_data
.mac
->cursor_foreground_pixel
;
2119 if (xgcv
.foreground
== xgcv
.background
)
2120 xgcv
.foreground
= s
->face
->foreground
;
2122 /* Make sure the cursor is distinct from text in this face. */
2123 if (xgcv
.background
== s
->face
->background
2124 && xgcv
.foreground
== s
->face
->foreground
)
2126 xgcv
.background
= s
->face
->foreground
;
2127 xgcv
.foreground
= s
->face
->background
;
2130 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2131 xgcv
.font
= s
->font
;
2132 mask
= GCForeground
| GCBackground
| GCFont
;
2134 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2135 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2138 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2139 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2141 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2146 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2149 x_set_mouse_face_gc (s
)
2150 struct glyph_string
*s
;
2155 /* What face has to be used last for the mouse face? */
2156 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2157 face
= FACE_FROM_ID (s
->f
, face_id
);
2159 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2161 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2162 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2164 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2165 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2166 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2168 /* If font in this face is same as S->font, use it. */
2169 if (s
->font
== s
->face
->font
)
2170 s
->gc
= s
->face
->gc
;
2173 /* Otherwise construct scratch_cursor_gc with values from FACE
2178 xgcv
.background
= s
->face
->background
;
2179 xgcv
.foreground
= s
->face
->foreground
;
2180 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2181 xgcv
.font
= s
->font
;
2182 mask
= GCForeground
| GCBackground
| GCFont
;
2184 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2185 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2188 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2189 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2191 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2194 xassert (s
->gc
!= 0);
2198 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2199 Faces to use in the mode line have already been computed when the
2200 matrix was built, so there isn't much to do, here. */
2203 x_set_mode_line_face_gc (s
)
2204 struct glyph_string
*s
;
2206 s
->gc
= s
->face
->gc
;
2210 /* Set S->gc of glyph string S for drawing that glyph string. Set
2211 S->stippled_p to a non-zero value if the face of S has a stipple
2215 x_set_glyph_string_gc (s
)
2216 struct glyph_string
*s
;
2218 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2220 if (s
->hl
== DRAW_NORMAL_TEXT
)
2222 s
->gc
= s
->face
->gc
;
2223 s
->stippled_p
= s
->face
->stipple
!= 0;
2225 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2227 x_set_mode_line_face_gc (s
);
2228 s
->stippled_p
= s
->face
->stipple
!= 0;
2230 else if (s
->hl
== DRAW_CURSOR
)
2232 x_set_cursor_gc (s
);
2235 else if (s
->hl
== DRAW_MOUSE_FACE
)
2237 x_set_mouse_face_gc (s
);
2238 s
->stippled_p
= s
->face
->stipple
!= 0;
2240 else if (s
->hl
== DRAW_IMAGE_RAISED
2241 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2243 s
->gc
= s
->face
->gc
;
2244 s
->stippled_p
= s
->face
->stipple
!= 0;
2248 s
->gc
= s
->face
->gc
;
2249 s
->stippled_p
= s
->face
->stipple
!= 0;
2252 /* GC must have been set. */
2253 xassert (s
->gc
!= 0);
2257 /* Set clipping for output of glyph string S. S may be part of a mode
2258 line or menu if we don't have X toolkit support. */
2261 x_set_glyph_string_clipping (s
)
2262 struct glyph_string
*s
;
2264 Rect rects
[MAX_CLIP_RECTS
];
2267 n
= get_glyph_string_clip_rects (s
, rects
, MAX_CLIP_RECTS
);
2268 mac_set_clip_rectangles (s
->display
, s
->gc
, rects
, n
);
2273 Compute left and right overhang of glyph string S. If S is a glyph
2274 string for a composition, assume overhangs don't exist. */
2277 mac_compute_glyph_string_overhangs (s
)
2278 struct glyph_string
*s
;
2281 && s
->first_glyph
->type
== CHAR_GLYPH
)
2284 || s
->font
->mac_style
2290 mac_text_extents_16 (s
->font
, s
->char2b
, s
->nchars
, &cs
);
2291 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2292 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2297 MacFontStruct
*font
= s
->font
;
2299 TextFont (font
->mac_fontnum
);
2300 TextSize (font
->mac_fontsize
);
2301 TextFace (font
->mac_fontface
);
2303 QDTextBounds (s
->nchars
* 2, (char *)s
->char2b
, &r
);
2305 s
->right_overhang
= r
.right
> s
->width
? r
.right
- s
->width
: 0;
2306 s
->left_overhang
= r
.left
< 0 ? -r
.left
: 0;
2311 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
2314 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
2315 struct glyph_string
*s
;
2318 mac_erase_rectangle (s
->f
, s
->gc
, x
, y
, w
, h
);
2322 /* We prefer not to use XDrawImageString (srcCopy text transfer mode)
2323 on Mac OS X because:
2324 - Screen is double-buffered. (In srcCopy mode, a text is drawn
2325 into an offscreen graphics world first. So performance gain
2326 cannot be expected.)
2327 - It lowers rendering quality.
2328 - Some fonts leave garbage on cursor movement. */
2330 /* Draw the background of glyph_string S. If S->background_filled_p
2331 is non-zero don't draw it. FORCE_P non-zero means draw the
2332 background even if it wouldn't be drawn normally. This is used
2333 when a string preceding S draws into the background of S, or S
2334 contains the first component of a composition. */
2337 x_draw_glyph_string_background (s
, force_p
)
2338 struct glyph_string
*s
;
2341 /* Nothing to do if background has already been drawn or if it
2342 shouldn't be drawn in the first place. */
2343 if (!s
->background_filled_p
)
2345 int box_line_width
= max (s
->face
->box_line_width
, 0);
2347 #if 0 /* MAC_TODO: stipple */
2350 /* Fill background with a stipple pattern. */
2351 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2352 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
2353 s
->y
+ box_line_width
,
2354 s
->background_width
,
2355 s
->height
- 2 * box_line_width
);
2356 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2357 s
->background_filled_p
= 1;
2361 #if defined (MAC_OS8) && !USE_ATSUI
2362 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
2363 || s
->font_not_found_p
2364 || s
->extends_to_end_of_line_p
2368 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
2369 s
->background_width
,
2370 s
->height
- 2 * box_line_width
);
2371 s
->background_filled_p
= 1;
2377 /* Draw the foreground of glyph string S. */
2380 x_draw_glyph_string_foreground (s
)
2381 struct glyph_string
*s
;
2385 /* If first glyph of S has a left box line, start drawing the text
2386 of S to the right of that box line. */
2387 if (s
->face
->box
!= FACE_NO_BOX
2388 && s
->first_glyph
->left_box_line_p
)
2389 x
= s
->x
+ abs (s
->face
->box_line_width
);
2393 /* Draw characters of S as rectangles if S's font could not be
2395 if (s
->font_not_found_p
)
2397 for (i
= 0; i
< s
->nchars
; ++i
)
2399 struct glyph
*g
= s
->first_glyph
+ i
;
2400 mac_draw_rectangle (s
->f
, s
->gc
, x
, s
->y
,
2401 g
->pixel_width
- 1, s
->height
- 1);
2402 x
+= g
->pixel_width
;
2407 char *char1b
= (char *) s
->char2b
;
2408 int boff
= s
->font_info
->baseline_offset
;
2410 if (s
->font_info
->vertical_centering
)
2411 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
2413 /* If we can use 8-bit functions, condense S->char2b. */
2416 && GC_FONT (s
->gc
)->mac_style
== NULL
2419 for (i
= 0; i
< s
->nchars
; ++i
)
2420 char1b
[i
] = s
->char2b
[i
].byte2
;
2422 #if defined (MAC_OS8) && !USE_ATSUI
2423 /* Draw text with XDrawString if background has already been
2424 filled. Otherwise, use XDrawImageString. (Note that
2425 XDrawImageString is usually faster than XDrawString.) Always
2426 use XDrawImageString when drawing the cursor so that there is
2427 no chance that characters under a box cursor are invisible. */
2429 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
2432 /* Draw characters with 16-bit or 8-bit functions. */
2435 || GC_FONT (s
->gc
)->mac_style
2438 #if USE_CG_TEXT_DRAWING
2440 && mac_draw_string_cg (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2441 s
->char2b
, s
->nchars
))
2445 mac_draw_string_16 (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2446 s
->char2b
, s
->nchars
);
2448 mac_draw_string (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2451 #if defined (MAC_OS8) && !USE_ATSUI
2455 mac_draw_image_string_16 (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2456 s
->char2b
, s
->nchars
);
2458 mac_draw_image_string (s
->f
, s
->gc
, x
, s
->ybase
- boff
,
2465 /* Draw the foreground of composite glyph string S. */
2468 x_draw_composite_glyph_string_foreground (s
)
2469 struct glyph_string
*s
;
2473 /* If first glyph of S has a left box line, start drawing the text
2474 of S to the right of that box line. */
2475 if (s
->face
->box
!= FACE_NO_BOX
2476 && s
->first_glyph
->left_box_line_p
)
2477 x
= s
->x
+ abs (s
->face
->box_line_width
);
2481 /* S is a glyph string for a composition. S->gidx is the index of
2482 the first character drawn for glyphs of this composition.
2483 S->gidx == 0 means we are drawing the very first character of
2484 this composition. */
2486 /* Draw a rectangle for the composition if the font for the very
2487 first character of the composition could not be loaded. */
2488 if (s
->font_not_found_p
)
2491 mac_draw_rectangle (s
->f
, s
->gc
, x
, s
->y
,
2492 s
->width
- 1, s
->height
- 1);
2496 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
2497 mac_draw_string_16 (s
->f
, s
->gc
,
2498 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
2499 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
2505 #ifdef USE_X_TOOLKIT
2507 static struct frame
*x_frame_of_widget
P_ ((Widget
));
2510 /* Return the frame on which widget WIDGET is used.. Abort if frame
2511 cannot be determined. */
2513 static struct frame
*
2514 x_frame_of_widget (widget
)
2517 struct x_display_info
*dpyinfo
;
2521 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
2523 /* Find the top-level shell of the widget. Note that this function
2524 can be called when the widget is not yet realized, so XtWindow
2525 (widget) == 0. That's the reason we can't simply use
2526 x_any_window_to_frame. */
2527 while (!XtIsTopLevelShell (widget
))
2528 widget
= XtParent (widget
);
2530 /* Look for a frame with that top-level widget. Allocate the color
2531 on that frame to get the right gamma correction value. */
2532 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
2533 if (GC_FRAMEP (XCAR (tail
))
2534 && (f
= XFRAME (XCAR (tail
)),
2535 (f
->output_data
.nothing
!= 1
2536 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
2537 && f
->output_data
.x
->widget
== widget
)
2544 /* Allocate the color COLOR->pixel on the screen and display of
2545 widget WIDGET in colormap CMAP. If an exact match cannot be
2546 allocated, try the nearest color available. Value is non-zero
2547 if successful. This is called from lwlib. */
2550 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
2555 struct frame
*f
= x_frame_of_widget (widget
);
2556 return x_alloc_nearest_color (f
, cmap
, color
);
2560 #endif /* USE_X_TOOLKIT */
2562 #if 0 /* MAC_TODO */
2564 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
2565 CMAP. If an exact match can't be allocated, try the nearest color
2566 available. Value is non-zero if successful. Set *COLOR to the
2570 x_alloc_nearest_color (f
, cmap
, color
)
2575 Display
*display
= FRAME_X_DISPLAY (f
);
2576 Screen
*screen
= FRAME_X_SCREEN (f
);
2579 gamma_correct (f
, color
);
2580 rc
= XAllocColor (display
, cmap
, color
);
2583 /* If we got to this point, the colormap is full, so we're going
2584 to try to get the next closest color. The algorithm used is
2585 a least-squares matching, which is what X uses for closest
2586 color matching with StaticColor visuals. */
2588 unsigned long nearest_delta
= ~0;
2589 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
2590 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
2592 for (i
= 0; i
< ncells
; ++i
)
2594 XQueryColors (display
, cmap
, cells
, ncells
);
2596 for (nearest
= i
= 0; i
< ncells
; ++i
)
2598 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
2599 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
2600 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
2601 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
2603 if (delta
< nearest_delta
)
2606 nearest_delta
= delta
;
2610 color
->red
= cells
[nearest
].red
;
2611 color
->green
= cells
[nearest
].green
;
2612 color
->blue
= cells
[nearest
].blue
;
2613 rc
= XAllocColor (display
, cmap
, color
);
2616 #ifdef DEBUG_X_COLORS
2618 register_color (color
->pixel
);
2619 #endif /* DEBUG_X_COLORS */
2625 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
2626 It's necessary to do this instead of just using PIXEL directly to
2627 get color reference counts right. */
2630 x_copy_color (f
, pixel
)
2632 unsigned long pixel
;
2636 color
.pixel
= pixel
;
2638 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2639 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2641 #ifdef DEBUG_X_COLORS
2642 register_color (pixel
);
2648 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
2649 It's necessary to do this instead of just using PIXEL directly to
2650 get color reference counts right. */
2653 x_copy_dpy_color (dpy
, cmap
, pixel
)
2656 unsigned long pixel
;
2660 color
.pixel
= pixel
;
2662 XQueryColor (dpy
, cmap
, &color
);
2663 XAllocColor (dpy
, cmap
, &color
);
2665 #ifdef DEBUG_X_COLORS
2666 register_color (pixel
);
2671 #endif /* MAC_TODO */
2674 /* Brightness beyond which a color won't have its highlight brightness
2677 Nominally, highlight colors for `3d' faces are calculated by
2678 brightening an object's color by a constant scale factor, but this
2679 doesn't yield good results for dark colors, so for colors who's
2680 brightness is less than this value (on a scale of 0-255) have to
2681 use an additional additive factor.
2683 The value here is set so that the default menu-bar/mode-line color
2684 (grey75) will not have its highlights changed at all. */
2685 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
2688 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
2689 or DELTA. Try a color with RGB values multiplied by FACTOR first.
2690 If this produces the same color as COLOR, try a color where all RGB
2691 values have DELTA added. Return the allocated color in *COLOR.
2692 DISPLAY is the X display, CMAP is the colormap to operate on.
2693 Value is non-zero if successful. */
2696 mac_alloc_lighter_color (f
, color
, factor
, delta
)
2698 unsigned long *color
;
2705 /* On Mac, RGB values are 0-255, not 0-65535, so scale delta. */
2708 /* Change RGB values by specified FACTOR. Avoid overflow! */
2709 xassert (factor
>= 0);
2710 new = RGB_TO_ULONG (min (0xff, (int) (factor
* RED_FROM_ULONG (*color
))),
2711 min (0xff, (int) (factor
* GREEN_FROM_ULONG (*color
))),
2712 min (0xff, (int) (factor
* BLUE_FROM_ULONG (*color
))));
2714 /* Calculate brightness of COLOR. */
2715 bright
= (2 * RED_FROM_ULONG (*color
) + 3 * GREEN_FROM_ULONG (*color
)
2716 + BLUE_FROM_ULONG (*color
)) / 6;
2718 /* We only boost colors that are darker than
2719 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
2720 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
2721 /* Make an additive adjustment to NEW, because it's dark enough so
2722 that scaling by FACTOR alone isn't enough. */
2724 /* How far below the limit this color is (0 - 1, 1 being darker). */
2725 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
2726 /* The additive adjustment. */
2727 int min_delta
= delta
* dimness
* factor
/ 2;
2730 new = RGB_TO_ULONG (max (0, min (0xff, (int) (RED_FROM_ULONG (*color
)) - min_delta
)),
2731 max (0, min (0xff, (int) (GREEN_FROM_ULONG (*color
)) - min_delta
)),
2732 max (0, min (0xff, (int) (BLUE_FROM_ULONG (*color
)) - min_delta
)));
2734 new = RGB_TO_ULONG (max (0, min (0xff, (int) (min_delta
+ RED_FROM_ULONG (*color
)))),
2735 max (0, min (0xff, (int) (min_delta
+ GREEN_FROM_ULONG (*color
)))),
2736 max (0, min (0xff, (int) (min_delta
+ BLUE_FROM_ULONG (*color
)))));
2740 new = RGB_TO_ULONG (max (0, min (0xff, (int) (delta
+ RED_FROM_ULONG (*color
)))),
2741 max (0, min (0xff, (int) (delta
+ GREEN_FROM_ULONG (*color
)))),
2742 max (0, min (0xff, (int) (delta
+ BLUE_FROM_ULONG (*color
)))));
2744 /* MAC_TODO: Map to palette and retry with delta if same? */
2745 /* MAC_TODO: Free colors (if using palette)? */
2756 /* Set up the foreground color for drawing relief lines of glyph
2757 string S. RELIEF is a pointer to a struct relief containing the GC
2758 with which lines will be drawn. Use a color that is FACTOR or
2759 DELTA lighter or darker than the relief's background which is found
2760 in S->f->output_data.x->relief_background. If such a color cannot
2761 be allocated, use DEFAULT_PIXEL, instead. */
2764 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
2766 struct relief
*relief
;
2769 unsigned long default_pixel
;
2772 struct mac_output
*di
= f
->output_data
.mac
;
2773 unsigned long mask
= GCForeground
;
2774 unsigned long pixel
;
2775 unsigned long background
= di
->relief_background
;
2776 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
2778 /* MAC_TODO: Free colors (if using palette)? */
2780 /* Allocate new color. */
2781 xgcv
.foreground
= default_pixel
;
2783 if (dpyinfo
->n_planes
!= 1
2784 && mac_alloc_lighter_color (f
, &pixel
, factor
, delta
))
2786 relief
->allocated_p
= 1;
2787 xgcv
.foreground
= relief
->pixel
= pixel
;
2790 if (relief
->gc
== 0)
2792 #if 0 /* MAC_TODO: stipple */
2793 xgcv
.stipple
= dpyinfo
->gray
;
2796 relief
->gc
= XCreateGC (NULL
, FRAME_MAC_WINDOW (f
), mask
, &xgcv
);
2799 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
2803 /* Set up colors for the relief lines around glyph string S. */
2806 x_setup_relief_colors (s
)
2807 struct glyph_string
*s
;
2809 struct mac_output
*di
= s
->f
->output_data
.mac
;
2810 unsigned long color
;
2812 if (s
->face
->use_box_color_for_shadows_p
)
2813 color
= s
->face
->box_color
;
2814 else if (s
->first_glyph
->type
== IMAGE_GLYPH
2816 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
2817 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
2822 /* Get the background color of the face. */
2823 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
2824 color
= xgcv
.background
;
2827 if (di
->white_relief
.gc
== 0
2828 || color
!= di
->relief_background
)
2830 di
->relief_background
= color
;
2831 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
2832 WHITE_PIX_DEFAULT (s
->f
));
2833 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
2834 BLACK_PIX_DEFAULT (s
->f
));
2839 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2840 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2841 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
2842 relief. LEFT_P non-zero means draw a relief on the left side of
2843 the rectangle. RIGHT_P non-zero means draw a relief on the right
2844 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2848 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
2849 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
2851 int left_x
, top_y
, right_x
, bottom_y
, width
;
2852 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
2855 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
2860 gc
= f
->output_data
.mac
->white_relief
.gc
;
2862 gc
= f
->output_data
.mac
->black_relief
.gc
;
2863 mac_set_clip_rectangles (dpy
, gc
, clip_rect
, 1);
2867 for (i
= 0; i
< width
; ++i
)
2868 mac_draw_line (f
, gc
,
2869 left_x
+ i
* left_p
, top_y
+ i
,
2870 right_x
- i
* right_p
, top_y
+ i
);
2874 for (i
= 0; i
< width
; ++i
)
2875 mac_draw_line (f
, gc
,
2876 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
2878 mac_reset_clip_rectangles (dpy
, gc
);
2880 gc
= f
->output_data
.mac
->black_relief
.gc
;
2882 gc
= f
->output_data
.mac
->white_relief
.gc
;
2883 mac_set_clip_rectangles (dpy
, gc
, clip_rect
, 1);
2887 for (i
= 0; i
< width
; ++i
)
2888 mac_draw_line (f
, gc
,
2889 left_x
+ i
* left_p
, bottom_y
- i
,
2890 right_x
- i
* right_p
, bottom_y
- i
);
2894 for (i
= 0; i
< width
; ++i
)
2895 mac_draw_line (f
, gc
,
2896 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
- 1);
2898 mac_reset_clip_rectangles (dpy
, gc
);
2902 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2903 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2904 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2905 left side of the rectangle. RIGHT_P non-zero means draw a line
2906 on the right side of the rectangle. CLIP_RECT is the clipping
2907 rectangle to use when drawing. */
2910 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2911 left_p
, right_p
, clip_rect
)
2912 struct glyph_string
*s
;
2913 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2918 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2919 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2920 mac_set_clip_rectangles (s
->display
, s
->gc
, clip_rect
, 1);
2923 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, top_y
,
2924 right_x
- left_x
+ 1, width
);
2928 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, top_y
,
2929 width
, bottom_y
- top_y
+ 1);
2932 mac_fill_rectangle (s
->f
, s
->gc
, left_x
, bottom_y
- width
+ 1,
2933 right_x
- left_x
+ 1, width
);
2937 mac_fill_rectangle (s
->f
, s
->gc
, right_x
- width
+ 1,
2938 top_y
, width
, bottom_y
- top_y
+ 1);
2940 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2941 mac_reset_clip_rectangles (s
->display
, s
->gc
);
2945 /* Draw a box around glyph string S. */
2948 x_draw_glyph_string_box (s
)
2949 struct glyph_string
*s
;
2951 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2952 int left_p
, right_p
;
2953 struct glyph
*last_glyph
;
2956 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2957 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2958 : window_box_right (s
->w
, s
->area
));
2960 /* The glyph that may have a right box line. */
2961 last_glyph
= (s
->cmp
|| s
->img
2963 : s
->first_glyph
+ s
->nchars
- 1);
2965 width
= abs (s
->face
->box_line_width
);
2966 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2968 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2970 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2972 bottom_y
= top_y
+ s
->height
- 1;
2974 left_p
= (s
->first_glyph
->left_box_line_p
2975 || (s
->hl
== DRAW_MOUSE_FACE
2977 || s
->prev
->hl
!= s
->hl
)));
2978 right_p
= (last_glyph
->right_box_line_p
2979 || (s
->hl
== DRAW_MOUSE_FACE
2981 || s
->next
->hl
!= s
->hl
)));
2983 get_glyph_string_clip_rect (s
, &clip_rect
);
2985 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2986 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2987 left_p
, right_p
, &clip_rect
);
2990 x_setup_relief_colors (s
);
2991 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2992 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2997 /* Draw foreground of image glyph string S. */
3000 x_draw_image_foreground (s
)
3001 struct glyph_string
*s
;
3004 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
3006 /* If first glyph of S has a left box line, start drawing it to the
3007 right of that line. */
3008 if (s
->face
->box
!= FACE_NO_BOX
3009 && s
->first_glyph
->left_box_line_p
3011 x
+= abs (s
->face
->box_line_width
);
3013 /* If there is a margin around the image, adjust x- and y-position
3015 if (s
->slice
.x
== 0)
3016 x
+= s
->img
->hmargin
;
3017 if (s
->slice
.y
== 0)
3018 y
+= s
->img
->vmargin
;
3022 x_set_glyph_string_clipping (s
);
3025 mac_copy_area_with_mask (s
->img
->pixmap
, s
->img
->mask
,
3026 s
->f
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
3027 s
->slice
.width
, s
->slice
.height
, x
, y
);
3030 mac_copy_area (s
->img
->pixmap
,
3031 s
->f
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
3032 s
->slice
.width
, s
->slice
.height
, x
, y
);
3034 /* When the image has a mask, we can expect that at
3035 least part of a mouse highlight or a block cursor will
3036 be visible. If the image doesn't have a mask, make
3037 a block cursor visible by drawing a rectangle around
3038 the image. I believe it's looking better if we do
3039 nothing here for mouse-face. */
3040 if (s
->hl
== DRAW_CURSOR
)
3042 int r
= s
->img
->relief
;
3044 mac_draw_rectangle (s
->f
, s
->gc
, x
- r
, y
- r
,
3045 s
->slice
.width
+ r
*2 - 1,
3046 s
->slice
.height
+ r
*2 - 1);
3051 /* Draw a rectangle if image could not be loaded. */
3052 mac_draw_rectangle (s
->f
, s
->gc
, x
, y
,
3053 s
->slice
.width
- 1, s
->slice
.height
- 1);
3057 /* Draw a relief around the image glyph string S. */
3060 x_draw_image_relief (s
)
3061 struct glyph_string
*s
;
3063 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3066 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
3068 /* If first glyph of S has a left box line, start drawing it to the
3069 right of that line. */
3070 if (s
->face
->box
!= FACE_NO_BOX
3071 && s
->first_glyph
->left_box_line_p
3073 x
+= abs (s
->face
->box_line_width
);
3075 /* If there is a margin around the image, adjust x- and y-position
3077 if (s
->slice
.x
== 0)
3078 x
+= s
->img
->hmargin
;
3079 if (s
->slice
.y
== 0)
3080 y
+= s
->img
->vmargin
;
3082 if (s
->hl
== DRAW_IMAGE_SUNKEN
3083 || s
->hl
== DRAW_IMAGE_RAISED
)
3085 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3086 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3090 thick
= abs (s
->img
->relief
);
3091 raised_p
= s
->img
->relief
> 0;
3096 x1
= x
+ s
->slice
.width
+ thick
- 1;
3097 y1
= y
+ s
->slice
.height
+ thick
- 1;
3099 x_setup_relief_colors (s
);
3100 get_glyph_string_clip_rect (s
, &r
);
3101 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
3103 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
3105 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
3110 /* Draw part of the background of glyph string S. X, Y, W, and H
3111 give the rectangle to draw. */
3114 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3115 struct glyph_string
*s
;
3118 #if 0 /* MAC_TODO: stipple */
3121 /* Fill background with a stipple pattern. */
3122 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3123 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3124 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3127 #endif /* MAC_TODO */
3128 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3132 /* Draw image glyph string S.
3135 s->x +-------------------------
3138 | +-------------------------
3141 | | +-------------------
3147 x_draw_image_glyph_string (s
)
3148 struct glyph_string
*s
;
3151 int box_line_hwidth
= abs (s
->face
->box_line_width
);
3152 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
3156 height
= s
->height
- 2 * box_line_vwidth
;
3159 /* Fill background with face under the image. Do it only if row is
3160 taller than image or if image has a clip mask to reduce
3162 s
->stippled_p
= s
->face
->stipple
!= 0;
3163 if (height
> s
->slice
.height
3167 || s
->img
->pixmap
== 0
3168 || s
->width
!= s
->background_width
)
3171 if (s
->first_glyph
->left_box_line_p
3173 x
+= box_line_hwidth
;
3176 if (s
->slice
.y
== 0)
3177 y
+= box_line_vwidth
;
3179 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
3181 s
->background_filled_p
= 1;
3184 /* Draw the foreground. */
3185 x_draw_image_foreground (s
);
3187 /* If we must draw a relief around the image, do it. */
3189 || s
->hl
== DRAW_IMAGE_RAISED
3190 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3191 x_draw_image_relief (s
);
3195 /* Draw stretch glyph string S. */
3198 x_draw_stretch_glyph_string (s
)
3199 struct glyph_string
*s
;
3201 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
3202 s
->stippled_p
= s
->face
->stipple
!= 0;
3204 if (s
->hl
== DRAW_CURSOR
3205 && !x_stretch_cursor_p
)
3207 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
3208 as wide as the stretch glyph. */
3209 int width
= min (FRAME_COLUMN_WIDTH (s
->f
), s
->background_width
);
3212 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
3214 /* Clear rest using the GC of the original non-cursor face. */
3215 if (width
< s
->background_width
)
3217 int x
= s
->x
+ width
, y
= s
->y
;
3218 int w
= s
->background_width
- width
, h
= s
->height
;
3222 if (s
->row
->mouse_face_p
3223 && cursor_in_mouse_face_p (s
->w
))
3225 x_set_mouse_face_gc (s
);
3231 get_glyph_string_clip_rect (s
, &r
);
3232 mac_set_clip_rectangles (s
->display
, gc
, &r
, 1);
3234 #if 0 /* MAC_TODO: stipple */
3235 if (s
->face
->stipple
)
3237 /* Fill background with a stipple pattern. */
3238 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
3239 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
3240 XSetFillStyle (s
->display
, gc
, FillSolid
);
3243 #endif /* MAC_TODO */
3244 mac_erase_rectangle (s
->f
, gc
, x
, y
, w
, h
);
3247 else if (!s
->background_filled_p
)
3248 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
3251 s
->background_filled_p
= 1;
3255 /* Draw glyph string S. */
3258 x_draw_glyph_string (s
)
3259 struct glyph_string
*s
;
3261 int relief_drawn_p
= 0;
3263 /* If S draws into the background of its successor that does not
3264 draw a cursor, draw the background of the successor first so that
3265 S can draw into it. This makes S->next use XDrawString instead
3266 of XDrawImageString. */
3267 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
3268 && s
->next
->hl
!= DRAW_CURSOR
)
3270 xassert (s
->next
->img
== NULL
);
3271 x_set_glyph_string_gc (s
->next
);
3272 x_set_glyph_string_clipping (s
->next
);
3273 x_draw_glyph_string_background (s
->next
, 1);
3276 /* Set up S->gc, set clipping and draw S. */
3277 x_set_glyph_string_gc (s
);
3279 /* Draw relief (if any) in advance for char/composition so that the
3280 glyph string can be drawn over it. */
3281 if (!s
->for_overlaps
3282 && s
->face
->box
!= FACE_NO_BOX
3283 && (s
->first_glyph
->type
== CHAR_GLYPH
3284 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
3287 x_set_glyph_string_clipping (s
);
3288 x_draw_glyph_string_background (s
, 1);
3289 x_draw_glyph_string_box (s
);
3290 x_set_glyph_string_clipping (s
);
3294 x_set_glyph_string_clipping (s
);
3296 switch (s
->first_glyph
->type
)
3299 x_draw_image_glyph_string (s
);
3303 x_draw_stretch_glyph_string (s
);
3307 if (s
->for_overlaps
)
3308 s
->background_filled_p
= 1;
3310 x_draw_glyph_string_background (s
, 0);
3311 x_draw_glyph_string_foreground (s
);
3314 case COMPOSITE_GLYPH
:
3315 if (s
->for_overlaps
|| s
->gidx
> 0)
3316 s
->background_filled_p
= 1;
3318 x_draw_glyph_string_background (s
, 1);
3319 x_draw_composite_glyph_string_foreground (s
);
3326 if (!s
->for_overlaps
)
3328 /* Draw underline. */
3329 if (s
->face
->underline_p
)
3331 unsigned long h
= 1;
3332 unsigned long dy
= s
->height
- h
;
3334 if (s
->face
->underline_defaulted_p
)
3335 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3340 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3341 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
3342 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3344 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3348 /* Draw overline. */
3349 if (s
->face
->overline_p
)
3351 unsigned long dy
= 0, h
= 1;
3353 if (s
->face
->overline_color_defaulted_p
)
3354 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3359 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3360 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
3361 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3363 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3367 /* Draw strike-through. */
3368 if (s
->face
->strike_through_p
)
3370 unsigned long h
= 1;
3371 unsigned long dy
= (s
->height
- h
) / 2;
3373 if (s
->face
->strike_through_color_defaulted_p
)
3374 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3379 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3380 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
3381 mac_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3383 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3387 /* Draw relief if not yet drawn. */
3388 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3389 x_draw_glyph_string_box (s
);
3392 /* Reset clipping. */
3393 mac_reset_clip_rectangles (s
->display
, s
->gc
);
3396 /* Shift display to make room for inserted glyphs. */
3399 mac_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
3401 int x
, y
, width
, height
, shift_by
;
3403 mac_scroll_area (f
, f
->output_data
.mac
->normal_gc
,
3404 x
, y
, width
, height
,
3408 /* Delete N glyphs at the nominal cursor position. Not implemented
3419 /* Clear entire frame. If updating_frame is non-null, clear that
3420 frame. Otherwise clear the selected frame. */
3430 f
= SELECTED_FRAME ();
3432 /* Clearing the frame will erase any cursor, so mark them all as no
3434 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3435 output_cursor
.hpos
= output_cursor
.vpos
= 0;
3436 output_cursor
.x
= -1;
3438 /* We don't set the output cursor here because there will always
3439 follow an explicit cursor_to. */
3441 mac_clear_window (f
);
3443 /* We have to clear the scroll bars, too. If we have changed
3444 colors or something like that, then they should be notified. */
3445 x_scroll_bar_clear (f
);
3447 XFlush (FRAME_MAC_DISPLAY (f
));
3453 /* Invert the middle quarter of the frame for .15 sec. */
3455 /* We use the select system call to do the waiting, so we have to make
3456 sure it's available. If it isn't, we just won't do visual bells. */
3458 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3461 /* Subtract the `struct timeval' values X and Y, storing the result in
3462 *RESULT. Return 1 if the difference is negative, otherwise 0. */
3465 timeval_subtract (result
, x
, y
)
3466 struct timeval
*result
, x
, y
;
3468 /* Perform the carry for the later subtraction by updating y. This
3469 is safer because on some systems the tv_sec member is unsigned. */
3470 if (x
.tv_usec
< y
.tv_usec
)
3472 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
3473 y
.tv_usec
-= 1000000 * nsec
;
3477 if (x
.tv_usec
- y
.tv_usec
> 1000000)
3479 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
3480 y
.tv_usec
+= 1000000 * nsec
;
3484 /* Compute the time remaining to wait. tv_usec is certainly
3486 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
3487 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
3489 /* Return indication of whether the result should be considered
3491 return x
.tv_sec
< y
.tv_sec
;
3498 /* Get the height not including a menu bar widget. */
3499 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
3500 /* Height of each line to flash. */
3501 int flash_height
= FRAME_LINE_HEIGHT (f
);
3502 /* These will be the left and right margins of the rectangles. */
3503 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3504 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3508 /* Don't flash the area between a scroll bar and the frame
3509 edge it is next to. */
3510 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
3512 case vertical_scroll_bar_left
:
3513 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3516 case vertical_scroll_bar_right
:
3517 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3524 width
= flash_right
- flash_left
;
3528 /* If window is tall, flash top and bottom line. */
3529 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3531 mac_invert_rectangle (f
, flash_left
,
3532 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3533 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3534 width
, flash_height
);
3535 mac_invert_rectangle (f
, flash_left
,
3536 (height
- flash_height
3537 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3538 width
, flash_height
);
3541 /* If it is short, flash it all. */
3542 mac_invert_rectangle (f
, flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3543 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3548 struct timeval wakeup
;
3550 EMACS_GET_TIME (wakeup
);
3552 /* Compute time to wait until, propagating carry from usecs. */
3553 wakeup
.tv_usec
+= 150000;
3554 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
3555 wakeup
.tv_usec
%= 1000000;
3557 /* Keep waiting until past the time wakeup or any input gets
3559 while (! detect_input_pending ())
3561 struct timeval current
;
3562 struct timeval timeout
;
3564 EMACS_GET_TIME (current
);
3566 /* Break if result would be negative. */
3567 if (timeval_subtract (¤t
, wakeup
, current
))
3570 /* How long `select' should wait. */
3572 timeout
.tv_usec
= 10000;
3574 /* Try to wait that long--but we might wake up sooner. */
3575 select (0, NULL
, NULL
, NULL
, &timeout
);
3579 /* If window is tall, flash top and bottom line. */
3580 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3582 mac_invert_rectangle (f
, flash_left
,
3583 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3584 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3585 width
, flash_height
);
3586 mac_invert_rectangle (f
, flash_left
,
3587 (height
- flash_height
3588 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3589 width
, flash_height
);
3592 /* If it is short, flash it all. */
3593 mac_invert_rectangle (f
, flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3594 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3601 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3604 /* Make audible bell. */
3609 struct frame
*f
= SELECTED_FRAME ();
3611 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3619 XFlush (FRAME_MAC_DISPLAY (f
));
3625 /* Specify how many text lines, from the top of the window,
3626 should be affected by insert-lines and delete-lines operations.
3627 This, and those operations, are used only within an update
3628 that is bounded by calls to x_update_begin and x_update_end. */
3631 XTset_terminal_window (n
)
3634 /* This function intentionally left blank. */
3639 /***********************************************************************
3641 ***********************************************************************/
3643 /* Perform an insert-lines or delete-lines operation, inserting N
3644 lines or deleting -N lines at vertical position VPOS. */
3647 x_ins_del_lines (vpos
, n
)
3654 /* Scroll part of the display as described by RUN. */
3657 x_scroll_run (w
, run
)
3661 struct frame
*f
= XFRAME (w
->frame
);
3662 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3664 /* Get frame-relative bounding box of the text display area of W,
3665 without mode lines. Include in this box the left and right
3667 window_box (w
, -1, &x
, &y
, &width
, &height
);
3669 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3670 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3671 bottom_y
= y
+ height
;
3675 /* Scrolling up. Make sure we don't copy part of the mode
3676 line at the bottom. */
3677 if (from_y
+ run
->height
> bottom_y
)
3678 height
= bottom_y
- from_y
;
3680 height
= run
->height
;
3684 /* Scolling down. Make sure we don't copy over the mode line.
3686 if (to_y
+ run
->height
> bottom_y
)
3687 height
= bottom_y
- to_y
;
3689 height
= run
->height
;
3694 /* Cursor off. Will be switched on again in x_update_window_end. */
3698 mac_scroll_area (f
, f
->output_data
.mac
->normal_gc
,
3708 /***********************************************************************
3710 ***********************************************************************/
3718 ControlRef root_control
;
3721 err
= GetRootControl (FRAME_MAC_WINDOW (f
), &root_control
);
3723 ActivateControl (root_control
);
3725 x_update_cursor (f
, 1);
3729 frame_unhighlight (f
)
3733 ControlRef root_control
;
3736 err
= GetRootControl (FRAME_MAC_WINDOW (f
), &root_control
);
3738 DeactivateControl (root_control
);
3740 x_update_cursor (f
, 1);
3743 /* The focus has changed. Update the frames as necessary to reflect
3744 the new situation. Note that we can't change the selected frame
3745 here, because the Lisp code we are interrupting might become confused.
3746 Each event gets marked with the frame in which it occurred, so the
3747 Lisp code can tell when the switch took place by examining the events. */
3750 x_new_focus_frame (dpyinfo
, frame
)
3751 struct x_display_info
*dpyinfo
;
3752 struct frame
*frame
;
3754 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3756 if (frame
!= dpyinfo
->x_focus_frame
)
3758 /* Set this before calling other routines, so that they see
3759 the correct value of x_focus_frame. */
3760 dpyinfo
->x_focus_frame
= frame
;
3762 if (old_focus
&& old_focus
->auto_lower
)
3763 x_lower_frame (old_focus
);
3766 selected_frame
= frame
;
3767 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
3769 Fselect_window (selected_frame
->selected_window
, Qnil
);
3770 choose_minibuf_frame ();
3773 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3774 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3776 pending_autoraise_frame
= 0;
3779 x_frame_rehighlight (dpyinfo
);
3782 /* Handle FocusIn and FocusOut state changes for FRAME.
3783 If FRAME has focus and there exists more than one frame, puts
3784 a FOCUS_IN_EVENT into *BUFP. */
3787 mac_focus_changed (type
, dpyinfo
, frame
, bufp
)
3789 struct mac_display_info
*dpyinfo
;
3790 struct frame
*frame
;
3791 struct input_event
*bufp
;
3793 if (type
== activeFlag
)
3795 if (dpyinfo
->x_focus_event_frame
!= frame
)
3797 x_new_focus_frame (dpyinfo
, frame
);
3798 dpyinfo
->x_focus_event_frame
= frame
;
3800 /* Don't stop displaying the initial startup message
3801 for a switch-frame event we don't need. */
3802 if (GC_NILP (Vterminal_frame
)
3803 && GC_CONSP (Vframe_list
)
3804 && !GC_NILP (XCDR (Vframe_list
)))
3806 bufp
->kind
= FOCUS_IN_EVENT
;
3807 XSETFRAME (bufp
->frame_or_window
, frame
);
3813 if (dpyinfo
->x_focus_event_frame
== frame
)
3815 dpyinfo
->x_focus_event_frame
= 0;
3816 x_new_focus_frame (dpyinfo
, 0);
3821 /* The focus may have changed. Figure out if it is a real focus change,
3822 by checking both FocusIn/Out and Enter/LeaveNotify events.
3824 Returns FOCUS_IN_EVENT event in *BUFP. */
3827 x_detect_focus_change (dpyinfo
, event
, bufp
)
3828 struct mac_display_info
*dpyinfo
;
3830 struct input_event
*bufp
;
3832 struct frame
*frame
;
3834 frame
= mac_window_to_frame ((WindowPtr
) event
->message
);
3838 /* On Mac, this is only called from focus events, so no switch needed. */
3839 mac_focus_changed ((event
->modifiers
& activeFlag
),
3840 dpyinfo
, frame
, bufp
);
3844 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3847 x_mouse_leave (dpyinfo
)
3848 struct x_display_info
*dpyinfo
;
3850 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3853 /* The focus has changed, or we have redirected a frame's focus to
3854 another frame (this happens when a frame uses a surrogate
3855 mini-buffer frame). Shift the highlight as appropriate.
3857 The FRAME argument doesn't necessarily have anything to do with which
3858 frame is being highlighted or un-highlighted; we only use it to find
3859 the appropriate X display info. */
3862 XTframe_rehighlight (frame
)
3863 struct frame
*frame
;
3865 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3869 x_frame_rehighlight (dpyinfo
)
3870 struct x_display_info
*dpyinfo
;
3872 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3874 if (dpyinfo
->x_focus_frame
)
3876 dpyinfo
->x_highlight_frame
3877 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3878 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3879 : dpyinfo
->x_focus_frame
);
3880 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3882 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
3883 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3887 dpyinfo
->x_highlight_frame
= 0;
3889 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3892 frame_unhighlight (old_highlight
);
3893 if (dpyinfo
->x_highlight_frame
)
3894 frame_highlight (dpyinfo
->x_highlight_frame
);
3900 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3902 #if 0 /* MAC_TODO */
3903 /* Initialize mode_switch_bit and modifier_meaning. */
3905 x_find_modifier_meanings (dpyinfo
)
3906 struct x_display_info
*dpyinfo
;
3908 int min_code
, max_code
;
3911 XModifierKeymap
*mods
;
3913 dpyinfo
->meta_mod_mask
= 0;
3914 dpyinfo
->shift_lock_mask
= 0;
3915 dpyinfo
->alt_mod_mask
= 0;
3916 dpyinfo
->super_mod_mask
= 0;
3917 dpyinfo
->hyper_mod_mask
= 0;
3920 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3922 min_code
= dpyinfo
->display
->min_keycode
;
3923 max_code
= dpyinfo
->display
->max_keycode
;
3926 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3927 min_code
, max_code
- min_code
+ 1,
3929 mods
= XGetModifierMapping (dpyinfo
->display
);
3931 /* Scan the modifier table to see which modifier bits the Meta and
3932 Alt keysyms are on. */
3934 int row
, col
; /* The row and column in the modifier table. */
3936 for (row
= 3; row
< 8; row
++)
3937 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3940 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3942 /* Zeroes are used for filler. Skip them. */
3946 /* Are any of this keycode's keysyms a meta key? */
3950 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3952 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3958 dpyinfo
->meta_mod_mask
|= (1 << row
);
3963 dpyinfo
->alt_mod_mask
|= (1 << row
);
3968 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3973 dpyinfo
->super_mod_mask
|= (1 << row
);
3977 /* Ignore this if it's not on the lock modifier. */
3978 if ((1 << row
) == LockMask
)
3979 dpyinfo
->shift_lock_mask
= LockMask
;
3987 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3988 if (! dpyinfo
->meta_mod_mask
)
3990 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3991 dpyinfo
->alt_mod_mask
= 0;
3994 /* If some keys are both alt and meta,
3995 make them just meta, not alt. */
3996 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3998 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
4001 XFree ((char *) syms
);
4002 XFreeModifiermap (mods
);
4005 #endif /* MAC_TODO */
4007 /* Convert between the modifier bits X uses and the modifier bits
4011 x_mac_to_emacs_modifiers (dpyinfo
, state
)
4012 struct x_display_info
*dpyinfo
;
4013 unsigned short state
;
4015 return (((state
& shiftKey
) ? shift_modifier
: 0)
4016 | ((state
& controlKey
) ? ctrl_modifier
: 0)
4017 | ((state
& cmdKey
) ? meta_modifier
: 0)
4018 | ((state
& optionKey
) ? alt_modifier
: 0));
4021 #if 0 /* MAC_TODO */
4022 static unsigned short
4023 x_emacs_to_x_modifiers (dpyinfo
, state
)
4024 struct x_display_info
*dpyinfo
;
4027 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
4028 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
4029 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
4030 | ((state
& shift_modifier
) ? ShiftMask
: 0)
4031 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
4032 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
4034 #endif /* MAC_TODO */
4036 /* Convert a keysym to its name. */
4039 x_get_keysym_name (keysym
)
4046 value
= XKeysymToString (keysym
);
4057 /* Function to report a mouse movement to the mainstream Emacs code.
4058 The input handler calls this.
4060 We have received a mouse movement event, which is given in *event.
4061 If the mouse is over a different glyph than it was last time, tell
4062 the mainstream emacs code by setting mouse_moved. If not, ask for
4063 another motion event, so we can check again the next time it moves. */
4065 static Point last_mouse_motion_position
;
4066 static Lisp_Object last_mouse_motion_frame
;
4069 note_mouse_movement (frame
, pos
)
4073 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (frame
);
4074 #if TARGET_API_MAC_CARBON
4078 last_mouse_movement_time
= TickCount () * (1000 / 60); /* to milliseconds */
4079 last_mouse_motion_position
= *pos
;
4080 XSETFRAME (last_mouse_motion_frame
, frame
);
4082 #if TARGET_API_MAC_CARBON
4083 if (!PtInRect (*pos
, GetWindowPortBounds (FRAME_MAC_WINDOW (frame
), &r
)))
4085 if (!PtInRect (*pos
, &FRAME_MAC_WINDOW (frame
)->portRect
))
4088 if (frame
== dpyinfo
->mouse_face_mouse_frame
)
4089 /* This case corresponds to LeaveNotify in X11. */
4091 /* If we move outside the frame, then we're certainly no
4092 longer on any text in the frame. */
4093 clear_mouse_face (dpyinfo
);
4094 dpyinfo
->mouse_face_mouse_frame
= 0;
4095 if (!dpyinfo
->grabbed
)
4096 rif
->define_frame_cursor (frame
,
4097 frame
->output_data
.mac
->nontext_cursor
);
4101 /* Has the mouse moved off the glyph it was on at the last sighting? */
4102 if (frame
!= last_mouse_glyph_frame
4103 || !PtInRect (*pos
, &last_mouse_glyph
))
4105 frame
->mouse_moved
= 1;
4106 last_mouse_scroll_bar
= Qnil
;
4107 note_mouse_highlight (frame
, pos
->h
, pos
->v
);
4108 /* Remember which glyph we're now on. */
4109 remember_mouse_glyph (frame
, pos
->h
, pos
->v
, &last_mouse_glyph
);
4110 last_mouse_glyph_frame
= frame
;
4118 /************************************************************************
4120 ************************************************************************/
4122 /* MAC TODO: This should be called from somewhere (or removed) ++KFS */
4125 redo_mouse_highlight ()
4127 if (!NILP (last_mouse_motion_frame
)
4128 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
4129 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
4130 last_mouse_motion_position
.h
,
4131 last_mouse_motion_position
.v
);
4135 static struct frame
*
4136 mac_focus_frame (dpyinfo
)
4137 struct mac_display_info
*dpyinfo
;
4139 if (dpyinfo
->x_focus_frame
)
4140 return dpyinfo
->x_focus_frame
;
4142 /* Mac version may get events, such as a menu bar click, even when
4143 all the frames are invisible. In this case, we regard the
4144 event came to the selected frame. */
4145 return SELECTED_FRAME ();
4149 /* Return the current position of the mouse.
4150 *FP should be a frame which indicates which display to ask about.
4152 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
4153 and *PART to the frame, window, and scroll bar part that the mouse
4154 is over. Set *X and *Y to the portion and whole of the mouse's
4155 position on the scroll bar.
4157 If the mouse movement started elsewhere, set *FP to the frame the
4158 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
4161 Set *TIME to the server time-stamp for the time at which the mouse
4162 was at this position.
4164 Don't store anything if we don't have a valid set of values to report.
4166 This clears the mouse_moved flag, so we can wait for the next mouse
4170 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
4173 Lisp_Object
*bar_window
;
4174 enum scroll_bar_part
*part
;
4176 unsigned long *time
;
4182 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
4183 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
4186 Lisp_Object frame
, tail
;
4188 /* Clear the mouse-moved flag for every frame on this display. */
4189 FOR_EACH_FRAME (tail
, frame
)
4190 XFRAME (frame
)->mouse_moved
= 0;
4192 last_mouse_scroll_bar
= Qnil
;
4194 if (FRAME_MAC_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
4195 && FRAME_LIVE_P (last_mouse_frame
))
4196 f1
= last_mouse_frame
;
4198 f1
= mac_focus_frame (FRAME_MAC_DISPLAY_INFO (*fp
));
4202 /* Ok, we found a frame. Store all the values.
4203 last_mouse_glyph is a rectangle used to reduce the
4204 generation of mouse events. To not miss any motion
4205 events, we must divide the frame into rectangles of the
4206 size of the smallest character that could be displayed
4207 on it, i.e. into the same rectangles that matrices on
4208 the frame are divided into. */
4211 SetPortWindowPort (FRAME_MAC_WINDOW (f1
));
4212 GetMouse (&mouse_pos
);
4213 remember_mouse_glyph (f1
, mouse_pos
.h
, mouse_pos
.v
,
4215 last_mouse_glyph_frame
= f1
;
4220 XSETINT (*x
, mouse_pos
.h
);
4221 XSETINT (*y
, mouse_pos
.v
);
4222 *time
= last_mouse_movement_time
;
4230 /************************************************************************
4232 ************************************************************************/
4234 #ifdef USE_TOOLKIT_SCROLL_BARS
4236 static pascal void scroll_bar_timer_callback
P_ ((EventLoopTimerRef
, void *));
4237 static OSStatus install_scroll_bar_timer
P_ ((void));
4238 static OSStatus set_scroll_bar_timer
P_ ((EventTimerInterval
));
4239 static int control_part_code_to_scroll_bar_part
P_ ((ControlPartCode
));
4240 static void construct_scroll_bar_click
P_ ((struct scroll_bar
*, int,
4241 struct input_event
*));
4242 static OSErr get_control_part_bounds
P_ ((ControlHandle
, ControlPartCode
,
4244 static void x_scroll_bar_handle_press
P_ ((struct scroll_bar
*,
4246 struct input_event
*));
4247 static void x_scroll_bar_handle_release
P_ ((struct scroll_bar
*,
4248 struct input_event
*));
4249 static void x_scroll_bar_handle_drag
P_ ((WindowPtr
, struct scroll_bar
*,
4250 Point
, struct input_event
*));
4251 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
4254 /* Last scroll bar part sent in x_scroll_bar_handle_*. */
4256 static int last_scroll_bar_part
;
4258 static EventLoopTimerRef scroll_bar_timer
;
4260 static int scroll_bar_timer_event_posted_p
;
4262 #define SCROLL_BAR_FIRST_DELAY 0.5
4263 #define SCROLL_BAR_CONTINUOUS_DELAY (1.0 / 15)
4266 scroll_bar_timer_callback (timer
, data
)
4267 EventLoopTimerRef timer
;
4270 EventRef event
= NULL
;
4273 err
= CreateEvent (NULL
, kEventClassMouse
, kEventMouseMoved
, 0,
4274 kEventAttributeNone
, &event
);
4279 GetMouse (&mouse_pos
);
4280 LocalToGlobal (&mouse_pos
);
4281 err
= SetEventParameter (event
, kEventParamMouseLocation
, typeQDPoint
,
4282 sizeof (Point
), &mouse_pos
);
4286 UInt32 modifiers
= GetCurrentKeyModifiers ();
4288 err
= SetEventParameter (event
, kEventParamKeyModifiers
, typeUInt32
,
4289 sizeof (UInt32
), &modifiers
);
4292 err
= PostEventToQueue (GetCurrentEventQueue (), event
,
4293 kEventPriorityStandard
);
4295 scroll_bar_timer_event_posted_p
= 1;
4298 ReleaseEvent (event
);
4302 install_scroll_bar_timer ()
4304 static EventLoopTimerUPP scroll_bar_timer_callbackUPP
= NULL
;
4306 if (scroll_bar_timer_callbackUPP
== NULL
)
4307 scroll_bar_timer_callbackUPP
=
4308 NewEventLoopTimerUPP (scroll_bar_timer_callback
);
4310 if (scroll_bar_timer
== NULL
)
4311 /* Mac OS X and CarbonLib 1.5 and later allow us to specify
4312 kEventDurationForever as delays. */
4314 InstallEventLoopTimer (GetCurrentEventLoop (),
4315 kEventDurationForever
, kEventDurationForever
,
4316 scroll_bar_timer_callbackUPP
, NULL
,
4321 set_scroll_bar_timer (delay
)
4322 EventTimerInterval delay
;
4324 if (scroll_bar_timer
== NULL
)
4325 install_scroll_bar_timer ();
4327 scroll_bar_timer_event_posted_p
= 0;
4329 return SetEventLoopTimerNextFireTime (scroll_bar_timer
, delay
);
4333 control_part_code_to_scroll_bar_part (part_code
)
4334 ControlPartCode part_code
;
4338 case kControlUpButtonPart
: return scroll_bar_up_arrow
;
4339 case kControlDownButtonPart
: return scroll_bar_down_arrow
;
4340 case kControlPageUpPart
: return scroll_bar_above_handle
;
4341 case kControlPageDownPart
: return scroll_bar_below_handle
;
4342 case kControlIndicatorPart
: return scroll_bar_handle
;
4349 construct_scroll_bar_click (bar
, part
, bufp
)
4350 struct scroll_bar
*bar
;
4352 struct input_event
*bufp
;
4354 bufp
->kind
= SCROLL_BAR_CLICK_EVENT
;
4355 bufp
->frame_or_window
= bar
->window
;
4359 XSETINT (bufp
->x
, 0);
4360 XSETINT (bufp
->y
, 0);
4361 bufp
->modifiers
= 0;
4365 get_control_part_bounds (ch
, part_code
, rect
)
4367 ControlPartCode part_code
;
4370 RgnHandle region
= NewRgn ();
4373 err
= GetControlRegion (ch
, part_code
, region
);
4375 GetRegionBounds (region
, rect
);
4376 DisposeRgn (region
);
4382 x_scroll_bar_handle_press (bar
, part_code
, bufp
)
4383 struct scroll_bar
*bar
;
4384 ControlPartCode part_code
;
4385 struct input_event
*bufp
;
4387 int part
= control_part_code_to_scroll_bar_part (part_code
);
4392 if (part
!= scroll_bar_handle
)
4394 construct_scroll_bar_click (bar
, part
, bufp
);
4395 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), part_code
);
4396 set_scroll_bar_timer (SCROLL_BAR_FIRST_DELAY
);
4399 last_scroll_bar_part
= part
;
4400 bar
->dragging
= Qnil
;
4401 tracked_scroll_bar
= bar
;
4405 x_scroll_bar_handle_release (bar
, bufp
)
4406 struct scroll_bar
*bar
;
4407 struct input_event
*bufp
;
4409 if (last_scroll_bar_part
!= scroll_bar_handle
4410 || !GC_NILP (bar
->dragging
))
4411 construct_scroll_bar_click (bar
, scroll_bar_end_scroll
, bufp
);
4413 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), 0);
4414 set_scroll_bar_timer (kEventDurationForever
);
4416 last_scroll_bar_part
= -1;
4417 bar
->dragging
= Qnil
;
4418 tracked_scroll_bar
= NULL
;
4422 x_scroll_bar_handle_drag (win
, bar
, mouse_pos
, bufp
)
4424 struct scroll_bar
*bar
;
4426 struct input_event
*bufp
;
4428 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4430 if (last_scroll_bar_part
== scroll_bar_handle
)
4435 get_control_part_bounds (SCROLL_BAR_CONTROL_HANDLE (bar
),
4436 kControlIndicatorPart
, &r
);
4438 if (GC_NILP (bar
->dragging
))
4439 XSETINT (bar
->dragging
, mouse_pos
.v
- r
.top
);
4441 top
= mouse_pos
.v
- XINT (bar
->dragging
) - XINT (bar
->track_top
);
4442 top_range
= (XINT (bar
->track_height
) - (r
.bottom
- r
.top
)) *
4443 (1.0 + (float) GetControlViewSize (ch
) / GetControl32BitMaximum (ch
))
4448 if (top
> top_range
)
4451 construct_scroll_bar_click (bar
, scroll_bar_handle
, bufp
);
4452 XSETINT (bufp
->x
, top
);
4453 XSETINT (bufp
->y
, top_range
);
4457 ControlPartCode part_code
;
4458 int unhilite_p
= 0, part
;
4460 if (ch
!= FindControlUnderMouse (mouse_pos
, win
, &part_code
))
4464 part
= control_part_code_to_scroll_bar_part (part_code
);
4466 switch (last_scroll_bar_part
)
4468 case scroll_bar_above_handle
:
4469 case scroll_bar_below_handle
:
4470 if (part
!= scroll_bar_above_handle
4471 && part
!= scroll_bar_below_handle
)
4475 case scroll_bar_up_arrow
:
4476 case scroll_bar_down_arrow
:
4477 if (part
!= scroll_bar_up_arrow
4478 && part
!= scroll_bar_down_arrow
)
4485 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), 0);
4486 else if (part
!= last_scroll_bar_part
4487 || scroll_bar_timer_event_posted_p
)
4489 construct_scroll_bar_click (bar
, part
, bufp
);
4490 last_scroll_bar_part
= part
;
4491 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), part_code
);
4492 set_scroll_bar_timer (SCROLL_BAR_CONTINUOUS_DELAY
);
4497 /* Set the thumb size and position of scroll bar BAR. We are currently
4498 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4501 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4502 struct scroll_bar
*bar
;
4503 int portion
, position
, whole
;
4505 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4507 int value
, viewsize
, maximum
;
4509 if (whole
== 0 || XINT (bar
->track_height
) == 0)
4510 value
= 0, viewsize
= 1, maximum
= 0;
4515 maximum
= max (0, whole
- portion
);
4520 SetControl32BitMinimum (ch
, 0);
4521 SetControl32BitMaximum (ch
, maximum
);
4522 SetControl32BitValue (ch
, value
);
4523 SetControlViewSize (ch
, viewsize
);
4528 #endif /* USE_TOOLKIT_SCROLL_BARS */
4532 /************************************************************************
4533 Scroll bars, general
4534 ************************************************************************/
4536 /* Create a scroll bar and return the scroll bar vector for it. W is
4537 the Emacs window on which to create the scroll bar. TOP, LEFT,
4538 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4541 static struct scroll_bar
*
4542 x_scroll_bar_create (w
, top
, left
, width
, height
, disp_top
, disp_height
)
4544 int top
, left
, width
, height
, disp_top
, disp_height
;
4546 struct frame
*f
= XFRAME (w
->frame
);
4547 struct scroll_bar
*bar
4548 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
4556 r
.right
= left
+ width
;
4557 r
.bottom
= disp_top
+ disp_height
;
4559 #if TARGET_API_MAC_CARBON
4560 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p", width
< disp_height
,
4561 0, 0, 0, kControlScrollBarProc
, (long) bar
);
4563 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p", width
< disp_height
,
4564 0, 0, 0, scrollBarProc
, (long) bar
);
4566 SET_SCROLL_BAR_CONTROL_HANDLE (bar
, ch
);
4568 XSETWINDOW (bar
->window
, w
);
4569 XSETINT (bar
->top
, top
);
4570 XSETINT (bar
->left
, left
);
4571 XSETINT (bar
->width
, width
);
4572 XSETINT (bar
->height
, height
);
4573 XSETINT (bar
->start
, 0);
4574 XSETINT (bar
->end
, 0);
4575 bar
->dragging
= Qnil
;
4576 #ifdef USE_TOOLKIT_SCROLL_BARS
4577 bar
->track_top
= Qnil
;
4578 bar
->track_height
= Qnil
;
4581 /* Add bar to its frame's list of scroll bars. */
4582 bar
->next
= FRAME_SCROLL_BARS (f
);
4584 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4585 if (!NILP (bar
->next
))
4586 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4593 /* Draw BAR's handle in the proper position.
4595 If the handle is already drawn from START to END, don't bother
4596 redrawing it, unless REBUILD is non-zero; in that case, always
4597 redraw it. (REBUILD is handy for drawing the handle after expose
4600 Normally, we want to constrain the start and end of the handle to
4601 fit inside its rectangle, but if the user is dragging the scroll
4602 bar handle, we want to let them drag it down all the way, so that
4603 the bar's top is as far down as it goes; otherwise, there's no way
4604 to move to the very end of the buffer. */
4606 #ifndef USE_TOOLKIT_SCROLL_BARS
4609 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
4610 struct scroll_bar
*bar
;
4614 int dragging
= ! NILP (bar
->dragging
);
4615 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4616 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4617 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
4618 int length
= end
- start
;
4620 /* If the display is already accurate, do nothing. */
4622 && start
== XINT (bar
->start
)
4623 && end
== XINT (bar
->end
))
4628 /* Make sure the values are reasonable, and try to preserve the
4629 distance between start and end. */
4632 else if (start
> top_range
)
4634 end
= start
+ length
;
4638 else if (end
> top_range
&& ! dragging
)
4641 /* Store the adjusted setting in the scroll bar. */
4642 XSETINT (bar
->start
, start
);
4643 XSETINT (bar
->end
, end
);
4645 /* Clip the end position, just for display. */
4646 if (end
> top_range
)
4649 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
4650 top positions, to make sure the handle is always at least that
4651 many pixels tall. */
4652 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4654 SetControlMinimum (ch
, 0);
4655 /* Don't inadvertently activate deactivated scroll bars */
4656 if (GetControlMaximum (ch
) != -1)
4657 SetControlMaximum (ch
, top_range
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
4659 SetControlValue (ch
, start
);
4660 #if TARGET_API_MAC_CARBON
4661 SetControlViewSize (ch
, end
- start
);
4667 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4669 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4673 x_scroll_bar_remove (bar
)
4674 struct scroll_bar
*bar
;
4676 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4680 /* Destroy the Mac scroll bar control */
4681 DisposeControl (SCROLL_BAR_CONTROL_HANDLE (bar
));
4683 /* Disassociate this scroll bar from its window. */
4684 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
4690 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4691 that we are displaying PORTION characters out of a total of WHOLE
4692 characters, starting at POSITION. If WINDOW has no scroll bar,
4696 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
4698 int portion
, whole
, position
;
4700 struct frame
*f
= XFRAME (w
->frame
);
4701 struct scroll_bar
*bar
;
4702 int top
, height
, left
, sb_left
, width
, sb_width
, disp_top
, disp_height
;
4703 int window_y
, window_height
;
4705 /* Get window dimensions. */
4706 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
4708 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
4709 height
= window_height
;
4711 /* Compute the left edge of the scroll bar area. */
4712 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
4714 /* Compute the width of the scroll bar which might be less than
4715 the width of the area reserved for the scroll bar. */
4716 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
4717 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
4721 /* Compute the left edge of the scroll bar. */
4722 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
4725 sb_left
= left
+ width
- sb_width
;
4727 /* Adjustments according to Inside Macintosh to make it look nice */
4729 disp_height
= height
;
4735 else if (disp_top
== FRAME_PIXEL_HEIGHT (f
) - 16)
4741 if (sb_left
+ sb_width
== FRAME_PIXEL_WIDTH (f
))
4744 /* Does the scroll bar exist yet? */
4745 if (NILP (w
->vertical_scroll_bar
))
4748 mac_clear_area (f
, left
, top
, width
, height
);
4750 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
, disp_top
,
4752 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
4756 /* It may just need to be moved and resized. */
4759 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
4760 ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4764 /* If already correctly positioned, do nothing. */
4765 if (!(XINT (bar
->left
) == sb_left
4766 && XINT (bar
->top
) == top
4767 && XINT (bar
->width
) == sb_width
4768 && XINT (bar
->height
) == height
))
4770 /* Since toolkit scroll bars are smaller than the space reserved
4771 for them on the frame, we have to clear "under" them. */
4772 mac_clear_area (f
, left
, top
, width
, height
);
4775 MoveControl (ch
, sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
, disp_top
);
4776 SizeControl (ch
, sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4778 if (sb_width
< disp_height
)
4781 /* Remember new settings. */
4782 XSETINT (bar
->left
, sb_left
);
4783 XSETINT (bar
->top
, top
);
4784 XSETINT (bar
->width
, sb_width
);
4785 XSETINT (bar
->height
, height
);
4786 #ifdef USE_TOOLKIT_SCROLL_BARS
4787 bar
->track_top
= Qnil
;
4788 bar
->track_height
= Qnil
;
4795 #ifdef USE_TOOLKIT_SCROLL_BARS
4796 if (NILP (bar
->track_top
))
4798 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4803 SetControl32BitMinimum (ch
, 0);
4804 SetControl32BitMaximum (ch
, 1);
4805 SetControlViewSize (ch
, 1);
4807 /* Move the scroll bar thumb to the top. */
4808 SetControl32BitValue (ch
, 0);
4809 get_control_part_bounds (ch
, kControlIndicatorPart
, &r0
);
4811 /* Move the scroll bar thumb to the bottom. */
4812 SetControl32BitValue (ch
, 1);
4813 get_control_part_bounds (ch
, kControlIndicatorPart
, &r1
);
4815 UnionRect (&r0
, &r1
, &r0
);
4816 XSETINT (bar
->track_top
, r0
.top
);
4817 XSETINT (bar
->track_height
, r0
.bottom
- r0
.top
);
4822 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4823 #else /* not USE_TOOLKIT_SCROLL_BARS */
4824 /* Set the scroll bar's current state, unless we're currently being
4826 if (NILP (bar
->dragging
))
4828 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
4831 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
4834 int start
= ((double) position
* top_range
) / whole
;
4835 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
4836 x_scroll_bar_set_handle (bar
, start
, end
, 0);
4839 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4843 /* The following three hooks are used when we're doing a thorough
4844 redisplay of the frame. We don't explicitly know which scroll bars
4845 are going to be deleted, because keeping track of when windows go
4846 away is a real pain - "Can you say set-window-configuration, boys
4847 and girls?" Instead, we just assert at the beginning of redisplay
4848 that *all* scroll bars are to be removed, and then save a scroll bar
4849 from the fiery pit when we actually redisplay its window. */
4851 /* Arrange for all scroll bars on FRAME to be removed at the next call
4852 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
4853 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
4856 XTcondemn_scroll_bars (frame
)
4859 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
4860 while (! NILP (FRAME_SCROLL_BARS (frame
)))
4863 bar
= FRAME_SCROLL_BARS (frame
);
4864 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
4865 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
4866 XSCROLL_BAR (bar
)->prev
= Qnil
;
4867 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
4868 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
4869 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
4874 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
4875 Note that WINDOW isn't necessarily condemned at all. */
4878 XTredeem_scroll_bar (window
)
4879 struct window
*window
;
4881 struct scroll_bar
*bar
;
4884 /* We can't redeem this window's scroll bar if it doesn't have one. */
4885 if (NILP (window
->vertical_scroll_bar
))
4888 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
4890 /* Unlink it from the condemned list. */
4891 f
= XFRAME (WINDOW_FRAME (window
));
4892 if (NILP (bar
->prev
))
4894 /* If the prev pointer is nil, it must be the first in one of
4896 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
4897 /* It's not condemned. Everything's fine. */
4899 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
4900 window
->vertical_scroll_bar
))
4901 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
4903 /* If its prev pointer is nil, it must be at the front of
4904 one or the other! */
4908 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
4910 if (! NILP (bar
->next
))
4911 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
4913 bar
->next
= FRAME_SCROLL_BARS (f
);
4915 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4916 if (! NILP (bar
->next
))
4917 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4920 /* Remove all scroll bars on FRAME that haven't been saved since the
4921 last call to `*condemn_scroll_bars_hook'. */
4924 XTjudge_scroll_bars (f
)
4927 Lisp_Object bar
, next
;
4929 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
4931 /* Clear out the condemned list now so we won't try to process any
4932 more events on the hapless scroll bars. */
4933 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
4935 for (; ! NILP (bar
); bar
= next
)
4937 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
4939 x_scroll_bar_remove (b
);
4942 b
->next
= b
->prev
= Qnil
;
4945 /* Now there should be no references to the condemned scroll bars,
4946 and they should get garbage-collected. */
4950 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
4951 is set to something other than NO_EVENT, it is enqueued.
4953 This may be called from a signal handler, so we have to ignore GC
4957 x_scroll_bar_handle_click (bar
, part_code
, er
, bufp
)
4958 struct scroll_bar
*bar
;
4959 ControlPartCode part_code
;
4961 struct input_event
*bufp
;
4963 int win_y
, top_range
;
4965 if (! GC_WINDOWP (bar
->window
))
4968 bufp
->kind
= SCROLL_BAR_CLICK_EVENT
;
4969 bufp
->frame_or_window
= bar
->window
;
4972 bar
->dragging
= Qnil
;
4976 case kControlUpButtonPart
:
4977 bufp
->part
= scroll_bar_up_arrow
;
4979 case kControlDownButtonPart
:
4980 bufp
->part
= scroll_bar_down_arrow
;
4982 case kControlPageUpPart
:
4983 bufp
->part
= scroll_bar_above_handle
;
4985 case kControlPageDownPart
:
4986 bufp
->part
= scroll_bar_below_handle
;
4988 #if TARGET_API_MAC_CARBON
4991 case kControlIndicatorPart
:
4993 if (er
->what
== mouseDown
)
4994 bar
->dragging
= make_number (0);
4995 XSETVECTOR (last_mouse_scroll_bar
, bar
);
4996 bufp
->part
= scroll_bar_handle
;
5000 win_y
= XINT (bufp
->y
) - XINT (bar
->top
);
5001 top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (0/*dummy*/, XINT (bar
->height
));
5003 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5007 if (! NILP (bar
->dragging
))
5008 win_y
-= XINT (bar
->dragging
);
5012 if (win_y
> top_range
)
5015 XSETINT (bufp
->x
, win_y
);
5016 XSETINT (bufp
->y
, top_range
);
5019 #ifndef USE_TOOLKIT_SCROLL_BARS
5021 /* Handle some mouse motion while someone is dragging the scroll bar.
5023 This may be called from a signal handler, so we have to ignore GC
5027 x_scroll_bar_note_movement (bar
, y_pos
, t
)
5028 struct scroll_bar
*bar
;
5032 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5034 last_mouse_movement_time
= t
;
5037 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5039 /* If we're dragging the bar, display it. */
5040 if (! GC_NILP (bar
->dragging
))
5042 /* Where should the handle be now? */
5043 int new_start
= y_pos
- 24;
5045 if (new_start
!= XINT (bar
->start
))
5047 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
5049 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5054 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5056 /* Return information to the user about the current position of the mouse
5057 on the scroll bar. */
5060 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
5062 Lisp_Object
*bar_window
;
5063 enum scroll_bar_part
*part
;
5065 unsigned long *time
;
5067 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5068 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
5069 #if TARGET_API_MAC_CARBON
5070 WindowPtr wp
= GetControlOwner (ch
);
5072 WindowPtr wp
= (*ch
)->contrlOwner
;
5075 struct frame
*f
= mac_window_to_frame (wp
);
5076 int win_y
, top_range
;
5078 SetPortWindowPort (wp
);
5080 GetMouse (&mouse_pos
);
5082 win_y
= mouse_pos
.v
- XINT (bar
->top
);
5083 top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
5085 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5089 if (! NILP (bar
->dragging
))
5090 win_y
-= XINT (bar
->dragging
);
5094 if (win_y
> top_range
)
5098 *bar_window
= bar
->window
;
5100 if (! NILP (bar
->dragging
))
5101 *part
= scroll_bar_handle
;
5102 else if (win_y
< XINT (bar
->start
))
5103 *part
= scroll_bar_above_handle
;
5104 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5105 *part
= scroll_bar_handle
;
5107 *part
= scroll_bar_below_handle
;
5109 XSETINT (*x
, win_y
);
5110 XSETINT (*y
, top_range
);
5113 last_mouse_scroll_bar
= Qnil
;
5115 *time
= last_mouse_movement_time
;
5119 /* The screen has been cleared so we may have changed foreground or
5120 background colors, and the scroll bars may need to be redrawn.
5121 Clear out the scroll bars, and ask for expose events, so we can
5125 x_scroll_bar_clear (f
)
5128 XTcondemn_scroll_bars (f
);
5129 XTjudge_scroll_bars (f
);
5133 /***********************************************************************
5135 ***********************************************************************/
5137 /* Set clipping for output in glyph row ROW. W is the window in which
5138 we operate. GC is the graphics context to set clipping in.
5140 ROW may be a text row or, e.g., a mode line. Text rows must be
5141 clipped to the interior of the window dedicated to text display,
5142 mode lines must be clipped to the whole window. */
5145 x_clip_to_row (w
, row
, area
, gc
)
5147 struct glyph_row
*row
;
5151 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5153 int window_x
, window_y
, window_width
;
5155 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
5157 clip_rect
.left
= window_x
;
5158 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
5159 clip_rect
.top
= max (clip_rect
.top
, window_y
);
5160 clip_rect
.right
= clip_rect
.left
+ window_width
;
5161 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
5163 mac_set_clip_rectangles (FRAME_MAC_DISPLAY (f
), gc
, &clip_rect
, 1);
5167 /* Draw a hollow box cursor on window W in glyph row ROW. */
5170 x_draw_hollow_cursor (w
, row
)
5172 struct glyph_row
*row
;
5174 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5175 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
5176 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
5179 struct glyph
*cursor_glyph
;
5182 /* Get the glyph the cursor is on. If we can't tell because
5183 the current matrix is invalid or such, give up. */
5184 cursor_glyph
= get_phys_cursor_glyph (w
);
5185 if (cursor_glyph
== NULL
)
5188 /* Compute frame-relative coordinates for phys cursor. */
5189 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
5190 y
= get_phys_cursor_geometry (w
, row
, cursor_glyph
, &h
);
5191 wd
= w
->phys_cursor_width
;
5193 /* The foreground of cursor_gc is typically the same as the normal
5194 background color, which can cause the cursor box to be invisible. */
5195 xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
5196 if (dpyinfo
->scratch_cursor_gc
)
5197 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
5199 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_MAC_WINDOW (f
),
5200 GCForeground
, &xgcv
);
5201 gc
= dpyinfo
->scratch_cursor_gc
;
5203 /* Set clipping, draw the rectangle, and reset clipping again. */
5204 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
5205 mac_draw_rectangle (f
, gc
, x
, y
, wd
, h
);
5206 mac_reset_clip_rectangles (dpy
, gc
);
5210 /* Draw a bar cursor on window W in glyph row ROW.
5212 Implementation note: One would like to draw a bar cursor with an
5213 angle equal to the one given by the font property XA_ITALIC_ANGLE.
5214 Unfortunately, I didn't find a font yet that has this property set.
5218 x_draw_bar_cursor (w
, row
, width
, kind
)
5220 struct glyph_row
*row
;
5222 enum text_cursor_kinds kind
;
5224 struct frame
*f
= XFRAME (w
->frame
);
5225 struct glyph
*cursor_glyph
;
5227 /* If cursor is out of bounds, don't draw garbage. This can happen
5228 in mini-buffer windows when switching between echo area glyphs
5230 cursor_glyph
= get_phys_cursor_glyph (w
);
5231 if (cursor_glyph
== NULL
)
5234 /* If on an image, draw like a normal cursor. That's usually better
5235 visible than drawing a bar, esp. if the image is large so that
5236 the bar might not be in the window. */
5237 if (cursor_glyph
->type
== IMAGE_GLYPH
)
5239 struct glyph_row
*row
;
5240 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
5241 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
5245 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
5246 Window window
= FRAME_MAC_WINDOW (f
);
5247 GC gc
= FRAME_MAC_DISPLAY_INFO (f
)->scratch_cursor_gc
;
5248 unsigned long mask
= GCForeground
| GCBackground
;
5249 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
5252 /* If the glyph's background equals the color we normally draw
5253 the bar cursor in, the bar cursor in its normal color is
5254 invisible. Use the glyph's foreground color instead in this
5255 case, on the assumption that the glyph's colors are chosen so
5256 that the glyph is legible. */
5257 if (face
->background
== f
->output_data
.mac
->cursor_pixel
)
5258 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
5260 xgcv
.background
= xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
5263 XChangeGC (dpy
, gc
, mask
, &xgcv
);
5266 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
5267 FRAME_MAC_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
5271 width
= FRAME_CURSOR_WIDTH (f
);
5272 width
= min (cursor_glyph
->pixel_width
, width
);
5274 w
->phys_cursor_width
= width
;
5275 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
5277 if (kind
== BAR_CURSOR
)
5278 mac_fill_rectangle (f
, gc
,
5279 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
5280 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
5281 width
, row
->height
);
5283 mac_fill_rectangle (f
, gc
,
5284 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
5285 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
5286 row
->height
- width
),
5287 cursor_glyph
->pixel_width
,
5290 mac_reset_clip_rectangles (dpy
, gc
);
5295 /* RIF: Define cursor CURSOR on frame F. */
5298 mac_define_frame_cursor (f
, cursor
)
5302 SetThemeCursor (cursor
);
5306 /* RIF: Clear area on frame F. */
5309 mac_clear_frame_area (f
, x
, y
, width
, height
)
5311 int x
, y
, width
, height
;
5313 mac_clear_area (f
, x
, y
, width
, height
);
5317 /* RIF: Draw cursor on window W. */
5320 mac_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
5322 struct glyph_row
*glyph_row
;
5324 int cursor_type
, cursor_width
;
5329 w
->phys_cursor_type
= cursor_type
;
5330 w
->phys_cursor_on_p
= 1;
5332 if (glyph_row
->exact_window_width_line_p
5333 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
5335 glyph_row
->cursor_in_fringe_p
= 1;
5336 draw_fringe_bitmap (w
, glyph_row
, 0);
5339 switch (cursor_type
)
5341 case HOLLOW_BOX_CURSOR
:
5342 x_draw_hollow_cursor (w
, glyph_row
);
5345 case FILLED_BOX_CURSOR
:
5346 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
5350 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
5354 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
5358 w
->phys_cursor_width
= 0;
5370 #if 0 /* MAC_TODO: no icon support yet. */
5372 x_bitmap_icon (f
, icon
)
5378 if (FRAME_W32_WINDOW (f
) == 0)
5382 hicon
= LoadIcon (hinst
, EMACS_CLASS
);
5383 else if (STRINGP (icon
))
5384 hicon
= LoadImage (NULL
, (LPCTSTR
) SDATA (icon
), IMAGE_ICON
, 0, 0,
5385 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
5386 else if (SYMBOLP (icon
))
5390 if (EQ (icon
, intern ("application")))
5391 name
= (LPCTSTR
) IDI_APPLICATION
;
5392 else if (EQ (icon
, intern ("hand")))
5393 name
= (LPCTSTR
) IDI_HAND
;
5394 else if (EQ (icon
, intern ("question")))
5395 name
= (LPCTSTR
) IDI_QUESTION
;
5396 else if (EQ (icon
, intern ("exclamation")))
5397 name
= (LPCTSTR
) IDI_EXCLAMATION
;
5398 else if (EQ (icon
, intern ("asterisk")))
5399 name
= (LPCTSTR
) IDI_ASTERISK
;
5400 else if (EQ (icon
, intern ("winlogo")))
5401 name
= (LPCTSTR
) IDI_WINLOGO
;
5405 hicon
= LoadIcon (NULL
, name
);
5413 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
5418 #endif /* MAC_TODO */
5420 /************************************************************************
5422 ************************************************************************/
5424 /* Display Error Handling functions not used on W32. Listing them here
5425 helps diff stay in step when comparing w32term.c with xterm.c.
5427 x_error_catcher (display, error)
5428 x_catch_errors (dpy)
5429 x_catch_errors_unwind (old_val)
5430 x_check_errors (dpy, format)
5431 x_had_errors_p (dpy)
5432 x_clear_errors (dpy)
5433 x_uncatch_errors (dpy, count)
5435 x_connection_signal (signalnum)
5436 x_connection_closed (dpy, error_message)
5437 x_error_quitter (display, error)
5438 x_error_handler (display, error)
5439 x_io_error_quitter (display)
5444 /* Changing the font of the frame. */
5446 /* Give frame F the font named FONTNAME as its default font, and
5447 return the full name of that font. FONTNAME may be a wildcard
5448 pattern; in that case, we choose some font that fits the pattern.
5449 The return value shows which font we chose. */
5452 x_new_font (f
, fontname
)
5454 register char *fontname
;
5456 struct font_info
*fontp
5457 = FS_LOAD_FONT (f
, 0, fontname
, -1);
5462 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
5463 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
5464 FRAME_FONTSET (f
) = -1;
5466 FRAME_COLUMN_WIDTH (f
) = fontp
->average_width
;
5467 FRAME_SPACE_WIDTH (f
) = fontp
->space_width
;
5468 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (FRAME_FONT (f
));
5470 compute_fringe_widths (f
, 1);
5472 /* Compute the scroll bar width in character columns. */
5473 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
5475 int wid
= FRAME_COLUMN_WIDTH (f
);
5476 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
5477 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
5481 int wid
= FRAME_COLUMN_WIDTH (f
);
5482 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
5485 /* Now make the frame display the given font. */
5486 if (FRAME_MAC_WINDOW (f
) != 0)
5488 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->normal_gc
,
5490 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->reverse_gc
,
5492 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->cursor_gc
,
5495 /* Don't change the size of a tip frame; there's no point in
5496 doing it because it's done in Fx_show_tip, and it leads to
5497 problems because the tip frame has no widget. */
5498 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
5499 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
5502 return build_string (fontp
->full_name
);
5505 /* Give frame F the fontset named FONTSETNAME as its default font, and
5506 return the full name of that fontset. FONTSETNAME may be a wildcard
5507 pattern; in that case, we choose some fontset that fits the pattern.
5508 The return value shows which fontset we chose. */
5511 x_new_fontset (f
, fontsetname
)
5515 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
5521 if (FRAME_FONTSET (f
) == fontset
)
5522 /* This fontset is already set in frame F. There's nothing more
5524 return fontset_name (fontset
);
5526 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
5528 if (!STRINGP (result
))
5529 /* Can't load ASCII font. */
5532 /* Since x_new_font doesn't update any fontset information, do it now. */
5533 FRAME_FONTSET (f
) = fontset
;
5535 return build_string (fontsetname
);
5539 /***********************************************************************
5540 TODO: W32 Input Methods
5541 ***********************************************************************/
5542 /* Listing missing functions from xterm.c helps diff stay in step.
5544 xim_destroy_callback (xim, client_data, call_data)
5545 xim_open_dpy (dpyinfo, resource_name)
5547 xim_instantiate_callback (display, client_data, call_data)
5548 xim_initialize (dpyinfo, resource_name)
5549 xim_close_dpy (dpyinfo)
5555 mac_get_window_bounds (f
, inner
, outer
)
5557 Rect
*inner
, *outer
;
5559 #if TARGET_API_MAC_CARBON
5560 GetWindowBounds (FRAME_MAC_WINDOW (f
), kWindowContentRgn
, inner
);
5561 GetWindowBounds (FRAME_MAC_WINDOW (f
), kWindowStructureRgn
, outer
);
5562 #else /* not TARGET_API_MAC_CARBON */
5563 RgnHandle region
= NewRgn ();
5565 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowContentRgn
, region
);
5566 *inner
= (*region
)->rgnBBox
;
5567 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowStructureRgn
, region
);
5568 *outer
= (*region
)->rgnBBox
;
5569 DisposeRgn (region
);
5570 #endif /* not TARGET_API_MAC_CARBON */
5575 /* Calculate the absolute position in frame F
5576 from its current recorded position values and gravity. */
5579 x_calc_absolute_position (f
)
5582 int width_diff
= 0, height_diff
= 0;
5583 int flags
= f
->size_hint_flags
;
5586 /* We have nothing to do if the current position
5587 is already for the top-left corner. */
5588 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
5591 /* Find the offsets of the outside upper-left corner of
5592 the inner window, with respect to the outer window. */
5593 mac_get_window_bounds (f
, &inner
, &outer
);
5595 width_diff
= (outer
.right
- outer
.left
) - (inner
.right
- inner
.left
);
5596 height_diff
= (outer
.bottom
- outer
.top
) - (inner
.bottom
- inner
.top
);
5598 /* Treat negative positions as relative to the leftmost bottommost
5599 position that fits on the screen. */
5600 if (flags
& XNegative
)
5601 f
->left_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->width
5603 - FRAME_PIXEL_WIDTH (f
)
5606 if (flags
& YNegative
)
5607 f
->top_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->height
5609 - FRAME_PIXEL_HEIGHT (f
)
5612 /* The left_pos and top_pos
5613 are now relative to the top and left screen edges,
5614 so the flags should correspond. */
5615 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5618 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
5619 to really change the position, and 0 when calling from
5620 x_make_frame_visible (in that case, XOFF and YOFF are the current
5621 position values). It is -1 when calling from x_set_frame_parameters,
5622 which means, do adjust for borders but don't change the gravity. */
5625 x_set_offset (f
, xoff
, yoff
, change_gravity
)
5627 register int xoff
, yoff
;
5630 if (change_gravity
> 0)
5634 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5636 f
->size_hint_flags
|= XNegative
;
5638 f
->size_hint_flags
|= YNegative
;
5639 f
->win_gravity
= NorthWestGravity
;
5641 x_calc_absolute_position (f
);
5644 x_wm_set_size_hint (f
, (long) 0, 0);
5646 #if TARGET_API_MAC_CARBON
5647 MoveWindowStructure (FRAME_MAC_WINDOW (f
), f
->left_pos
, f
->top_pos
);
5648 /* If the title bar is completely outside the screen, adjust the
5650 ConstrainWindowToScreen (FRAME_MAC_WINDOW (f
), kWindowTitleBarRgn
,
5651 kWindowConstrainMoveRegardlessOfFit
5652 | kWindowConstrainAllowPartial
, NULL
, NULL
);
5653 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
5656 Rect inner
, outer
, screen_rect
, dummy
;
5657 RgnHandle region
= NewRgn ();
5659 mac_get_window_bounds (f
, &inner
, &outer
);
5660 f
->x_pixels_diff
= inner
.left
- outer
.left
;
5661 f
->y_pixels_diff
= inner
.top
- outer
.top
;
5662 MoveWindow (FRAME_MAC_WINDOW (f
), f
->left_pos
+ f
->x_pixels_diff
,
5663 f
->top_pos
+ f
->y_pixels_diff
, false);
5665 /* If the title bar is completely outside the screen, adjust the
5666 position. The variable `outer' holds the title bar rectangle.
5667 The variable `inner' holds slightly smaller one than `outer',
5668 so that the calculation of overlapping may not become too
5670 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowTitleBarRgn
, region
);
5671 outer
= (*region
)->rgnBBox
;
5672 DisposeRgn (region
);
5674 InsetRect (&inner
, 8, 8);
5675 screen_rect
= qd
.screenBits
.bounds
;
5676 screen_rect
.top
+= GetMBarHeight ();
5678 if (!SectRect (&inner
, &screen_rect
, &dummy
))
5680 if (inner
.right
<= screen_rect
.left
)
5681 f
->left_pos
= screen_rect
.left
;
5682 else if (inner
.left
>= screen_rect
.right
)
5683 f
->left_pos
= screen_rect
.right
- (outer
.right
- outer
.left
);
5685 if (inner
.bottom
<= screen_rect
.top
)
5686 f
->top_pos
= screen_rect
.top
;
5687 else if (inner
.top
>= screen_rect
.bottom
)
5688 f
->top_pos
= screen_rect
.bottom
- (outer
.bottom
- outer
.top
);
5690 MoveWindow (FRAME_MAC_WINDOW (f
), f
->left_pos
+ f
->x_pixels_diff
,
5691 f
->top_pos
+ f
->y_pixels_diff
, false);
5699 /* Call this to change the size of frame F's x-window.
5700 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
5701 for this size change and subsequent size changes.
5702 Otherwise we leave the window gravity unchanged. */
5705 x_set_window_size (f
, change_gravity
, cols
, rows
)
5710 int pixelwidth
, pixelheight
;
5714 check_frame_size (f
, &rows
, &cols
);
5715 f
->scroll_bar_actual_width
5716 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
5718 compute_fringe_widths (f
, 0);
5720 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
5721 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
5723 f
->win_gravity
= NorthWestGravity
;
5724 x_wm_set_size_hint (f
, (long) 0, 0);
5726 SizeWindow (FRAME_MAC_WINDOW (f
), pixelwidth
, pixelheight
, 0);
5727 #if TARGET_API_MAC_CARBON
5728 if (f
->output_data
.mac
->hourglass_control
)
5729 MoveControl (f
->output_data
.mac
->hourglass_control
,
5730 pixelwidth
- HOURGLASS_WIDTH
, 0);
5733 /* Now, strictly speaking, we can't be sure that this is accurate,
5734 but the window manager will get around to dealing with the size
5735 change request eventually, and we'll hear how it went when the
5736 ConfigureNotify event gets here.
5738 We could just not bother storing any of this information here,
5739 and let the ConfigureNotify event set everything up, but that
5740 might be kind of confusing to the Lisp code, since size changes
5741 wouldn't be reported in the frame parameters until some random
5742 point in the future when the ConfigureNotify event arrives.
5744 We pass 1 for DELAY since we can't run Lisp code inside of
5746 change_frame_size (f
, rows
, cols
, 0, 1, 0);
5747 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
5748 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
5750 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
5751 receive in the ConfigureNotify event; if we get what we asked
5752 for, then the event won't cause the screen to become garbaged, so
5753 we have to make sure to do it here. */
5754 SET_FRAME_GARBAGED (f
);
5756 XFlush (FRAME_X_DISPLAY (f
));
5758 /* If cursor was outside the new size, mark it as off. */
5759 mark_window_cursors_off (XWINDOW (f
->root_window
));
5761 /* Clear out any recollection of where the mouse highlighting was,
5762 since it might be in a place that's outside the new frame size.
5763 Actually checking whether it is outside is a pain in the neck,
5764 so don't try--just let the highlighting be done afresh with new size. */
5765 cancel_mouse_face (f
);
5770 /* Mouse warping. */
5772 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
5775 x_set_mouse_position (f
, x
, y
)
5781 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
5782 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
5784 if (pix_x
< 0) pix_x
= 0;
5785 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
5787 if (pix_y
< 0) pix_y
= 0;
5788 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
5790 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
5794 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
5798 #if 0 /* MAC_TODO: CursorDeviceMoveTo is non-Carbon */
5801 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
5802 0, 0, 0, 0, pix_x
, pix_y
);
5807 /* focus shifting, raising and lowering. */
5810 x_focus_on_frame (f
)
5813 #if 0 /* This proves to be unpleasant. */
5817 /* I don't think that the ICCCM allows programs to do things like this
5818 without the interaction of the window manager. Whatever you end up
5819 doing with this code, do it to x_unfocus_frame too. */
5820 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5821 RevertToPointerRoot
, CurrentTime
);
5831 /* Raise frame F. */
5837 if (f
->async_visible
)
5840 SelectWindow (FRAME_MAC_WINDOW (f
));
5845 /* Lower frame F. */
5851 if (f
->async_visible
)
5854 SendBehind (FRAME_MAC_WINDOW (f
), nil
);
5860 XTframe_raise_lower (f
, raise_flag
)
5870 /* Change of visibility. */
5873 mac_handle_visibility_change (f
)
5876 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
5877 int visible
= 0, iconified
= 0;
5878 struct input_event buf
;
5880 if (IsWindowVisible (wp
))
5881 if (IsWindowCollapsed (wp
))
5886 if (!f
->async_visible
&& visible
)
5890 /* wait_reading_process_output will notice this and update
5891 the frame's display structures. If we were made
5892 invisible, we should not set garbaged, because that stops
5893 redrawing on Update events. */
5894 SET_FRAME_GARBAGED (f
);
5897 buf
.kind
= DEICONIFY_EVENT
;
5898 XSETFRAME (buf
.frame_or_window
, f
);
5899 kbd_buffer_store_event (&buf
);
5901 else if (! NILP (Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
5902 /* Force a redisplay sooner or later to update the
5903 frame titles in case this is the second frame. */
5904 record_asynch_buffer_change ();
5906 else if (f
->async_visible
&& !visible
)
5910 buf
.kind
= ICONIFY_EVENT
;
5911 XSETFRAME (buf
.frame_or_window
, f
);
5912 kbd_buffer_store_event (&buf
);
5915 f
->async_visible
= visible
;
5916 f
->async_iconified
= iconified
;
5919 /* This tries to wait until the frame is really visible.
5920 However, if the window manager asks the user where to position
5921 the frame, this will return before the user finishes doing that.
5922 The frame will not actually be visible at that time,
5923 but it will become visible later when the window manager
5924 finishes with it. */
5927 x_make_frame_visible (f
)
5931 int original_top
, original_left
;
5935 if (! FRAME_VISIBLE_P (f
))
5937 /* We test FRAME_GARBAGED_P here to make sure we don't
5938 call x_set_offset a second time
5939 if we get to x_make_frame_visible a second time
5940 before the window gets really visible. */
5941 if (! FRAME_ICONIFIED_P (f
)
5942 && ! f
->output_data
.mac
->asked_for_visible
)
5943 #if TARGET_API_MAC_CARBON
5944 if (!(FRAME_SIZE_HINTS (f
)->flags
& (USPosition
| PPosition
)))
5946 struct frame
*sf
= SELECTED_FRAME ();
5947 if (!FRAME_MAC_P (sf
))
5948 RepositionWindow (FRAME_MAC_WINDOW (f
), NULL
,
5949 kWindowCenterOnMainScreen
);
5951 RepositionWindow (FRAME_MAC_WINDOW (f
),
5952 FRAME_MAC_WINDOW (sf
),
5953 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
5954 kWindowCascadeStartAtParentWindowScreen
5956 kWindowCascadeOnParentWindowScreen
5959 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
5963 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
5965 f
->output_data
.mac
->asked_for_visible
= 1;
5967 SelectWindow (FRAME_MAC_WINDOW (f
));
5968 CollapseWindow (FRAME_MAC_WINDOW (f
), false);
5969 ShowWindow (FRAME_MAC_WINDOW (f
));
5972 XFlush (FRAME_MAC_DISPLAY (f
));
5974 /* Synchronize to ensure Emacs knows the frame is visible
5975 before we do anything else. We do this loop with input not blocked
5976 so that incoming events are handled. */
5981 /* This must come after we set COUNT. */
5984 XSETFRAME (frame
, f
);
5986 /* Wait until the frame is visible. Process X events until a
5987 MapNotify event has been seen, or until we think we won't get a
5988 MapNotify at all.. */
5989 for (count
= input_signal_count
+ 10;
5990 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
5992 /* Force processing of queued events. */
5995 /* Machines that do polling rather than SIGIO have been
5996 observed to go into a busy-wait here. So we'll fake an
5997 alarm signal to let the handler know that there's something
5998 to be read. We used to raise a real alarm, but it seems
5999 that the handler isn't always enabled here. This is
6001 if (input_polling_used ())
6003 /* It could be confusing if a real alarm arrives while
6004 processing the fake one. Turn it off and let the
6005 handler reset it. */
6006 extern void poll_for_input_1
P_ ((void));
6007 int old_poll_suppress_count
= poll_suppress_count
;
6008 poll_suppress_count
= 1;
6009 poll_for_input_1 ();
6010 poll_suppress_count
= old_poll_suppress_count
;
6013 /* See if a MapNotify event has been processed. */
6014 FRAME_SAMPLE_VISIBILITY (f
);
6019 /* Change from mapped state to withdrawn state. */
6021 /* Make the frame visible (mapped and not iconified). */
6024 x_make_frame_invisible (f
)
6027 /* A deactivate event does not occur when the last visible frame is
6028 made invisible. So if we clear the highlight here, it will not
6029 be rehighlighted when it is made visible. */
6031 /* Don't keep the highlight on an invisible frame. */
6032 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
6033 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
6038 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
6039 that the current position of the window is user-specified, rather than
6040 program-specified, so that when the window is mapped again, it will be
6041 placed at the same location, without forcing the user to position it
6042 by hand again (they have already done that once for this window.) */
6043 x_wm_set_size_hint (f
, (long) 0, 1);
6045 HideWindow (FRAME_MAC_WINDOW (f
));
6049 #if !USE_CARBON_EVENTS
6050 mac_handle_visibility_change (f
);
6054 /* Change window state from mapped to iconified. */
6062 /* A deactivate event does not occur when the last visible frame is
6063 iconified. So if we clear the highlight here, it will not be
6064 rehighlighted when it is deiconified. */
6066 /* Don't keep the highlight on an invisible frame. */
6067 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
6068 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
6071 if (f
->async_iconified
)
6076 FRAME_SAMPLE_VISIBILITY (f
);
6078 if (! FRAME_VISIBLE_P (f
))
6079 ShowWindow (FRAME_MAC_WINDOW (f
));
6081 err
= CollapseWindow (FRAME_MAC_WINDOW (f
), true);
6086 error ("Can't notify window manager of iconification");
6088 #if !USE_CARBON_EVENTS
6089 mac_handle_visibility_change (f
);
6094 /* Free X resources of frame F. */
6097 x_free_frame_resources (f
)
6100 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6101 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
6105 if (wp
!= tip_window
)
6106 remove_window_handler (wp
);
6109 if (wp
== tip_window
)
6110 /* Neither WaitNextEvent nor ReceiveNextEvent receives `window
6111 closed' event. So we reset tip_window here. */
6114 free_frame_menubar (f
);
6116 if (FRAME_FACE_CACHE (f
))
6117 free_frame_faces (f
);
6121 if (FRAME_SIZE_HINTS (f
))
6122 xfree (FRAME_SIZE_HINTS (f
));
6124 xfree (f
->output_data
.mac
);
6125 f
->output_data
.mac
= NULL
;
6127 if (f
== dpyinfo
->x_focus_frame
)
6128 dpyinfo
->x_focus_frame
= 0;
6129 if (f
== dpyinfo
->x_focus_event_frame
)
6130 dpyinfo
->x_focus_event_frame
= 0;
6131 if (f
== dpyinfo
->x_highlight_frame
)
6132 dpyinfo
->x_highlight_frame
= 0;
6134 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6136 dpyinfo
->mouse_face_beg_row
6137 = dpyinfo
->mouse_face_beg_col
= -1;
6138 dpyinfo
->mouse_face_end_row
6139 = dpyinfo
->mouse_face_end_col
= -1;
6140 dpyinfo
->mouse_face_window
= Qnil
;
6141 dpyinfo
->mouse_face_deferred_gc
= 0;
6142 dpyinfo
->mouse_face_mouse_frame
= 0;
6149 /* Destroy the X window of frame F. */
6152 x_destroy_window (f
)
6155 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6157 x_free_frame_resources (f
);
6159 dpyinfo
->reference_count
--;
6163 /* Setting window manager hints. */
6165 /* Set the normal size hints for the window manager, for frame F.
6166 FLAGS is the flags word to use--or 0 meaning preserve the flags
6167 that the window now has.
6168 If USER_POSITION is nonzero, we set the USPosition
6169 flag (this is useful when FLAGS is 0). */
6171 x_wm_set_size_hint (f
, flags
, user_position
)
6176 int base_width
, base_height
, width_inc
, height_inc
;
6177 int min_rows
= 0, min_cols
= 0;
6178 XSizeHints
*size_hints
;
6180 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
6181 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
6182 width_inc
= FRAME_COLUMN_WIDTH (f
);
6183 height_inc
= FRAME_LINE_HEIGHT (f
);
6185 check_frame_size (f
, &min_rows
, &min_cols
);
6187 size_hints
= FRAME_SIZE_HINTS (f
);
6188 if (size_hints
== NULL
)
6190 size_hints
= FRAME_SIZE_HINTS (f
) = xmalloc (sizeof (XSizeHints
));
6191 bzero (size_hints
, sizeof (XSizeHints
));
6194 size_hints
->flags
|= PResizeInc
| PMinSize
| PBaseSize
;
6195 size_hints
->width_inc
= width_inc
;
6196 size_hints
->height_inc
= height_inc
;
6197 size_hints
->min_width
= base_width
+ min_cols
* width_inc
;
6198 size_hints
->min_height
= base_height
+ min_rows
* height_inc
;
6199 size_hints
->base_width
= base_width
;
6200 size_hints
->base_height
= base_height
;
6203 size_hints
->flags
= flags
;
6204 else if (user_position
)
6206 size_hints
->flags
&= ~ PPosition
;
6207 size_hints
->flags
|= USPosition
;
6211 #if 0 /* MAC_TODO: hide application instead of iconify? */
6212 /* Used for IconicState or NormalState */
6215 x_wm_set_window_state (f
, state
)
6219 #ifdef USE_X_TOOLKIT
6222 XtSetArg (al
[0], XtNinitialState
, state
);
6223 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6224 #else /* not USE_X_TOOLKIT */
6225 Window window
= FRAME_X_WINDOW (f
);
6227 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
6228 f
->output_data
.x
->wm_hints
.initial_state
= state
;
6230 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6231 #endif /* not USE_X_TOOLKIT */
6235 x_wm_set_icon_pixmap (f
, pixmap_id
)
6241 #ifndef USE_X_TOOLKIT
6242 Window window
= FRAME_X_WINDOW (f
);
6247 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
6248 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
6252 /* It seems there is no way to turn off use of an icon pixmap.
6253 The following line does it, only if no icon has yet been created,
6254 for some window managers. But with mwm it crashes.
6255 Some people say it should clear the IconPixmapHint bit in this case,
6256 but that doesn't work, and the X consortium said it isn't the
6257 right thing at all. Since there is no way to win,
6258 best to explicitly give up. */
6260 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
6266 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
6270 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
6271 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6274 #else /* not USE_X_TOOLKIT */
6276 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
6277 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6279 #endif /* not USE_X_TOOLKIT */
6282 #endif /* MAC_TODO */
6285 x_wm_set_icon_position (f
, icon_x
, icon_y
)
6289 #if 0 /* MAC_TODO: no icons on Mac */
6290 #ifdef USE_X_TOOLKIT
6291 Window window
= XtWindow (f
->output_data
.x
->widget
);
6293 Window window
= FRAME_X_WINDOW (f
);
6296 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
6297 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
6298 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
6300 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6301 #endif /* MAC_TODO */
6305 /***********************************************************************
6307 ***********************************************************************/
6309 /* An XLFD pattern is divided into blocks delimited by '*'. This
6310 structure holds information for each block. */
6311 struct xlfdpat_block
6313 /* Length of the pattern string in this block. Non-zero except for
6314 the first and the last blocks. */
6317 /* Pattern string except the last character in this block. The last
6318 character is replaced with NUL in order to use it as a
6320 unsigned char *pattern
;
6322 /* Last character of the pattern string. Must not be '?'. */
6323 unsigned char last_char
;
6325 /* One of the tables for the Boyer-Moore string search. It
6326 specifies the number of positions to proceed for each character
6327 with which the match fails. */
6330 /* The skip value for the last character in the above `skip' is
6331 assigned to `infinity' in order to simplify a loop condition.
6332 The original value is saved here. */
6338 /* Normalized pattern string. "Normalized" means that capital
6339 letters are lowered, blocks are not empty except the first and
6340 the last ones, and trailing '?'s in a block that is not the last
6341 one are moved to the next one. The last character in each block
6342 is replaced with NUL. */
6345 /* Number of characters except '*'s and trailing '?'s in the
6346 normalized pattern string. */
6349 /* Number of trailing '?'s in the normalized pattern string. */
6350 int trailing_anychars
;
6352 /* Number of blocks and information for each block. The latter is
6353 NULL if the pattern is exact (no '*' or '?' in it). */
6355 struct xlfdpat_block
*blocks
;
6359 xlfdpat_destroy (pat
)
6360 struct xlfdpat
*pat
;
6367 xfree (pat
->blocks
);
6374 static struct xlfdpat
*
6375 xlfdpat_create (pattern
)
6378 struct xlfdpat
*pat
;
6379 int nblocks
, i
, skip
;
6380 unsigned char last_char
, *p
, *q
, *anychar_head
;
6381 struct xlfdpat_block
*blk
;
6383 pat
= xmalloc (sizeof (struct xlfdpat
));
6387 pat
->buf
= xmalloc (strlen (pattern
) + 1);
6388 if (pat
->buf
== NULL
)
6391 /* Normalize the pattern string and store it to `pat->buf'. */
6393 anychar_head
= NULL
;
6396 for (p
= pattern
; *p
; p
++)
6398 unsigned char c
= *p
;
6401 if (last_char
== '*')
6402 /* ...a** -> ...a* */
6406 if (last_char
== '?')
6407 if (anychar_head
> pat
->buf
&& *(anychar_head
- 1) == '*')
6408 /* ...*??* -> ...*?? */
6411 /* ...a??* -> ...a*?? */
6413 *anychar_head
++ = '*';
6420 if (last_char
!= '?')
6424 /* On Mac OS X 10.3, tolower also converts non-ASCII
6425 characters for some locales. */
6429 *q
++ = last_char
= c
;
6433 pat
->nblocks
= nblocks
;
6434 if (last_char
!= '?')
6435 pat
->trailing_anychars
= 0;
6438 pat
->trailing_anychars
= q
- anychar_head
;
6441 pat
->nchars
= q
- pat
->buf
- (nblocks
- 1);
6443 if (anychar_head
== NULL
&& nblocks
== 1)
6445 /* The pattern is exact. */
6450 pat
->blocks
= xmalloc (sizeof (struct xlfdpat_block
) * nblocks
);
6451 if (pat
->blocks
== NULL
)
6454 /* Divide the normalized pattern into blocks. */
6456 for (blk
= pat
->blocks
; blk
< pat
->blocks
+ nblocks
- 1; blk
++)
6461 blk
->len
= p
- blk
->pattern
;
6465 blk
->len
= q
- blk
->pattern
;
6467 /* Setup a table for the Boyer-Moore string search. */
6468 for (blk
= pat
->blocks
; blk
< pat
->blocks
+ nblocks
; blk
++)
6471 blk
->last_char
= blk
->pattern
[blk
->len
- 1];
6472 blk
->pattern
[blk
->len
- 1] = '\0';
6474 for (skip
= 1; skip
< blk
->len
; skip
++)
6475 if (blk
->pattern
[blk
->len
- skip
- 1] == '?')
6478 for (i
= 0; i
< 256; i
++)
6479 blk
->skip
[i
] = skip
;
6481 p
= blk
->pattern
+ (blk
->len
- skip
);
6483 blk
->skip
[*p
++] = skip
;
6485 blk
->last_char_skip
= blk
->skip
[blk
->last_char
];
6491 xlfdpat_destroy (pat
);
6496 xlfdpat_exact_p (pat
)
6497 struct xlfdpat
*pat
;
6499 return pat
->blocks
== NULL
;
6502 /* Return the first string in STRING + 0, ..., STRING + START_MAX such
6503 that the pattern in *BLK matches with its prefix. Return NULL
6504 there is no such strings. STRING must be lowered in advance. */
6507 xlfdpat_block_match_1 (blk
, string
, start_max
)
6508 struct xlfdpat_block
*blk
;
6509 unsigned char *string
;
6512 int start
, infinity
;
6513 unsigned char *p
, *s
;
6515 xassert (blk
->len
> 0);
6516 xassert (start_max
+ blk
->len
<= strlen (string
));
6517 xassert (blk
->last_char
!= '?');
6519 /* See the comments in the function `boyer_moore' (search.c) for the
6520 use of `infinity'. */
6521 infinity
= start_max
+ blk
->len
+ 1;
6522 blk
->skip
[blk
->last_char
] = infinity
;
6527 /* Check the last character of the pattern. */
6528 s
= string
+ blk
->len
- 1;
6531 start
+= blk
->skip
[*(s
+ start
)];
6533 while (start
<= start_max
);
6535 if (start
< infinity
)
6536 /* Couldn't find the last character. */
6539 /* No less than `infinity' means we could find the last
6540 character at `s[start - infinity]'. */
6543 /* Check the remaining characters. We prefer making no-'?'
6544 cases faster because the use of '?' is really rare. */
6549 while (*p
++ == *s
++)
6552 while (*(p
- 1) == '?');
6554 if (*(p
- 1) == '\0')
6556 return string
+ start
;
6559 start
+= blk
->last_char_skip
;
6561 while (start
<= start_max
);
6566 #define xlfdpat_block_match(b, s, m) \
6567 ((b)->len == 1 ? memchr ((s), (b)->last_char, (m) + 1) \
6568 : xlfdpat_block_match_1 (b, s, m))
6570 /* Check if XLFD pattern PAT, which is generated by `xfldpat_create',
6571 matches with STRING. STRING must be lowered in advance. */
6574 xlfdpat_match (pat
, string
)
6575 struct xlfdpat
*pat
;
6576 unsigned char *string
;
6578 int str_len
, nblocks
, i
, start_max
;
6579 struct xlfdpat_block
*blk
;
6582 xassert (pat
->nblocks
> 0);
6584 if (xlfdpat_exact_p (pat
))
6585 return strcmp (pat
->buf
, string
) == 0;
6587 /* The number of the characters in the string must not be smaller
6588 than that in the pattern. */
6589 str_len
= strlen (string
);
6590 if (str_len
< pat
->nchars
+ pat
->trailing_anychars
)
6593 /* Chop off the trailing '?'s. */
6594 str_len
-= pat
->trailing_anychars
;
6596 /* The last block. When it is non-empty, it must match at the end
6598 nblocks
= pat
->nblocks
;
6599 blk
= pat
->blocks
+ (nblocks
- 1);
6601 /* The last block is also the first one. */
6602 return (str_len
== blk
->len
6603 && (blk
->len
== 0 || xlfdpat_block_match (blk
, string
, 0)));
6604 else if (blk
->len
!= 0)
6605 if (!xlfdpat_block_match (blk
, string
+ (str_len
- blk
->len
), 0))
6608 /* The first block. When it is non-empty, it must match at the
6609 beginning of the string. */
6613 s
= xlfdpat_block_match (blk
, string
, 0);
6616 string
= s
+ blk
->len
;
6619 /* The rest of the blocks. */
6620 start_max
= str_len
- pat
->nchars
;
6621 for (i
= 1, blk
++; i
< nblocks
- 1; i
++, blk
++)
6623 s
= xlfdpat_block_match (blk
, string
, start_max
);
6626 start_max
-= s
- string
;
6627 string
= s
+ blk
->len
;
6634 /***********************************************************************
6636 ***********************************************************************/
6638 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6641 x_get_font_info (f
, font_idx
)
6645 return (FRAME_MAC_FONT_TABLE (f
) + font_idx
);
6648 /* the global font name table */
6649 static char **font_name_table
= NULL
;
6650 static int font_name_table_size
= 0;
6651 static int font_name_count
= 0;
6653 /* Alist linking font family names to Font Manager font family
6654 references (which can also be used as QuickDraw font IDs). We use
6655 an alist because hash tables are not ready when the terminal frame
6656 for Mac OS Classic is created. */
6657 static Lisp_Object fm_font_family_alist
;
6659 /* Hash table linking font family names to ATSU font IDs. */
6660 static Lisp_Object atsu_font_id_hash
;
6663 /* Alist linking character set strings to Mac text encoding and Emacs
6665 static Lisp_Object Vmac_charset_info_alist
;
6668 create_text_encoding_info_alist ()
6670 Lisp_Object result
= Qnil
, rest
;
6672 for (rest
= Vmac_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
6674 Lisp_Object charset_info
= XCAR (rest
);
6675 Lisp_Object charset
, coding_system
, text_encoding
;
6676 Lisp_Object existing_info
;
6678 if (!(CONSP (charset_info
)
6679 && STRINGP (charset
= XCAR (charset_info
))
6680 && CONSP (XCDR (charset_info
))
6681 && INTEGERP (text_encoding
= XCAR (XCDR (charset_info
)))
6682 && CONSP (XCDR (XCDR (charset_info
)))
6683 && SYMBOLP (coding_system
= XCAR (XCDR (XCDR (charset_info
))))))
6686 existing_info
= assq_no_quit (text_encoding
, result
);
6687 if (NILP (existing_info
))
6688 result
= Fcons (list3 (text_encoding
, coding_system
, charset
),
6691 if (NILP (Fmember (charset
, XCDR (XCDR (existing_info
)))))
6692 XSETCDR (XCDR (existing_info
),
6693 Fcons (charset
, XCDR (XCDR (existing_info
))));
6701 decode_mac_font_name (name
, size
, coding_system
)
6704 Lisp_Object coding_system
;
6706 struct coding_system coding
;
6709 if (!NILP (coding_system
) && !NILP (Fcoding_system_p (coding_system
)))
6711 for (p
= name
; *p
; p
++)
6712 if (!isascii (*p
) || iscntrl (*p
))
6717 setup_coding_system (coding_system
, &coding
);
6718 coding
.src_multibyte
= 0;
6719 coding
.dst_multibyte
= 1;
6720 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6721 coding
.composing
= COMPOSITION_DISABLED
;
6722 buf
= (char *) alloca (size
);
6724 decode_coding (&coding
, name
, buf
, strlen (name
), size
- 1);
6725 bcopy (buf
, name
, coding
.produced
);
6726 name
[coding
.produced
] = '\0';
6730 /* If there's just one occurrence of '-' in the family name, it is
6731 replaced with '_'. (More than one occurrence of '-' means a
6732 "FOUNDRY-FAMILY-CHARSET"-style name.) */
6733 p
= strchr (name
, '-');
6734 if (p
&& strchr (p
+ 1, '-') == NULL
)
6737 for (p
= name
; *p
; p
++)
6738 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
6739 for some locales. */
6746 mac_to_x_fontname (name
, size
, style
, charset
)
6754 char xf
[256], *result
;
6757 if (sscanf (name
, "%31[^-]-%255[^-]-%31s", foundry
, family
, cs
) == 3)
6761 strcpy(foundry
, "Apple");
6762 strcpy(family
, name
);
6765 sprintf (xf
, "%s-%c-normal--%d-%d-%d-%d-m-%d-%s",
6766 style
& bold
? "bold" : "medium", style
& italic
? 'i' : 'r',
6767 size
, size
* 10, size
? 72 : 0, size
? 72 : 0, size
* 10, charset
);
6769 result
= xmalloc (strlen (foundry
) + strlen (family
) + strlen (xf
) + 3 + 1);
6770 sprintf (result
, "-%s-%s-%s", foundry
, family
, xf
);
6771 for (p
= result
; *p
; p
++)
6772 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
6773 for some locales. */
6780 /* Parse fully-specified and instantiated X11 font spec XF, and store
6781 the results to FAMILY, *SIZE, *STYLE, and CHARSET. Return 1 if the
6782 parsing succeeded, and 0 otherwise. For FAMILY and CHARSET, the
6783 caller must allocate at least 256 and 32 bytes respectively. For
6784 ordinary Mac fonts, the value stored to FAMILY should just be their
6785 names, like "monaco", "Taipei", etc. Fonts converted from the GNU
6786 intlfonts collection contain their charset designation in their
6787 names, like "ETL-Fixed-iso8859-1", "ETL-Fixed-koi8-r", etc. Both
6788 types of font names are handled accordingly. */
6790 const int kDefaultFontSize
= 12;
6793 parse_x_font_name (xf
, family
, size
, style
, charset
)
6799 Str31 foundry
, weight
;
6800 int point_size
, avgwidth
;
6803 if (sscanf (xf
, "-%31[^-]-%255[^-]-%31[^-]-%1[^-]-%*[^-]-%*[^-]-%d-%d-%*[^-]-%*[^-]-%*c-%d-%31s",
6804 foundry
, family
, weight
, slant
, size
,
6805 &point_size
, &avgwidth
, charset
) != 8
6806 && sscanf (xf
, "-%31[^-]-%255[^-]-%31[^-]-%1[^-]-%*[^-]--%d-%d-%*[^-]-%*[^-]-%*c-%d-%31s",
6807 foundry
, family
, weight
, slant
, size
,
6808 &point_size
, &avgwidth
, charset
) != 8)
6814 *size
= point_size
/ 10;
6815 else if (avgwidth
> 0)
6816 *size
= avgwidth
/ 10;
6819 *size
= kDefaultFontSize
;
6822 if (strcmp (weight
, "bold") == 0)
6827 if (NILP (Fassoc (build_string (charset
), Vmac_charset_info_alist
)))
6829 int foundry_len
= strlen (foundry
), family_len
= strlen (family
);
6831 if (foundry_len
+ family_len
+ strlen (charset
) + 2 < sizeof (Str255
))
6833 /* Like sprintf (family, "%s-%s-%s", foundry, family, charset),
6834 but take overlap into account. */
6835 memmove (family
+ foundry_len
+ 1, family
, family_len
);
6836 memcpy (family
, foundry
, foundry_len
);
6837 family
[foundry_len
] = '-';
6838 family
[foundry_len
+ 1 + family_len
] = '-';
6839 strcpy (family
+ foundry_len
+ 1 + family_len
+ 1, charset
);
6845 for (p
= family
; *p
; p
++)
6846 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
6847 for some locales. */
6856 add_font_name_table_entry (char *font_name
)
6858 if (font_name_table_size
== 0)
6860 font_name_table_size
= 256;
6861 font_name_table
= (char **)
6862 xmalloc (font_name_table_size
* sizeof (char *));
6864 else if (font_name_count
+ 1 >= font_name_table_size
)
6866 font_name_table_size
*= 2;
6867 font_name_table
= (char **)
6868 xrealloc (font_name_table
,
6869 font_name_table_size
* sizeof (char *));
6872 font_name_table
[font_name_count
++] = font_name
;
6875 /* Sets up the table font_name_table to contain the list of all fonts
6876 in the system the first time the table is used so that the Resource
6877 Manager need not be accessed every time this information is
6881 init_font_name_table ()
6883 #if TARGET_API_MAC_CARBON
6884 FMFontFamilyIterator ffi
;
6885 FMFontFamilyInstanceIterator ffii
;
6887 Lisp_Object text_encoding_info_alist
;
6888 struct gcpro gcpro1
;
6890 text_encoding_info_alist
= create_text_encoding_info_alist ();
6893 #if USE_CG_TEXT_DRAWING
6894 init_cg_text_anti_aliasing_threshold ();
6896 if (!NILP (assq_no_quit (make_number (kTextEncodingMacUnicode
),
6897 text_encoding_info_alist
)))
6900 ItemCount nfonts
, i
;
6901 ATSUFontID
*font_ids
= NULL
;
6902 Ptr name
, prev_name
= NULL
;
6906 make_hash_table (Qequal
, make_number (DEFAULT_HASH_SIZE
),
6907 make_float (DEFAULT_REHASH_SIZE
),
6908 make_float (DEFAULT_REHASH_THRESHOLD
),
6910 err
= ATSUFontCount (&nfonts
);
6912 font_ids
= xmalloc (sizeof (ATSUFontID
) * nfonts
);
6914 err
= ATSUGetFontIDs (font_ids
, nfonts
, NULL
);
6916 for (i
= 0; i
< nfonts
; i
++)
6918 err
= ATSUFindFontName (font_ids
[i
], kFontFamilyName
,
6919 kFontMacintoshPlatform
, kFontNoScript
,
6920 kFontNoLanguage
, 0, NULL
, &name_len
, NULL
);
6923 name
= xmalloc (name_len
+ 1);
6926 name
[name_len
] = '\0';
6927 err
= ATSUFindFontName (font_ids
[i
], kFontFamilyName
,
6928 kFontMacintoshPlatform
, kFontNoScript
,
6929 kFontNoLanguage
, name_len
, name
,
6932 decode_mac_font_name (name
, name_len
+ 1, Qnil
);
6935 && (prev_name
== NULL
6936 || strcmp (name
, prev_name
) != 0))
6938 static char *cs
= "iso10646-1";
6940 add_font_name_table_entry (mac_to_x_fontname (name
, 0,
6942 add_font_name_table_entry (mac_to_x_fontname (name
, 0,
6944 add_font_name_table_entry (mac_to_x_fontname (name
, 0,
6946 add_font_name_table_entry (mac_to_x_fontname (name
, 0,
6947 italic
| bold
, cs
));
6948 Fputhash (make_unibyte_string (name
, name_len
),
6949 long_to_cons (font_ids
[i
]), atsu_font_id_hash
);
6963 /* Create a dummy instance iterator here to avoid creating and
6964 destroying it in the loop. */
6965 if (FMCreateFontFamilyInstanceIterator (0, &ffii
) != noErr
)
6967 /* Create an iterator to enumerate the font families. */
6968 if (FMCreateFontFamilyIterator (NULL
, NULL
, kFMDefaultOptions
, &ffi
)
6971 FMDisposeFontFamilyInstanceIterator (&ffii
);
6975 GCPRO1 (text_encoding_info_alist
);
6977 while (FMGetNextFontFamily (&ffi
, &ff
) == noErr
)
6983 TextEncoding encoding
;
6984 TextEncodingBase sc
;
6985 Lisp_Object text_encoding_info
;
6987 if (FMGetFontFamilyName (ff
, name
) != noErr
)
6993 if (FMGetFontFamilyTextEncoding (ff
, &encoding
) != noErr
)
6995 sc
= GetTextEncodingBase (encoding
);
6996 text_encoding_info
= assq_no_quit (make_number (sc
),
6997 text_encoding_info_alist
);
6998 if (NILP (text_encoding_info
))
6999 text_encoding_info
= assq_no_quit (make_number (kTextEncodingMacRoman
),
7000 text_encoding_info_alist
);
7001 decode_mac_font_name (name
, sizeof (name
),
7002 XCAR (XCDR (text_encoding_info
)));
7003 fm_font_family_alist
= Fcons (Fcons (build_string (name
),
7005 fm_font_family_alist
);
7007 /* Point the instance iterator at the current font family. */
7008 if (FMResetFontFamilyInstanceIterator (ff
, &ffii
) != noErr
)
7011 while (FMGetNextFontFamilyInstance (&ffii
, &font
, &style
, &size
)
7014 Lisp_Object rest
= XCDR (XCDR (text_encoding_info
));
7016 if (size
> 0 || style
== normal
)
7017 for (; !NILP (rest
); rest
= XCDR (rest
))
7019 char *cs
= SDATA (XCAR (rest
));
7023 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
7025 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
7027 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
7029 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
7035 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
7044 /* Dispose of the iterators. */
7045 FMDisposeFontFamilyIterator (&ffi
);
7046 FMDisposeFontFamilyInstanceIterator (&ffii
);
7047 #else /* !TARGET_API_MAC_CARBON */
7049 SInt16 fontnum
, old_fontnum
;
7050 int num_mac_fonts
= CountResources('FOND');
7052 Handle font_handle
, font_handle_2
;
7053 short id
, scriptcode
;
7056 struct FontAssoc
*fat
;
7057 struct AsscEntry
*assc_entry
;
7058 Lisp_Object text_encoding_info_alist
, text_encoding_info
;
7059 struct gcpro gcpro1
;
7061 GetPort (&port
); /* save the current font number used */
7062 old_fontnum
= port
->txFont
;
7064 text_encoding_info_alist
= create_text_encoding_info_alist ();
7066 GCPRO1 (text_encoding_info_alist
);
7068 for (i
= 1; i
<= num_mac_fonts
; i
++) /* get all available fonts */
7070 font_handle
= GetIndResource ('FOND', i
);
7074 GetResInfo (font_handle
, &id
, &type
, name
);
7075 GetFNum (name
, &fontnum
);
7081 scriptcode
= FontToScript (fontnum
);
7082 text_encoding_info
= assq_no_quit (make_number (scriptcode
),
7083 text_encoding_info_alist
);
7084 if (NILP (text_encoding_info
))
7085 text_encoding_info
= assq_no_quit (make_number (smRoman
),
7086 text_encoding_info_alist
);
7087 decode_mac_font_name (name
, sizeof (name
),
7088 XCAR (XCDR (text_encoding_info
)));
7089 fm_font_family_alist
= Fcons (Fcons (build_string (name
),
7090 make_number (fontnum
)),
7091 fm_font_family_alist
);
7094 HLock (font_handle
);
7096 if (GetResourceSizeOnDisk (font_handle
)
7097 >= sizeof (struct FamRec
))
7099 fat
= (struct FontAssoc
*) (*font_handle
7100 + sizeof (struct FamRec
));
7102 = (struct AsscEntry
*) (*font_handle
7103 + sizeof (struct FamRec
)
7104 + sizeof (struct FontAssoc
));
7106 for (j
= 0; j
<= fat
->numAssoc
; j
++, assc_entry
++)
7108 Lisp_Object rest
= XCDR (XCDR (text_encoding_info
));
7110 for (; !NILP (rest
); rest
= XCDR (rest
))
7112 char *cs
= SDATA (XCAR (rest
));
7114 add_font_name_table_entry (mac_to_x_fontname (name
,
7115 assc_entry
->fontSize
,
7116 assc_entry
->fontStyle
,
7122 HUnlock (font_handle
);
7123 font_handle_2
= GetNextFOND (font_handle
);
7124 ReleaseResource (font_handle
);
7125 font_handle
= font_handle_2
;
7127 while (ResError () == noErr
&& font_handle
);
7132 TextFont (old_fontnum
);
7133 #endif /* !TARGET_API_MAC_CARBON */
7138 mac_clear_font_name_table ()
7142 for (i
= 0; i
< font_name_count
; i
++)
7143 xfree (font_name_table
[i
]);
7144 xfree (font_name_table
);
7145 font_name_table
= NULL
;
7146 font_name_table_size
= font_name_count
= 0;
7147 fm_font_family_alist
= Qnil
;
7151 enum xlfd_scalable_field_index
7153 XLFD_SCL_PIXEL_SIZE
,
7154 XLFD_SCL_POINT_SIZE
,
7159 static int xlfd_scalable_fields
[] =
7168 mac_do_list_fonts (pattern
, maxnames
)
7173 Lisp_Object font_list
= Qnil
;
7174 struct xlfdpat
*pat
;
7176 int scl_val
[XLFD_SCL_LAST
], *field
, *val
;
7179 if (font_name_table
== NULL
) /* Initialize when first used. */
7180 init_font_name_table ();
7182 for (i
= 0; i
< XLFD_SCL_LAST
; i
++)
7185 /* If the pattern contains 14 dashes and one of PIXEL_SIZE,
7186 POINT_SIZE, and AVGWIDTH fields is explicitly specified, scalable
7187 fonts are scaled according to the specified size. */
7190 field
= xlfd_scalable_fields
;
7198 if ('0' <= *ptr
&& *ptr
<= '9')
7200 *val
= *ptr
++ - '0';
7201 while ('0' <= *ptr
&& *ptr
<= '9' && *val
< 10000)
7202 *val
= *val
* 10 + *ptr
++ - '0';
7209 ptr
= strchr (ptr
, '-');
7212 while (ptr
&& i
< 14);
7214 if (i
== 14 && ptr
== NULL
)
7216 if (scl_val
[XLFD_SCL_PIXEL_SIZE
] < 0)
7217 scl_val
[XLFD_SCL_PIXEL_SIZE
] =
7218 (scl_val
[XLFD_SCL_POINT_SIZE
] > 0 ? scl_val
[XLFD_SCL_POINT_SIZE
] / 10
7219 : (scl_val
[XLFD_SCL_AVGWIDTH
] > 0 ? scl_val
[XLFD_SCL_AVGWIDTH
] / 10
7221 if (scl_val
[XLFD_SCL_POINT_SIZE
] < 0)
7222 scl_val
[XLFD_SCL_POINT_SIZE
] =
7223 (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0 ? scl_val
[XLFD_SCL_PIXEL_SIZE
] * 10
7224 : (scl_val
[XLFD_SCL_AVGWIDTH
] > 0 ? scl_val
[XLFD_SCL_AVGWIDTH
]
7226 if (scl_val
[XLFD_SCL_AVGWIDTH
] < 0)
7227 scl_val
[XLFD_SCL_AVGWIDTH
] =
7228 (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0 ? scl_val
[XLFD_SCL_PIXEL_SIZE
] * 10
7229 : (scl_val
[XLFD_SCL_POINT_SIZE
] > 0 ? scl_val
[XLFD_SCL_POINT_SIZE
]
7233 scl_val
[XLFD_SCL_PIXEL_SIZE
] = -1;
7235 pat
= xlfdpat_create (pattern
);
7239 exact
= xlfdpat_exact_p (pat
);
7241 for (i
= 0; i
< font_name_count
; i
++)
7243 if (xlfdpat_match (pat
, font_name_table
[i
]))
7245 font_list
= Fcons (build_string (font_name_table
[i
]), font_list
);
7246 if (exact
|| maxnames
> 0 && ++n_fonts
>= maxnames
)
7249 else if (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0
7250 && (ptr
= strstr (font_name_table
[i
], "-0-0-0-0-m-0-")))
7252 int former_len
= ptr
- font_name_table
[i
];
7254 scaled
= xmalloc (strlen (font_name_table
[i
]) + 20 + 1);
7257 memcpy (scaled
, font_name_table
[i
], former_len
);
7258 sprintf (scaled
+ former_len
,
7259 "-%d-%d-72-72-m-%d-%s",
7260 scl_val
[XLFD_SCL_PIXEL_SIZE
],
7261 scl_val
[XLFD_SCL_POINT_SIZE
],
7262 scl_val
[XLFD_SCL_AVGWIDTH
],
7263 ptr
+ sizeof ("-0-0-0-0-m-0-") - 1);
7265 if (xlfdpat_match (pat
, scaled
))
7267 font_list
= Fcons (build_string (scaled
), font_list
);
7269 if (exact
|| maxnames
> 0 && ++n_fonts
>= maxnames
)
7277 xlfdpat_destroy (pat
);
7282 /* Return a list of names of available fonts matching PATTERN on frame F.
7284 Frame F null means we have not yet created any frame on Mac, and
7285 consult the first display in x_display_list. MAXNAMES sets a limit
7286 on how many fonts to match. */
7289 x_list_fonts (f
, pattern
, size
, maxnames
)
7291 Lisp_Object pattern
;
7294 Lisp_Object list
= Qnil
, patterns
, tem
, key
;
7295 struct mac_display_info
*dpyinfo
7296 = f
? FRAME_MAC_DISPLAY_INFO (f
) : x_display_list
;
7298 xassert (size
<= 0);
7300 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
7301 if (NILP (patterns
))
7302 patterns
= Fcons (pattern
, Qnil
);
7304 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
7306 pattern
= XCAR (patterns
);
7308 if (!STRINGP (pattern
))
7311 tem
= XCAR (XCDR (dpyinfo
->name_list_element
));
7312 key
= Fcons (pattern
, make_number (maxnames
));
7314 list
= Fassoc (key
, tem
);
7317 list
= Fcdr_safe (list
);
7318 /* We have a cashed list. Don't have to get the list again. */
7323 list
= mac_do_list_fonts (SDATA (pattern
), maxnames
);
7326 /* MAC_TODO: add code for matching outline fonts here */
7328 /* Now store the result in the cache. */
7329 XSETCAR (XCDR (dpyinfo
->name_list_element
),
7330 Fcons (Fcons (key
, list
),
7331 XCAR (XCDR (dpyinfo
->name_list_element
))));
7334 if (NILP (list
)) continue; /* Try the remaining alternatives. */
7343 /* Check that FONT is valid on frame F. It is if it can be found in F's
7347 x_check_font (f
, font
)
7352 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7354 xassert (font
!= NULL
);
7356 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7357 if (dpyinfo
->font_table
[i
].name
7358 && font
== dpyinfo
->font_table
[i
].font
)
7361 xassert (i
< dpyinfo
->n_fonts
);
7364 #endif /* GLYPH_DEBUG != 0 */
7366 /* Set *W to the minimum width, *H to the minimum font height of FONT.
7367 Note: There are (broken) X fonts out there with invalid XFontStruct
7368 min_bounds contents. For example, handa@etl.go.jp reports that
7369 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
7370 have font->min_bounds.width == 0. */
7373 x_font_min_bounds (font
, w
, h
)
7374 MacFontStruct
*font
;
7377 *h
= FONT_HEIGHT (font
);
7378 *w
= font
->min_bounds
.width
;
7382 /* Compute the smallest character width and smallest font height over
7383 all fonts available on frame F. Set the members smallest_char_width
7384 and smallest_font_height in F's x_display_info structure to
7385 the values computed. Value is non-zero if smallest_font_height or
7386 smallest_char_width become smaller than they were before. */
7389 x_compute_min_glyph_bounds (f
)
7393 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7394 MacFontStruct
*font
;
7395 int old_width
= dpyinfo
->smallest_char_width
;
7396 int old_height
= dpyinfo
->smallest_font_height
;
7398 dpyinfo
->smallest_font_height
= 100000;
7399 dpyinfo
->smallest_char_width
= 100000;
7401 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
7402 if (dpyinfo
->font_table
[i
].name
)
7404 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
7407 font
= (MacFontStruct
*) fontp
->font
;
7408 xassert (font
!= (MacFontStruct
*) ~0);
7409 x_font_min_bounds (font
, &w
, &h
);
7411 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
7412 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
7415 xassert (dpyinfo
->smallest_char_width
> 0
7416 && dpyinfo
->smallest_font_height
> 0);
7418 return (dpyinfo
->n_fonts
== 1
7419 || dpyinfo
->smallest_char_width
< old_width
7420 || dpyinfo
->smallest_font_height
< old_height
);
7424 /* Determine whether given string is a fully-specified XLFD: all 14
7425 fields are present, none is '*'. */
7428 is_fully_specified_xlfd (char *p
)
7436 for (i
= 0; i
< 13; i
++)
7438 q
= strchr (p
+ 1, '-');
7441 if (q
- p
== 2 && *(p
+ 1) == '*')
7446 if (strchr (p
+ 1, '-') != NULL
)
7449 if (*(p
+ 1) == '*' && *(p
+ 2) == '\0')
7456 /* XLoadQueryFont creates and returns an internal representation for a
7457 font in a MacFontStruct struct. There is really no concept
7458 corresponding to "loading" a font on the Mac. But we check its
7459 existence and find the font number and all other information for it
7460 and store them in the returned MacFontStruct. */
7462 static MacFontStruct
*
7463 XLoadQueryFont (Display
*dpy
, char *fontname
)
7471 static ATSUFontID font_id
;
7472 ATSUStyle mac_style
= NULL
;
7475 #if TARGET_API_MAC_CARBON
7476 TextEncoding encoding
;
7481 MacFontStruct
*font
;
7482 XCharStruct
*space_bounds
= NULL
, *pcm
;
7484 if (is_fully_specified_xlfd (fontname
))
7488 Lisp_Object matched_fonts
;
7490 matched_fonts
= mac_do_list_fonts (fontname
, 1);
7491 if (NILP (matched_fonts
))
7493 name
= SDATA (XCAR (matched_fonts
));
7496 if (parse_x_font_name (name
, family
, &size
, &fontface
, charset
) == 0)
7500 if (strcmp (charset
, "iso10646-1") == 0) /* XXX */
7503 ATSUAttributeTag tags
[] = {kATSUFontTag
, kATSUSizeTag
,
7504 kATSUQDBoldfaceTag
, kATSUQDItalicTag
};
7505 ByteCount sizes
[] = {sizeof (ATSUFontID
), sizeof (Fixed
),
7506 sizeof (Boolean
), sizeof (Boolean
)};
7507 static Fixed size_fixed
;
7508 static Boolean bold_p
, italic_p
;
7509 ATSUAttributeValuePtr values
[] = {&font_id
, &size_fixed
,
7510 &bold_p
, &italic_p
};
7511 ATSUFontFeatureType types
[] = {kAllTypographicFeaturesType
};
7512 ATSUFontFeatureSelector selectors
[] = {kAllTypeFeaturesOffSelector
};
7513 Lisp_Object font_id_cons
;
7515 font_id_cons
= Fgethash (make_unibyte_string (family
, strlen (family
)),
7516 atsu_font_id_hash
, Qnil
);
7517 if (NILP (font_id_cons
))
7519 font_id
= cons_to_long (font_id_cons
);
7520 size_fixed
= Long2Fix (size
);
7521 bold_p
= (fontface
& bold
) != 0;
7522 italic_p
= (fontface
& italic
) != 0;
7523 err
= ATSUCreateStyle (&mac_style
);
7526 err
= ATSUSetFontFeatures (mac_style
, sizeof (types
) / sizeof (types
[0]),
7530 err
= ATSUSetAttributes (mac_style
, sizeof (tags
) / sizeof (tags
[0]),
7531 tags
, sizes
, values
);
7533 scriptcode
= kTextEncodingMacUnicode
;
7538 Lisp_Object tmp
= Fassoc (build_string (family
), fm_font_family_alist
);
7542 fontnum
= XINT (XCDR (tmp
));
7543 #if TARGET_API_MAC_CARBON
7544 if (FMGetFontFamilyTextEncoding (fontnum
, &encoding
) != noErr
)
7546 scriptcode
= GetTextEncodingBase (encoding
);
7548 scriptcode
= FontToScript (fontnum
);
7552 font
= (MacFontStruct
*) xmalloc (sizeof (struct MacFontStruct
));
7554 font
->mac_fontnum
= fontnum
;
7555 font
->mac_fontsize
= size
;
7556 font
->mac_fontface
= fontface
;
7557 font
->mac_scriptcode
= scriptcode
;
7559 font
->mac_style
= mac_style
;
7560 #if USE_CG_TEXT_DRAWING
7561 font
->cg_font
= NULL
;
7562 font
->cg_glyphs
= NULL
;
7566 /* Apple Japanese (SJIS) font is listed as both
7567 "*-jisx0208.1983-sjis" (Japanese script) and "*-jisx0201.1976-0"
7568 (Roman script) in init_font_name_table (). The latter should be
7569 treated as a one-byte font. */
7570 if (scriptcode
== smJapanese
&& strcmp (charset
, "jisx0201.1976-0") == 0)
7571 font
->mac_scriptcode
= smRoman
;
7573 font
->full_name
= mac_to_x_fontname (family
, size
, fontface
, charset
);
7576 if (font
->mac_style
)
7581 font
->min_byte1
= 0;
7582 font
->max_byte1
= 0xff;
7583 font
->min_char_or_byte2
= 0;
7584 font
->max_char_or_byte2
= 0xff;
7586 font
->bounds
.rows
= xmalloc (sizeof (XCharStructRow
*) * 0x100);
7587 if (font
->bounds
.rows
== NULL
)
7589 mac_unload_font (&one_mac_display_info
, font
);
7592 bzero (font
->bounds
.rows
, sizeof (XCharStructRow
*) * 0x100);
7593 font
->bounds
.rows
[0] = xmalloc (sizeof (XCharStructRow
));
7594 if (font
->bounds
.rows
[0] == NULL
)
7596 mac_unload_font (&one_mac_display_info
, font
);
7599 bzero (font
->bounds
.rows
[0], sizeof (XCharStructRow
));
7601 #if USE_CG_TEXT_DRAWING
7603 FMFontFamily font_family
;
7605 ATSFontRef ats_font
;
7607 err
= FMGetFontFamilyInstanceFromFont (font_id
, &font_family
, &style
);
7609 err
= FMGetFontFromFontFamilyInstance (font_family
, fontface
,
7611 /* Use CG text drawing if italic/bold is not synthesized. */
7612 if (err
== noErr
&& style
== fontface
)
7614 ats_font
= FMGetATSFontRefFromFont (font_id
);
7615 font
->cg_font
= CGFontCreateWithPlatformFont (&ats_font
);
7620 font
->cg_glyphs
= xmalloc (sizeof (CGGlyph
) * 0x100);
7621 if (font
->cg_glyphs
)
7622 bzero (font
->cg_glyphs
, sizeof (CGGlyph
) * 0x100);
7624 space_bounds
= font
->bounds
.rows
[0]->per_char
+ 0x20;
7625 err
= mac_query_char_extents (font
->mac_style
, 0x20,
7626 &font
->ascent
, &font
->descent
,
7628 #if USE_CG_TEXT_DRAWING
7629 (font
->cg_glyphs
? font
->cg_glyphs
+ 0x20
7637 mac_unload_font (&one_mac_display_info
, font
);
7640 XCHARSTRUCTROW_SET_CHAR_VALID (font
->bounds
.rows
[0], 0x20);
7642 pcm
= font
->bounds
.rows
[0]->per_char
;
7643 for (c
= 0x21; c
<= 0xff; c
++)
7646 /* Soft hyphen is not supported in ATSUI. */
7654 mac_query_char_extents (font
->mac_style
, c
, NULL
, NULL
, pcm
+ c
,
7655 #if USE_CG_TEXT_DRAWING
7656 (font
->cg_glyphs
? font
->cg_glyphs
+ c
7662 XCHARSTRUCTROW_SET_CHAR_VALID (font
->bounds
.rows
[0], c
);
7664 #if USE_CG_TEXT_DRAWING
7665 if (font
->cg_glyphs
&& font
->cg_glyphs
[c
] == 0)
7667 /* Don't use CG text drawing if font substitution occurs in
7668 ASCII or Latin-1 characters. */
7669 CGFontRelease (font
->cg_font
);
7670 font
->cg_font
= NULL
;
7671 xfree (font
->cg_glyphs
);
7672 font
->cg_glyphs
= NULL
;
7681 SInt16 old_fontnum
, old_fontsize
;
7683 FontInfo the_fontinfo
;
7684 int is_two_byte_font
;
7686 /* Save the current font number used. */
7688 #if TARGET_API_MAC_CARBON
7689 old_fontnum
= GetPortTextFont (port
);
7690 old_fontsize
= GetPortTextSize (port
);
7691 old_fontface
= GetPortTextFace (port
);
7693 old_fontnum
= port
->txFont
;
7694 old_fontsize
= port
->txSize
;
7695 old_fontface
= port
->txFace
;
7700 TextFace (fontface
);
7702 GetFontInfo (&the_fontinfo
);
7704 font
->ascent
= the_fontinfo
.ascent
;
7705 font
->descent
= the_fontinfo
.descent
;
7707 is_two_byte_font
= (font
->mac_scriptcode
== smJapanese
7708 || font
->mac_scriptcode
== smTradChinese
7709 || font
->mac_scriptcode
== smSimpChinese
7710 || font
->mac_scriptcode
== smKorean
);
7712 if (is_two_byte_font
)
7716 font
->min_byte1
= 0xa1;
7717 font
->max_byte1
= 0xfe;
7718 font
->min_char_or_byte2
= 0xa1;
7719 font
->max_char_or_byte2
= 0xfe;
7721 /* Use the width of an "ideographic space" of that font
7722 because the_fontinfo.widMax returns the wrong width for
7724 switch (font
->mac_scriptcode
)
7727 font
->min_byte1
= 0x81;
7728 font
->max_byte1
= 0xfc;
7729 font
->min_char_or_byte2
= 0x40;
7730 font
->max_char_or_byte2
= 0xfc;
7731 char_width
= StringWidth("\p\x81\x40");
7734 font
->min_char_or_byte2
= 0x40;
7735 char_width
= StringWidth("\p\xa1\x40");
7738 char_width
= StringWidth("\p\xa1\xa1");
7741 char_width
= StringWidth("\p\xa1\xa1");
7745 font
->bounds
.per_char
= NULL
;
7747 if (fontface
& italic
)
7748 font
->max_bounds
.rbearing
= char_width
+ 1;
7750 font
->max_bounds
.rbearing
= char_width
;
7751 font
->max_bounds
.lbearing
= 0;
7752 font
->max_bounds
.width
= char_width
;
7753 font
->max_bounds
.ascent
= the_fontinfo
.ascent
;
7754 font
->max_bounds
.descent
= the_fontinfo
.descent
;
7756 font
->min_bounds
= font
->max_bounds
;
7762 font
->min_byte1
= font
->max_byte1
= 0;
7763 font
->min_char_or_byte2
= 0x20;
7764 font
->max_char_or_byte2
= 0xff;
7766 font
->bounds
.per_char
=
7767 xmalloc (sizeof (XCharStruct
) * (0xff - 0x20 + 1));
7768 if (font
->bounds
.per_char
== NULL
)
7770 mac_unload_font (&one_mac_display_info
, font
);
7773 bzero (font
->bounds
.per_char
,
7774 sizeof (XCharStruct
) * (0xff - 0x20 + 1));
7776 space_bounds
= font
->bounds
.per_char
;
7777 mac_query_char_extents (NULL
, 0x20, &font
->ascent
, &font
->descent
,
7778 space_bounds
, NULL
);
7780 for (c
= 0x21, pcm
= space_bounds
+ 1; c
<= 0xff; c
++, pcm
++)
7781 mac_query_char_extents (NULL
, c
, NULL
, NULL
, pcm
, NULL
);
7784 /* Restore previous font number, size and face. */
7785 TextFont (old_fontnum
);
7786 TextSize (old_fontsize
);
7787 TextFace (old_fontface
);
7794 font
->min_bounds
= font
->max_bounds
= *space_bounds
;
7795 for (c
= 0x21, pcm
= space_bounds
+ 1; c
<= 0x7f; c
++, pcm
++)
7798 font
->min_bounds
.lbearing
= min (font
->min_bounds
.lbearing
,
7800 font
->min_bounds
.rbearing
= min (font
->min_bounds
.rbearing
,
7802 font
->min_bounds
.width
= min (font
->min_bounds
.width
,
7804 font
->min_bounds
.ascent
= min (font
->min_bounds
.ascent
,
7807 font
->max_bounds
.lbearing
= max (font
->max_bounds
.lbearing
,
7809 font
->max_bounds
.rbearing
= max (font
->max_bounds
.rbearing
,
7811 font
->max_bounds
.width
= max (font
->max_bounds
.width
,
7813 font
->max_bounds
.ascent
= max (font
->max_bounds
.ascent
,
7818 font
->mac_style
== NULL
&&
7820 font
->max_bounds
.width
== font
->min_bounds
.width
7821 && font
->min_bounds
.lbearing
>= 0
7822 && font
->max_bounds
.rbearing
<= font
->max_bounds
.width
)
7824 /* Fixed width and no overhangs. */
7825 xfree (font
->bounds
.per_char
);
7826 font
->bounds
.per_char
= NULL
;
7830 #if !defined (MAC_OS8) || USE_ATSUI
7831 /* AppKit and WebKit do some adjustment to the heights of Courier,
7832 Helvetica, and Times. This only works on the environments where
7833 the XDrawImageString counterpart is never used. */
7834 if (strcmp (family
, "courier") == 0 || strcmp (family
, "helvetica") == 0
7835 || strcmp (family
, "times") == 0)
7836 font
->ascent
+= (font
->ascent
+ font
->descent
) * .15 + 0.5;
7844 mac_unload_font (dpyinfo
, font
)
7845 struct mac_display_info
*dpyinfo
;
7848 xfree (font
->full_name
);
7850 if (font
->mac_style
)
7854 for (i
= font
->min_byte1
; i
<= font
->max_byte1
; i
++)
7855 if (font
->bounds
.rows
[i
])
7856 xfree (font
->bounds
.rows
[i
]);
7857 xfree (font
->bounds
.rows
);
7858 ATSUDisposeStyle (font
->mac_style
);
7862 if (font
->bounds
.per_char
)
7863 xfree (font
->bounds
.per_char
);
7864 #if USE_CG_TEXT_DRAWING
7866 CGFontRelease (font
->cg_font
);
7867 if (font
->cg_glyphs
)
7868 xfree (font
->cg_glyphs
);
7874 /* Load font named FONTNAME of the size SIZE for frame F, and return a
7875 pointer to the structure font_info while allocating it dynamically.
7876 If SIZE is 0, load any size of font.
7877 If loading is failed, return NULL. */
7880 x_load_font (f
, fontname
, size
)
7882 register char *fontname
;
7885 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7886 Lisp_Object font_names
;
7888 /* Get a list of all the fonts that match this name. Once we
7889 have a list of matching fonts, we compare them against the fonts
7890 we already have by comparing names. */
7891 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
7893 if (!NILP (font_names
))
7898 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7899 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
7900 if (dpyinfo
->font_table
[i
].name
7901 && (!strcmp (dpyinfo
->font_table
[i
].name
,
7902 SDATA (XCAR (tail
)))
7903 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
7904 SDATA (XCAR (tail
)))))
7905 return (dpyinfo
->font_table
+ i
);
7910 /* Load the font and add it to the table. */
7913 struct MacFontStruct
*font
;
7914 struct font_info
*fontp
;
7915 unsigned long value
;
7918 fontname
= (char *) SDATA (XCAR (font_names
));
7921 font
= (MacFontStruct
*) XLoadQueryFont (FRAME_MAC_DISPLAY (f
), fontname
);
7926 /* Find a free slot in the font table. */
7927 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
7928 if (dpyinfo
->font_table
[i
].name
== NULL
)
7931 /* If no free slot found, maybe enlarge the font table. */
7932 if (i
== dpyinfo
->n_fonts
7933 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
7936 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
7937 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
7939 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
7942 fontp
= dpyinfo
->font_table
+ i
;
7943 if (i
== dpyinfo
->n_fonts
)
7946 /* Now fill in the slots of *FONTP. */
7948 bzero (fontp
, sizeof (*fontp
));
7950 fontp
->font_idx
= i
;
7951 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
7952 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
7954 if (font
->min_bounds
.width
== font
->max_bounds
.width
)
7956 /* Fixed width font. */
7957 fontp
->average_width
= fontp
->space_width
= font
->min_bounds
.width
;
7964 char2b
.byte1
= 0x00, char2b
.byte2
= 0x20;
7965 pcm
= mac_per_char_metric (font
, &char2b
, 0);
7967 fontp
->space_width
= pcm
->width
;
7969 fontp
->space_width
= FONT_WIDTH (font
);
7973 int width
= pcm
->width
;
7974 for (char2b
.byte2
= 33; char2b
.byte2
<= 126; char2b
.byte2
++)
7975 if ((pcm
= mac_per_char_metric (font
, &char2b
, 0)) != NULL
)
7976 width
+= pcm
->width
;
7977 fontp
->average_width
= width
/ 95;
7980 fontp
->average_width
= FONT_WIDTH (font
);
7983 fontp
->full_name
= (char *) xmalloc (strlen (font
->full_name
) + 1);
7984 bcopy (font
->full_name
, fontp
->full_name
, strlen (font
->full_name
) + 1);
7986 fontp
->size
= font
->max_bounds
.width
;
7987 fontp
->height
= FONT_HEIGHT (font
);
7989 /* For some font, ascent and descent in max_bounds field is
7990 larger than the above value. */
7991 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
7992 if (max_height
> fontp
->height
)
7993 fontp
->height
= max_height
;
7996 /* The slot `encoding' specifies how to map a character
7997 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
7998 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
7999 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
8000 2:0xA020..0xFF7F). For the moment, we don't know which charset
8001 uses this font. So, we set information in fontp->encoding[1]
8002 which is never used by any charset. If mapping can't be
8003 decided, set FONT_ENCODING_NOT_DECIDED. */
8004 if (font
->mac_scriptcode
== smJapanese
)
8005 fontp
->encoding
[1] = 4;
8009 = (font
->max_byte1
== 0
8011 ? (font
->min_char_or_byte2
< 0x80
8012 ? (font
->max_char_or_byte2
< 0x80
8013 ? 0 /* 0x20..0x7F */
8014 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
8015 : 1) /* 0xA0..0xFF */
8017 : (font
->min_byte1
< 0x80
8018 ? (font
->max_byte1
< 0x80
8019 ? (font
->min_char_or_byte2
< 0x80
8020 ? (font
->max_char_or_byte2
< 0x80
8021 ? 0 /* 0x2020..0x7F7F */
8022 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
8023 : 3) /* 0x20A0..0x7FFF */
8024 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
8025 : (font
->min_char_or_byte2
< 0x80
8026 ? (font
->max_char_or_byte2
< 0x80
8027 ? 2 /* 0xA020..0xFF7F */
8028 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
8029 : 1))); /* 0xA0A0..0xFFFF */
8032 #if 0 /* MAC_TODO: fill these out with more reasonably values */
8033 fontp
->baseline_offset
8034 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
8035 ? (long) value
: 0);
8036 fontp
->relative_compose
8037 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
8038 ? (long) value
: 0);
8039 fontp
->default_ascent
8040 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
8041 ? (long) value
: 0);
8043 fontp
->baseline_offset
= 0;
8044 fontp
->relative_compose
= 0;
8045 fontp
->default_ascent
= 0;
8048 /* Set global flag fonts_changed_p to non-zero if the font loaded
8049 has a character with a smaller width than any other character
8050 before, or if the font loaded has a smaller height than any
8051 other font loaded before. If this happens, it will make a
8052 glyph matrix reallocation necessary. */
8053 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
8060 /* Return a pointer to struct font_info of a font named FONTNAME for
8061 frame F. If no such font is loaded, return NULL. */
8064 x_query_font (f
, fontname
)
8066 register char *fontname
;
8068 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
8071 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
8072 if (dpyinfo
->font_table
[i
].name
8073 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
8074 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
8075 return (dpyinfo
->font_table
+ i
);
8080 /* Find a CCL program for a font specified by FONTP, and set the member
8081 `encoder' of the structure. */
8084 x_find_ccl_program (fontp
)
8085 struct font_info
*fontp
;
8087 Lisp_Object list
, elt
;
8089 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
8093 && STRINGP (XCAR (elt
))
8094 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
8100 struct ccl_program
*ccl
8101 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
8103 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
8106 fontp
->font_encoder
= ccl
;
8112 /* The Mac Event loop code */
8114 #if !TARGET_API_MAC_CARBON
8116 #include <Quickdraw.h>
8117 #include <Balloons.h>
8118 #include <Devices.h>
8120 #include <Gestalt.h>
8122 #include <Processes.h>
8124 #include <ToolUtils.h>
8125 #include <TextUtils.h>
8126 #include <Dialogs.h>
8129 #include <Resources.h>
8134 #endif /* ! TARGET_API_MAC_CARBON */
8139 #define WINDOW_RESOURCE 128
8140 #define TERM_WINDOW_RESOURCE 129
8142 #define DEFAULT_NUM_COLS 80
8144 #define MIN_DOC_SIZE 64
8145 #define MAX_DOC_SIZE 32767
8147 #define EXTRA_STACK_ALLOC (256 * 1024)
8149 #define ARGV_STRING_LIST_ID 129
8150 #define ABOUT_ALERT_ID 128
8151 #define RAM_TOO_LARGE_ALERT_ID 129
8153 /* Contains the string "reverse", which is a constant for mouse button emu.*/
8154 Lisp_Object Qreverse
;
8157 /* Modifier associated with the control key, or nil to ignore. */
8158 Lisp_Object Vmac_control_modifier
;
8160 /* Modifier associated with the option key, or nil to ignore. */
8161 Lisp_Object Vmac_option_modifier
;
8163 /* Modifier associated with the command key, or nil to ignore. */
8164 Lisp_Object Vmac_command_modifier
;
8166 /* Modifier associated with the function key, or nil to ignore. */
8167 Lisp_Object Vmac_function_modifier
;
8169 /* True if the option and command modifiers should be used to emulate
8170 a three button mouse */
8171 Lisp_Object Vmac_emulate_three_button_mouse
;
8173 #if USE_CARBON_EVENTS
8174 /* Non-zero if the mouse wheel button (i.e. button 4) should map to
8175 mouse-2, instead of mouse-3. */
8176 int mac_wheel_button_is_mouse_2
;
8178 /* If non-zero, the Mac "Command" key is passed on to the Mac Toolbox
8179 for processing before Emacs sees it. */
8180 int mac_pass_command_to_system
;
8182 /* If non-zero, the Mac "Control" key is passed on to the Mac Toolbox
8183 for processing before Emacs sees it. */
8184 int mac_pass_control_to_system
;
8187 /* Points to the variable `inev' in the function XTread_socket. It is
8188 used for passing an input event to the function back from
8189 Carbon/Apple event handlers. */
8190 static struct input_event
*read_socket_inev
= NULL
;
8192 Point saved_menu_event_location
;
8195 #if USE_CARBON_EVENTS
8196 static Lisp_Object Qhicommand
;
8198 extern int mac_ready_for_apple_events
;
8199 extern Lisp_Object Qundefined
;
8200 extern void init_apple_event_handler
P_ ((void));
8201 extern void mac_find_apple_event_spec
P_ ((AEEventClass
, AEEventID
,
8202 Lisp_Object
*, Lisp_Object
*,
8205 #if TARGET_API_MAC_CARBON
8207 static pascal OSErr
mac_do_track_drag (DragTrackingMessage
, WindowPtr
, void*, DragReference
);
8208 static pascal OSErr
mac_do_receive_drag (WindowPtr
, void*, DragReference
);
8209 static DragTrackingHandlerUPP mac_do_track_dragUPP
= NULL
;
8210 static DragReceiveHandlerUPP mac_do_receive_dragUPP
= NULL
;
8213 #if USE_CARBON_EVENTS
8215 extern void init_service_handler ();
8216 static Lisp_Object Qservices
, Qpaste
, Qperform
;
8218 /* Window Event Handler */
8219 static pascal OSStatus
mac_handle_window_event (EventHandlerCallRef
,
8222 OSErr
install_window_handler (WindowPtr
);
8224 extern void init_emacs_passwd_dir ();
8225 extern int emacs_main (int, char **, char **);
8227 extern void initialize_applescript();
8228 extern void terminate_applescript();
8231 #if USE_CARBON_EVENTS
8232 mac_to_emacs_modifiers (UInt32 mods
)
8234 mac_to_emacs_modifiers (EventModifiers mods
)
8237 unsigned int result
= 0;
8238 if (mods
& shiftKey
)
8239 result
|= shift_modifier
;
8241 /* Deactivated to simplify configuration:
8242 if Vmac_option_modifier is non-NIL, we fully process the Option
8243 key. Otherwise, we only process it if an additional Ctrl or Command
8244 is pressed. That way the system may convert the character to a
8246 if ((mods & optionKey) &&
8247 (( !NILP(Vmac_option_modifier) ||
8248 ((mods & cmdKey) || (mods & controlKey))))) */
8250 if (!NILP (Vmac_option_modifier
) && (mods
& optionKey
)) {
8251 Lisp_Object val
= Fget(Vmac_option_modifier
, Qmodifier_value
);
8253 result
|= XUINT(val
);
8255 if (!NILP (Vmac_command_modifier
) && (mods
& cmdKey
)) {
8256 Lisp_Object val
= Fget(Vmac_command_modifier
, Qmodifier_value
);
8258 result
|= XUINT(val
);
8260 if (!NILP (Vmac_control_modifier
) && (mods
& controlKey
)) {
8261 Lisp_Object val
= Fget(Vmac_control_modifier
, Qmodifier_value
);
8263 result
|= XUINT(val
);
8267 if (!NILP (Vmac_function_modifier
) && (mods
& kEventKeyModifierFnMask
)) {
8268 Lisp_Object val
= Fget(Vmac_function_modifier
, Qmodifier_value
);
8270 result
|= XUINT(val
);
8278 mac_get_emulated_btn ( UInt32 modifiers
)
8281 if (!NILP (Vmac_emulate_three_button_mouse
)) {
8282 int cmdIs3
= !EQ (Vmac_emulate_three_button_mouse
, Qreverse
);
8283 if (modifiers
& cmdKey
)
8284 result
= cmdIs3
? 2 : 1;
8285 else if (modifiers
& optionKey
)
8286 result
= cmdIs3
? 1 : 2;
8291 #if USE_CARBON_EVENTS
8292 /* Obtains the event modifiers from the event ref and then calls
8293 mac_to_emacs_modifiers. */
8295 mac_event_to_emacs_modifiers (EventRef eventRef
)
8298 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
8299 sizeof (UInt32
), NULL
, &mods
);
8300 if (!NILP (Vmac_emulate_three_button_mouse
) &&
8301 GetEventClass(eventRef
) == kEventClassMouse
)
8303 mods
&= ~(optionKey
| cmdKey
);
8305 return mac_to_emacs_modifiers (mods
);
8308 /* Given an event ref, return the code to use for the mouse button
8309 code in the emacs input_event. */
8311 mac_get_mouse_btn (EventRef ref
)
8313 EventMouseButton result
= kEventMouseButtonPrimary
;
8314 GetEventParameter (ref
, kEventParamMouseButton
, typeMouseButton
, NULL
,
8315 sizeof (EventMouseButton
), NULL
, &result
);
8318 case kEventMouseButtonPrimary
:
8319 if (NILP (Vmac_emulate_three_button_mouse
))
8323 GetEventParameter (ref
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
8324 sizeof (UInt32
), NULL
, &mods
);
8325 return mac_get_emulated_btn(mods
);
8327 case kEventMouseButtonSecondary
:
8328 return mac_wheel_button_is_mouse_2
? 2 : 1;
8329 case kEventMouseButtonTertiary
:
8330 case 4: /* 4 is the number for the mouse wheel button */
8331 return mac_wheel_button_is_mouse_2
? 1 : 2;
8337 /* Normally, ConvertEventRefToEventRecord will correctly handle all
8338 events. However the click of the mouse wheel is not converted to a
8339 mouseDown or mouseUp event. Likewise for dead key down events.
8340 This calls ConvertEventRef, but then checks to see if it is a mouse
8341 up/down, or a dead key down carbon event that has not been
8342 converted, and if so, converts it by hand (to be picked up in the
8343 XTread_socket loop). */
8344 static Boolean
mac_convert_event_ref (EventRef eventRef
, EventRecord
*eventRec
)
8346 Boolean result
= ConvertEventRefToEventRecord (eventRef
, eventRec
);
8351 switch (GetEventClass (eventRef
))
8353 case kEventClassMouse
:
8354 switch (GetEventKind (eventRef
))
8356 case kEventMouseDown
:
8357 eventRec
->what
= mouseDown
;
8362 eventRec
->what
= mouseUp
;
8371 case kEventClassKeyboard
:
8372 switch (GetEventKind (eventRef
))
8374 case kEventRawKeyDown
:
8376 unsigned char char_codes
;
8379 eventRec
->what
= keyDown
;
8380 GetEventParameter (eventRef
, kEventParamKeyMacCharCodes
, typeChar
,
8381 NULL
, sizeof (char), NULL
, &char_codes
);
8382 GetEventParameter (eventRef
, kEventParamKeyCode
, typeUInt32
,
8383 NULL
, sizeof (UInt32
), NULL
, &key_code
);
8384 eventRec
->message
= char_codes
| ((key_code
& 0xff) << 8);
8400 /* Need where and when. */
8403 GetEventParameter (eventRef
, kEventParamMouseLocation
, typeQDPoint
,
8404 NULL
, sizeof (Point
), NULL
, &eventRec
->where
);
8405 /* Use two step process because new event modifiers are 32-bit
8406 and old are 16-bit. Currently, only loss is NumLock & Fn. */
8407 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
,
8408 NULL
, sizeof (UInt32
), NULL
, &mods
);
8409 eventRec
->modifiers
= mods
;
8411 eventRec
->when
= EventTimeToTicks (GetEventTime (eventRef
));
8422 Handle menubar_handle
;
8423 MenuHandle menu_handle
;
8425 menubar_handle
= GetNewMBar (128);
8426 if(menubar_handle
== NULL
)
8428 SetMenuBar (menubar_handle
);
8431 #if !TARGET_API_MAC_CARBON
8432 menu_handle
= GetMenuHandle (M_APPLE
);
8433 if(menu_handle
!= NULL
)
8434 AppendResMenu (menu_handle
,'DRVR');
8442 do_init_managers (void)
8444 #if !TARGET_API_MAC_CARBON
8445 InitGraf (&qd
.thePort
);
8447 FlushEvents (everyEvent
, 0);
8452 #endif /* !TARGET_API_MAC_CARBON */
8455 #if !TARGET_API_MAC_CARBON
8456 /* set up some extra stack space for use by emacs */
8457 SetApplLimit ((Ptr
) ((long) GetApplLimit () - EXTRA_STACK_ALLOC
));
8459 /* MaxApplZone must be called for AppleScript to execute more
8460 complicated scripts */
8463 #endif /* !TARGET_API_MAC_CARBON */
8467 do_check_ram_size (void)
8469 SInt32 physical_ram_size
, logical_ram_size
;
8471 if (Gestalt (gestaltPhysicalRAMSize
, &physical_ram_size
) != noErr
8472 || Gestalt (gestaltLogicalRAMSize
, &logical_ram_size
) != noErr
8473 || physical_ram_size
> (1 << VALBITS
)
8474 || logical_ram_size
> (1 << VALBITS
))
8476 StopAlert (RAM_TOO_LARGE_ALERT_ID
, NULL
);
8482 do_window_update (WindowPtr win
)
8484 struct frame
*f
= mac_window_to_frame (win
);
8488 /* The tooltip has been drawn already. Avoid the SET_FRAME_GARBAGED
8490 if (win
!= tip_window
)
8492 if (f
->async_visible
== 0)
8494 /* Update events may occur when a frame gets iconified. */
8496 f
->async_visible
= 1;
8497 f
->async_iconified
= 0;
8498 SET_FRAME_GARBAGED (f
);
8504 #if TARGET_API_MAC_CARBON
8505 RgnHandle region
= NewRgn ();
8507 GetPortVisibleRegion (GetWindowPort (win
), region
);
8508 GetRegionBounds (region
, &r
);
8509 expose_frame (f
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
);
8510 UpdateControls (win
, region
);
8511 DisposeRgn (region
);
8513 r
= (*win
->visRgn
)->rgnBBox
;
8514 expose_frame (f
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
);
8515 UpdateControls (win
, win
->visRgn
);
8524 is_emacs_window (WindowPtr win
)
8526 Lisp_Object tail
, frame
;
8531 FOR_EACH_FRAME (tail
, frame
)
8532 if (FRAME_MAC_P (XFRAME (frame
)))
8533 if (FRAME_MAC_WINDOW (XFRAME (frame
)) == win
)
8542 /* Window-activate events will do the job. */
8548 /* Window-deactivate events will do the job. */
8553 do_apple_menu (SInt16 menu_item
)
8555 #if !TARGET_API_MAC_CARBON
8557 SInt16 da_driver_refnum
;
8559 if (menu_item
== I_ABOUT
)
8560 NoteAlert (ABOUT_ALERT_ID
, NULL
);
8563 GetMenuItemText (GetMenuHandle (M_APPLE
), menu_item
, item_name
);
8564 da_driver_refnum
= OpenDeskAcc (item_name
);
8566 #endif /* !TARGET_API_MAC_CARBON */
8570 do_menu_choice (SInt32 menu_choice
)
8572 SInt16 menu_id
, menu_item
;
8574 menu_id
= HiWord (menu_choice
);
8575 menu_item
= LoWord (menu_choice
);
8583 do_apple_menu (menu_item
);
8588 struct frame
*f
= mac_focus_frame (&one_mac_display_info
);
8589 MenuHandle menu
= GetMenuHandle (menu_id
);
8594 GetMenuItemRefCon (menu
, menu_item
, &refcon
);
8595 menubar_selection_callback (f
, refcon
);
8604 /* Handle drags in size box. Based on code contributed by Ben
8605 Mesander and IM - Window Manager A. */
8608 do_grow_window (WindowPtr w
, EventRecord
*e
)
8611 int rows
, columns
, width
, height
;
8612 struct frame
*f
= mac_window_to_frame (w
);
8613 XSizeHints
*size_hints
= FRAME_SIZE_HINTS (f
);
8614 int min_width
= MIN_DOC_SIZE
, min_height
= MIN_DOC_SIZE
;
8615 #if TARGET_API_MAC_CARBON
8621 if (size_hints
->flags
& PMinSize
)
8623 min_width
= size_hints
->min_width
;
8624 min_height
= size_hints
->min_height
;
8626 SetRect (&limit_rect
, min_width
, min_height
, MAX_DOC_SIZE
, MAX_DOC_SIZE
);
8628 #if TARGET_API_MAC_CARBON
8629 if (!ResizeWindow (w
, e
->where
, &limit_rect
, &new_rect
))
8631 height
= new_rect
.bottom
- new_rect
.top
;
8632 width
= new_rect
.right
- new_rect
.left
;
8634 grow_size
= GrowWindow (w
, e
->where
, &limit_rect
);
8635 /* see if it really changed size */
8638 height
= HiWord (grow_size
);
8639 width
= LoWord (grow_size
);
8642 if (width
!= FRAME_PIXEL_WIDTH (f
)
8643 || height
!= FRAME_PIXEL_HEIGHT (f
))
8645 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, height
);
8646 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, width
);
8648 x_set_window_size (f
, 0, columns
, rows
);
8653 /* Handle clicks in zoom box. Calculation of "standard state" based
8654 on code in IM - Window Manager A and code contributed by Ben
8655 Mesander. The standard state of an Emacs window is 80-characters
8656 wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */
8659 do_zoom_window (WindowPtr w
, int zoom_in_or_out
)
8662 Rect zoom_rect
, port_rect
;
8664 int w_title_height
, columns
, rows
, width
, height
;
8665 struct frame
*f
= mac_window_to_frame (w
);
8666 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
8668 #if TARGET_API_MAC_CARBON
8670 Point standard_size
;
8672 standard_size
.h
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
8673 standard_size
.v
= dpyinfo
->height
;
8675 if (IsWindowInStandardState (w
, &standard_size
, &zoom_rect
))
8676 zoom_in_or_out
= inZoomIn
;
8679 /* Adjust the standard size according to character boundaries. */
8681 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, zoom_rect
.right
- zoom_rect
.left
);
8682 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, zoom_rect
.bottom
- zoom_rect
.top
);
8683 standard_size
.h
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, columns
);
8684 standard_size
.v
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
8685 GetWindowBounds (w
, kWindowContentRgn
, &port_rect
);
8686 if (IsWindowInStandardState (w
, &standard_size
, &zoom_rect
)
8687 && port_rect
.left
== zoom_rect
.left
8688 && port_rect
.top
== zoom_rect
.top
)
8689 zoom_in_or_out
= inZoomIn
;
8691 zoom_in_or_out
= inZoomOut
;
8694 ZoomWindowIdeal (w
, zoom_in_or_out
, &standard_size
);
8696 #else /* not TARGET_API_MAC_CARBON */
8697 GetPort (&save_port
);
8699 SetPortWindowPort (w
);
8701 /* Clear window to avoid flicker. */
8702 EraseRect (&(w
->portRect
));
8703 if (zoom_in_or_out
== inZoomOut
)
8705 SetPt (&top_left
, w
->portRect
.left
, w
->portRect
.top
);
8706 LocalToGlobal (&top_left
);
8708 /* calculate height of window's title bar */
8709 w_title_height
= top_left
.v
- 1
8710 - (**((WindowPeek
) w
)->strucRgn
).rgnBBox
.top
+ GetMBarHeight ();
8712 /* get maximum height of window into zoom_rect.bottom - zoom_rect.top */
8713 zoom_rect
= qd
.screenBits
.bounds
;
8714 zoom_rect
.top
+= w_title_height
;
8715 InsetRect (&zoom_rect
, 8, 4); /* not too tight */
8717 zoom_rect
.right
= zoom_rect
.left
8718 + FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
8720 /* Adjust the standard size according to character boundaries. */
8721 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, zoom_rect
.bottom
- zoom_rect
.top
);
8723 zoom_rect
.top
+ FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
8725 (**((WStateDataHandle
) ((WindowPeek
) w
)->dataHandle
)).stdState
8729 ZoomWindow (w
, zoom_in_or_out
, f
== mac_focus_frame (dpyinfo
));
8731 SetPort (save_port
);
8732 #endif /* not TARGET_API_MAC_CARBON */
8734 /* retrieve window size and update application values */
8735 #if TARGET_API_MAC_CARBON
8736 GetWindowPortBounds (w
, &port_rect
);
8738 port_rect
= w
->portRect
;
8740 height
= port_rect
.bottom
- port_rect
.top
;
8741 width
= port_rect
.right
- port_rect
.left
;
8743 if (width
!= FRAME_PIXEL_WIDTH (f
)
8744 || height
!= FRAME_PIXEL_HEIGHT (f
))
8746 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, height
);
8747 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, width
);
8749 change_frame_size (f
, rows
, columns
, 0, 1, 0);
8750 SET_FRAME_GARBAGED (f
);
8751 cancel_mouse_face (f
);
8753 FRAME_PIXEL_WIDTH (f
) = width
;
8754 FRAME_PIXEL_HEIGHT (f
) = height
;
8756 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
8760 mac_store_apple_event (class, id
, desc
)
8761 Lisp_Object
class, id
;
8765 struct input_event buf
;
8768 desc_copy
= xmalloc (sizeof (AEDesc
));
8769 if (desc_copy
== NULL
)
8772 err
= AEDuplicateDesc (desc
, desc_copy
);
8777 buf
.kind
= MAC_APPLE_EVENT
;
8780 buf
.code
= (int)desc_copy
;
8781 XSETFRAME (buf
.frame_or_window
,
8782 mac_focus_frame (&one_mac_display_info
));
8784 kbd_buffer_store_event (&buf
);
8791 mac_make_lispy_event_code (code
)
8794 AEDesc
*desc
= (AEDesc
*)code
;
8797 obj
= mac_aedesc_to_lisp (desc
);
8798 AEDisposeDesc (desc
);
8804 #if USE_CARBON_EVENTS
8805 static pascal OSStatus
8806 mac_handle_command_event (next_handler
, event
, data
)
8807 EventHandlerCallRef next_handler
;
8814 Lisp_Object class_key
, id_key
, binding
;
8816 result
= CallNextEventHandler (next_handler
, event
);
8817 if (result
!= eventNotHandledErr
)
8820 GetEventParameter (event
, kEventParamDirectObject
, typeHICommand
, NULL
,
8821 sizeof (HICommand
), NULL
, &command
);
8823 if (command
.commandID
== 0)
8824 return eventNotHandledErr
;
8826 /* A HICommand event is mapped to an Apple event whose event class
8827 symbol is `hicommand' and event ID is its command ID. */
8828 class_key
= Qhicommand
;
8829 mac_find_apple_event_spec (0, command
.commandID
,
8830 &class_key
, &id_key
, &binding
);
8831 if (!NILP (binding
) && !EQ (binding
, Qundefined
))
8832 if (INTEGERP (binding
))
8833 return XINT (binding
);
8836 AppleEvent apple_event
;
8838 static EventParamName names
[] = {kEventParamDirectObject
,
8839 kEventParamKeyModifiers
};
8840 static EventParamType types
[] = {typeHICommand
,
8842 err
= create_apple_event_from_event_ref (event
, 2, names
, types
,
8846 err
= mac_store_apple_event (class_key
, id_key
, &apple_event
);
8847 AEDisposeDesc (&apple_event
);
8853 return eventNotHandledErr
;
8857 init_command_handler ()
8860 EventTypeSpec specs
[] = {{kEventClassCommand
, kEventCommandProcess
}};
8861 static EventHandlerUPP handle_command_eventUPP
= NULL
;
8863 if (handle_command_eventUPP
== NULL
)
8864 handle_command_eventUPP
= NewEventHandlerUPP (mac_handle_command_event
);
8865 return InstallApplicationEventHandler (handle_command_eventUPP
,
8866 GetEventTypeCount (specs
), specs
,
8870 static pascal OSStatus
8871 mac_handle_window_event (next_handler
, event
, data
)
8872 EventHandlerCallRef next_handler
;
8879 XSizeHints
*size_hints
;
8881 GetEventParameter (event
, kEventParamDirectObject
, typeWindowRef
,
8882 NULL
, sizeof (WindowPtr
), NULL
, &wp
);
8884 switch (GetEventKind (event
))
8886 case kEventWindowUpdate
:
8887 result
= CallNextEventHandler (next_handler
, event
);
8888 if (result
!= eventNotHandledErr
)
8891 do_window_update (wp
);
8894 case kEventWindowBoundsChanging
:
8895 result
= CallNextEventHandler (next_handler
, event
);
8896 if (result
!= eventNotHandledErr
)
8899 GetEventParameter (event
, kEventParamAttributes
, typeUInt32
,
8900 NULL
, sizeof (UInt32
), NULL
, &attributes
);
8901 size_hints
= FRAME_SIZE_HINTS (mac_window_to_frame (wp
));
8902 if ((attributes
& kWindowBoundsChangeUserResize
)
8903 && ((size_hints
->flags
& (PResizeInc
| PBaseSize
| PMinSize
))
8904 == (PResizeInc
| PBaseSize
| PMinSize
)))
8909 GetEventParameter (event
, kEventParamCurrentBounds
,
8911 NULL
, sizeof (Rect
), NULL
, &bounds
);
8912 width
= bounds
.right
- bounds
.left
;
8913 height
= bounds
.bottom
- bounds
.top
;
8915 if (width
< size_hints
->min_width
)
8916 width
= size_hints
->min_width
;
8918 width
= size_hints
->base_width
8919 + (int) ((width
- size_hints
->base_width
)
8920 / (float) size_hints
->width_inc
+ .5)
8921 * size_hints
->width_inc
;
8923 if (height
< size_hints
->min_height
)
8924 height
= size_hints
->min_height
;
8926 height
= size_hints
->base_height
8927 + (int) ((height
- size_hints
->base_height
)
8928 / (float) size_hints
->height_inc
+ .5)
8929 * size_hints
->height_inc
;
8931 bounds
.right
= bounds
.left
+ width
;
8932 bounds
.bottom
= bounds
.top
+ height
;
8933 SetEventParameter (event
, kEventParamCurrentBounds
,
8934 typeQDRectangle
, sizeof (Rect
), &bounds
);
8939 case kEventWindowShown
:
8940 case kEventWindowHidden
:
8941 case kEventWindowExpanded
:
8942 case kEventWindowCollapsed
:
8943 result
= CallNextEventHandler (next_handler
, event
);
8945 mac_handle_visibility_change (mac_window_to_frame (wp
));
8951 return eventNotHandledErr
;
8954 static pascal OSStatus
8955 mac_handle_mouse_event (next_handler
, event
, data
)
8956 EventHandlerCallRef next_handler
;
8962 switch (GetEventKind (event
))
8964 case kEventMouseWheelMoved
:
8968 EventMouseWheelAxis axis
;
8972 result
= CallNextEventHandler (next_handler
, event
);
8973 if (result
!= eventNotHandledErr
|| read_socket_inev
== NULL
)
8976 GetEventParameter (event
, kEventParamWindowRef
, typeWindowRef
,
8977 NULL
, sizeof (WindowRef
), NULL
, &wp
);
8978 f
= mac_window_to_frame (wp
);
8979 if (f
!= mac_focus_frame (&one_mac_display_info
))
8982 GetEventParameter (event
, kEventParamMouseWheelAxis
,
8983 typeMouseWheelAxis
, NULL
,
8984 sizeof (EventMouseWheelAxis
), NULL
, &axis
);
8985 if (axis
!= kEventMouseWheelAxisY
)
8988 GetEventParameter (event
, kEventParamMouseWheelDelta
, typeSInt32
,
8989 NULL
, sizeof (SInt32
), NULL
, &delta
);
8990 GetEventParameter (event
, kEventParamMouseLocation
, typeQDPoint
,
8991 NULL
, sizeof (Point
), NULL
, &point
);
8992 read_socket_inev
->kind
= WHEEL_EVENT
;
8993 read_socket_inev
->code
= 0;
8994 read_socket_inev
->modifiers
=
8995 (mac_event_to_emacs_modifiers (event
)
8996 | ((delta
< 0) ? down_modifier
: up_modifier
));
8997 SetPortWindowPort (wp
);
8998 GlobalToLocal (&point
);
8999 XSETINT (read_socket_inev
->x
, point
.h
);
9000 XSETINT (read_socket_inev
->y
, point
.v
);
9001 XSETFRAME (read_socket_inev
->frame_or_window
, f
);
9011 return eventNotHandledErr
;
9016 mac_store_services_event (event
)
9020 AppleEvent apple_event
;
9023 switch (GetEventKind (event
))
9025 case kEventServicePaste
:
9027 err
= create_apple_event_from_event_ref (event
, 0, NULL
, NULL
,
9031 case kEventServicePerform
:
9033 static EventParamName names
[] = {kEventParamServiceMessageName
,
9034 kEventParamServiceUserData
};
9035 static EventParamType types
[] = {typeCFStringRef
,
9039 err
= create_apple_event_from_event_ref (event
, 2, names
, types
,
9050 err
= mac_store_apple_event (Qservices
, id_key
, &apple_event
);
9051 AEDisposeDesc (&apple_event
);
9056 #endif /* MAC_OSX */
9057 #endif /* USE_CARBON_EVENTS */
9061 install_window_handler (window
)
9065 #if USE_CARBON_EVENTS
9066 EventTypeSpec specs_window
[] =
9067 {{kEventClassWindow
, kEventWindowUpdate
},
9068 {kEventClassWindow
, kEventWindowBoundsChanging
},
9069 {kEventClassWindow
, kEventWindowShown
},
9070 {kEventClassWindow
, kEventWindowHidden
},
9071 {kEventClassWindow
, kEventWindowExpanded
},
9072 {kEventClassWindow
, kEventWindowCollapsed
}};
9073 EventTypeSpec specs_mouse
[] = {{kEventClassMouse
, kEventMouseWheelMoved
}};
9074 static EventHandlerUPP handle_window_eventUPP
= NULL
;
9075 static EventHandlerUPP handle_mouse_eventUPP
= NULL
;
9077 if (handle_window_eventUPP
== NULL
)
9078 handle_window_eventUPP
= NewEventHandlerUPP (mac_handle_window_event
);
9079 if (handle_mouse_eventUPP
== NULL
)
9080 handle_mouse_eventUPP
= NewEventHandlerUPP (mac_handle_mouse_event
);
9081 err
= InstallWindowEventHandler (window
, handle_window_eventUPP
,
9082 GetEventTypeCount (specs_window
),
9083 specs_window
, NULL
, NULL
);
9085 err
= InstallWindowEventHandler (window
, handle_mouse_eventUPP
,
9086 GetEventTypeCount (specs_mouse
),
9087 specs_mouse
, NULL
, NULL
);
9089 #if TARGET_API_MAC_CARBON
9090 if (mac_do_track_dragUPP
== NULL
)
9091 mac_do_track_dragUPP
= NewDragTrackingHandlerUPP (mac_do_track_drag
);
9092 if (mac_do_receive_dragUPP
== NULL
)
9093 mac_do_receive_dragUPP
= NewDragReceiveHandlerUPP (mac_do_receive_drag
);
9096 err
= InstallTrackingHandler (mac_do_track_dragUPP
, window
, NULL
);
9098 err
= InstallReceiveHandler (mac_do_receive_dragUPP
, window
, NULL
);
9104 remove_window_handler (window
)
9107 #if TARGET_API_MAC_CARBON
9108 if (mac_do_track_dragUPP
)
9109 RemoveTrackingHandler (mac_do_track_dragUPP
, window
);
9110 if (mac_do_receive_dragUPP
)
9111 RemoveReceiveHandler (mac_do_receive_dragUPP
, window
);
9115 #if TARGET_API_MAC_CARBON
9117 mac_do_track_drag (DragTrackingMessage message
, WindowPtr window
,
9118 void *handlerRefCon
, DragReference theDrag
)
9120 static int can_accept
;
9123 ItemReference theItem
;
9124 FlavorFlags theFlags
;
9127 if (GetFrontWindowOfClass (kMovableModalWindowClass
, false))
9128 return dragNotAcceptedErr
;
9132 case kDragTrackingEnterHandler
:
9133 CountDragItems (theDrag
, &items
);
9135 for (index
= 1; index
<= items
; index
++)
9137 GetDragItemReferenceNumber (theDrag
, index
, &theItem
);
9138 result
= GetFlavorFlags (theDrag
, theItem
, flavorTypeHFS
, &theFlags
);
9139 if (result
== noErr
)
9147 case kDragTrackingEnterWindow
:
9150 RgnHandle hilite_rgn
= NewRgn ();
9152 struct frame
*f
= mac_window_to_frame (window
);
9154 GetWindowPortBounds (window
, &r
);
9155 OffsetRect (&r
, -r
.left
, -r
.top
);
9156 RectRgn (hilite_rgn
, &r
);
9157 ShowDragHilite (theDrag
, hilite_rgn
, true);
9158 DisposeRgn (hilite_rgn
);
9159 SetThemeCursor (kThemeCopyArrowCursor
);
9163 case kDragTrackingInWindow
:
9166 case kDragTrackingLeaveWindow
:
9169 struct frame
*f
= mac_window_to_frame (window
);
9171 HideDragHilite (theDrag
);
9172 SetThemeCursor (kThemeArrowCursor
);
9176 case kDragTrackingLeaveHandler
:
9184 mac_do_receive_drag (WindowPtr window
, void *handlerRefCon
,
9185 DragReference theDrag
)
9189 FlavorFlags theFlags
;
9192 ItemReference theItem
;
9194 Size size
= sizeof (HFSFlavor
);
9195 Lisp_Object file_list
;
9197 if (GetFrontWindowOfClass (kMovableModalWindowClass
, false))
9198 return dragNotAcceptedErr
;
9201 GetDragMouse (theDrag
, &mouse
, 0L);
9202 CountDragItems (theDrag
, &items
);
9203 for (index
= 1; index
<= items
; index
++)
9205 /* Only handle file references. */
9206 GetDragItemReferenceNumber (theDrag
, index
, &theItem
);
9207 result
= GetFlavorFlags (theDrag
, theItem
, flavorTypeHFS
, &theFlags
);
9208 if (result
== noErr
)
9213 char unix_path_name
[MAXPATHLEN
];
9215 GetFlavorData (theDrag
, theItem
, flavorTypeHFS
, &data
, &size
, 0L);
9217 /* Use Carbon routines, otherwise it converts the file name
9218 to /Macintosh HD/..., which is not correct. */
9219 FSpMakeFSRef (&data
.fileSpec
, &fref
);
9220 if (! FSRefMakePath (&fref
, unix_path_name
, sizeof (unix_path_name
)));
9222 if (fsspec_to_posix_pathname (&data
.fileSpec
, unix_path_name
,
9223 sizeof (unix_path_name
) - 1) == noErr
)
9225 /* x-dnd functions expect undecoded filenames. */
9226 file_list
= Fcons (make_unibyte_string (unix_path_name
,
9227 strlen (unix_path_name
)),
9231 /* If there are items in the list, construct an event and post it to
9232 the queue like an interrupt using kbd_buffer_store_event. */
9233 if (!NILP (file_list
))
9235 struct input_event event
;
9237 struct frame
*f
= mac_window_to_frame (window
);
9240 GlobalToLocal (&mouse
);
9241 GetDragModifiers (theDrag
, NULL
, NULL
, &modifiers
);
9243 event
.kind
= DRAG_N_DROP_EVENT
;
9245 event
.modifiers
= mac_to_emacs_modifiers (modifiers
);
9246 event
.timestamp
= TickCount () * (1000 / 60);
9247 XSETINT (event
.x
, mouse
.h
);
9248 XSETINT (event
.y
, mouse
.v
);
9249 XSETFRAME (frame
, f
);
9250 event
.frame_or_window
= frame
;
9251 event
.arg
= file_list
;
9252 /* Post to the interrupt queue */
9253 kbd_buffer_store_event (&event
);
9254 /* MAC_TODO: Mimic behavior of windows by switching contexts to Emacs */
9256 ProcessSerialNumber psn
;
9257 GetCurrentProcess (&psn
);
9258 SetFrontProcess (&psn
);
9264 return dragNotAcceptedErr
;
9271 profiler_exit_proc ()
9273 ProfilerDump ("\pEmacs.prof");
9278 /* These few functions implement Emacs as a normal Mac application
9279 (almost): set up the heap and the Toolbox, handle necessary system
9280 events plus a few simple menu events. They also set up Emacs's
9281 access to functions defined in the rest of this file. Emacs uses
9282 function hooks to perform all its terminal I/O. A complete list of
9283 these functions appear in termhooks.h. For what they do, read the
9284 comments there and see also w32term.c and xterm.c. What's
9285 noticeably missing here is the event loop, which is normally
9286 present in most Mac application. After performing the necessary
9287 Mac initializations, main passes off control to emacs_main
9288 (corresponding to main in emacs.c). Emacs_main calls XTread_socket
9289 (defined further below) to read input. This is where
9290 WaitNextEvent/ReceiveNextEvent is called to process Mac events. */
9297 #if __profile__ /* is the profiler on? */
9298 if (ProfilerInit(collectDetailed
, bestTimeBase
, 5000, 200))
9303 /* set creator and type for files created by MSL */
9308 do_init_managers ();
9313 do_check_ram_size ();
9316 init_emacs_passwd_dir ();
9320 initialize_applescript ();
9322 init_apple_event_handler ();
9328 /* set up argv array from STR# resource */
9329 get_string_list (&argv
, ARGV_STRING_LIST_ID
);
9333 /* free up AppleScript resources on exit */
9334 atexit (terminate_applescript
);
9336 #if __profile__ /* is the profiler on? */
9337 atexit (profiler_exit_proc
);
9340 /* 3rd param "envp" never used in emacs_main */
9341 (void) emacs_main (argc
, argv
, 0);
9344 /* Never reached - real exit in Fkill_emacs */
9349 /* Table for translating Mac keycode to X keysym values. Contributed
9351 Mapping for special keys is now identical to that in Apple X11
9352 except `clear' (-> <clear>) on the KeyPad, `enter' (-> <kp-enter>)
9353 on the right of the Cmd key on laptops, and fn + `enter' (->
9355 static unsigned char keycode_to_xkeysym_table
[] = {
9356 /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9357 /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9358 /*0x20*/ 0, 0, 0, 0, 0x0d /*return*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9360 /*0x30*/ 0x09 /*tab*/, 0 /*0x0020 space*/, 0, 0x08 /*backspace*/,
9361 /*0x34*/ 0x8d /*enter on laptops*/, 0x1b /*escape*/, 0, 0,
9362 /*0x38*/ 0, 0, 0, 0,
9363 /*0x3C*/ 0, 0, 0, 0,
9365 /*0x40*/ 0, 0xae /*kp-.*/, 0, 0xaa /*kp-**/,
9366 /*0x44*/ 0, 0xab /*kp-+*/, 0, 0x0b /*clear*/,
9367 /*0x48*/ 0, 0, 0, 0xaf /*kp-/*/,
9368 /*0x4C*/ 0x8d /*kp-enter*/, 0, 0xad /*kp--*/, 0,
9370 /*0x50*/ 0, 0xbd /*kp-=*/, 0xb0 /*kp-0*/, 0xb1 /*kp-1*/,
9371 /*0x54*/ 0xb2 /*kp-2*/, 0xb3 /*kp-3*/, 0xb4 /*kp-4*/, 0xb5 /*kp-5*/,
9372 /*0x58*/ 0xb6 /*kp-6*/, 0xb7 /*kp-7*/, 0, 0xb8 /*kp-8*/,
9373 /*0x5C*/ 0xb9 /*kp-9*/, 0, 0, 0,
9375 /*0x60*/ 0xc2 /*f5*/, 0xc3 /*f6*/, 0xc4 /*f7*/, 0xc0 /*f3*/,
9376 /*0x64*/ 0xc5 /*f8*/, 0xc6 /*f9*/, 0, 0xc8 /*f11*/,
9377 /*0x68*/ 0, 0xca /*f13*/, 0, 0xcb /*f14*/,
9378 /*0x6C*/ 0, 0xc7 /*f10*/, 0x0a /*fn+enter on laptops*/, 0xc9 /*f12*/,
9380 /*0x70*/ 0, 0xcc /*f15*/, 0x6a /*help*/, 0x50 /*home*/,
9381 /*0x74*/ 0x55 /*pgup*/, 0xff /*delete*/, 0xc1 /*f4*/, 0x57 /*end*/,
9382 /*0x78*/ 0xbf /*f2*/, 0x56 /*pgdown*/, 0xbe /*f1*/, 0x51 /*left*/,
9383 /*0x7C*/ 0x53 /*right*/, 0x54 /*down*/, 0x52 /*up*/, 0
9388 keycode_to_xkeysym (int keyCode
, int *xKeySym
)
9390 *xKeySym
= keycode_to_xkeysym_table
[keyCode
& 0x7f];
9391 return *xKeySym
!= 0;
9394 static unsigned char fn_keycode_to_xkeysym_table
[] = {
9395 /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9396 /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9397 /*0x20*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9399 /*0x30*/ 0, 0, 0, 0,
9400 /*0x34*/ 0, 0, 0, 0,
9401 /*0x38*/ 0, 0, 0, 0,
9402 /*0x3C*/ 0, 0, 0, 0,
9404 /*0x40*/ 0, 0x2e /*kp-. = .*/, 0, 0x50 /*kp-* = 'p'*/,
9405 /*0x44*/ 0, '/' /*kp-+*/, 0, 0,
9406 /*0x48*/ 0, 0, 0, 0x30 /*kp-/ = '0'*/,
9407 /*0x4C*/ 0, 0, 0x3b /*kp-- = ';'*/, 0,
9409 /*0x50*/ 0, 0x2d /*kp-= = '-'*/, 0x6d /*kp-0 = 'm'*/, 0x6a /*kp-1 = 'j'*/,
9410 /*0x54*/ 0x6b /*kp-2 = 'k'*/, 0x6c /*kp-3 = 'l'*/, 'u' /*kp-4*/, 'i' /*kp-5*/,
9411 /*0x58*/ 'o' /*kp-6*/, '7' /*kp-7*/, 0, '8' /*kp-8*/,
9412 /*0x5C*/ '9' /*kp-9*/, 0, 0, 0,
9414 /*0x60*/ 0, 0, 0, 0,
9415 /*0x64*/ 0, 0, 0, 0,
9416 /*0x68*/ 0, 0, 0, 0,
9417 /*0x6C*/ 0, 0, 0, 0,
9419 /*0x70*/ 0, 0, 0, 0,
9420 /*0x74*/ 0, 0, 0, 0,
9421 /*0x78*/ 0, 0, 0, 0,
9425 convert_fn_keycode (EventRef eventRef
, int keyCode
, int *newCode
)
9428 /* Use the special map to translate keys when function modifier is
9429 to be caught. KeyTranslate can't be used in that case.
9430 We can't detect the function key using the input_event.modifiers,
9431 because this uses the high word of an UInt32. Therefore,
9432 we'll just read it out of the original eventRef.
9436 /* TODO / known issues
9438 - Fn-Shift-j is regonized as Fn-j and not Fn-J.
9439 The above table always translates to lower characters. We need to use
9440 the KCHR keyboard resource (KeyTranslate() ) to map k->K and 8->*.
9442 - The table is meant for English language keyboards, and it will work
9443 for many others with the exception of key combinations like Fn-ö on
9444 a German keyboard, which is currently mapped to Fn-;.
9445 How to solve this without keeping separate tables for all keyboards
9446 around? KeyTranslate isn't of much help here, as it only takes a 16-bit
9447 value for keycode with the modifiers in he high byte, i.e. no room for the
9448 Fn modifier. That's why we need the table.
9453 if (!NILP(Vmac_function_modifier
))
9455 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
9456 sizeof (UInt32
), NULL
, &mods
);
9457 if (mods
& kEventKeyModifierFnMask
)
9458 { *newCode
= fn_keycode_to_xkeysym_table
[keyCode
& 0x7f];
9460 return (*newCode
!= 0);
9468 backtranslate_modified_keycode(int mods
, int keycode
, int def
)
9470 EventModifiers mapped_modifiers
=
9471 (NILP (Vmac_control_modifier
) ? 0 : controlKey
)
9472 | (NILP (Vmac_option_modifier
) ? 0 : optionKey
)
9473 | (NILP (Vmac_command_modifier
) ? 0 : cmdKey
);
9475 if (mods
& mapped_modifiers
)
9477 /* This code comes from Keyboard Resource,
9478 Appendix C of IM - Text. This is necessary
9479 since shift is ignored in KCHR table
9480 translation when option or command is pressed.
9481 It also does not translate correctly
9482 control-shift chars like C-% so mask off shift
9485 Not done for combinations with the option key (alt)
9486 unless it is to be caught by Emacs: this is
9487 to preserve key combinations translated by the OS
9490 /* Mask off modifier keys that are mapped to some Emacs
9492 int new_modifiers
= mods
& ~mapped_modifiers
;
9493 /* set high byte of keycode to modifier high byte*/
9494 int new_keycode
= keycode
| new_modifiers
;
9495 Ptr kchr_ptr
= (Ptr
) GetScriptManagerVariable (smKCHRCache
);
9496 unsigned long some_state
= 0;
9497 return (int) KeyTranslate (kchr_ptr
, new_keycode
,
9498 &some_state
) & 0xff;
9499 /* TO DO: Recognize two separate resulting characters, "for
9500 example, when the user presses Option-E followed by N, you
9501 can map this through the KeyTranslate function using the
9502 U.S. 'KCHR' resource to produce ´n, which KeyTranslate
9503 returns as two characters in the bytes labeled Character code
9504 1 and Character code 2." (from Carbon API doc) */
9512 #if !USE_CARBON_EVENTS
9513 static RgnHandle mouse_region
= NULL
;
9516 mac_wait_next_event (er
, sleep_time
, dequeue
)
9521 static EventRecord er_buf
= {nullEvent
};
9522 UInt32 target_tick
, current_tick
;
9523 EventMask event_mask
;
9525 if (mouse_region
== NULL
)
9526 mouse_region
= NewRgn ();
9528 event_mask
= everyEvent
;
9529 if (!mac_ready_for_apple_events
)
9530 event_mask
-= highLevelEventMask
;
9532 current_tick
= TickCount ();
9533 target_tick
= current_tick
+ sleep_time
;
9535 if (er_buf
.what
== nullEvent
)
9536 while (!WaitNextEvent (event_mask
, &er_buf
,
9537 target_tick
- current_tick
, mouse_region
))
9539 current_tick
= TickCount ();
9540 if (target_tick
<= current_tick
)
9546 er_buf
.what
= nullEvent
;
9549 #endif /* not USE_CARBON_EVENTS */
9551 /* Emacs calls this whenever it wants to read an input event from the
9554 XTread_socket (sd
, expected
, hold_quit
)
9556 struct input_event
*hold_quit
;
9558 struct input_event inev
;
9560 #if USE_CARBON_EVENTS
9562 EventTargetRef toolbox_dispatcher
;
9565 struct mac_display_info
*dpyinfo
= &one_mac_display_info
;
9567 if (interrupt_input_blocked
)
9569 interrupt_input_pending
= 1;
9573 interrupt_input_pending
= 0;
9576 /* So people can tell when we have read the available input. */
9577 input_signal_count
++;
9579 #if USE_CARBON_EVENTS
9580 toolbox_dispatcher
= GetEventDispatcherTarget ();
9582 while (!ReceiveNextEvent (0, NULL
, kEventDurationNoWait
,
9583 kEventRemoveFromQueue
, &eventRef
))
9584 #else /* !USE_CARBON_EVENTS */
9585 while (mac_wait_next_event (&er
, 0, true))
9586 #endif /* !USE_CARBON_EVENTS */
9590 unsigned long timestamp
;
9592 /* It is necessary to set this (additional) argument slot of an
9593 event to nil because keyboard.c protects incompletely
9594 processed event from being garbage collected by placing them
9595 in the kbd_buffer_gcpro vector. */
9597 inev
.kind
= NO_EVENT
;
9600 #if USE_CARBON_EVENTS
9601 timestamp
= GetEventTime (eventRef
) / kEventDurationMillisecond
;
9603 timestamp
= er
.when
* (1000 / 60); /* ticks to milliseconds */
9606 #if USE_CARBON_EVENTS
9607 /* Handle new events */
9608 if (!mac_convert_event_ref (eventRef
, &er
))
9610 /* There used to be a handler for the kEventMouseWheelMoved
9611 event here. But as of Mac OS X 10.4, this kind of event
9612 is not directly posted to the main event queue by
9613 two-finger scrolling on the trackpad. Instead, some
9614 private event is posted and it is converted to a wheel
9615 event by the default handler for the application target.
9616 The converted one can be received by a Carbon event
9617 handler installed on a window target. */
9618 read_socket_inev
= &inev
;
9619 SendEventToEventTarget (eventRef
, toolbox_dispatcher
);
9620 read_socket_inev
= NULL
;
9623 #endif /* USE_CARBON_EVENTS */
9629 WindowPtr window_ptr
;
9630 ControlPartCode part_code
;
9633 #if USE_CARBON_EVENTS
9634 /* This is needed to send mouse events like aqua window
9635 buttons to the correct handler. */
9636 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
9637 != eventNotHandledErr
)
9640 last_mouse_glyph_frame
= 0;
9642 if (dpyinfo
->grabbed
&& last_mouse_frame
9643 && FRAME_LIVE_P (last_mouse_frame
))
9645 window_ptr
= FRAME_MAC_WINDOW (last_mouse_frame
);
9646 part_code
= inContent
;
9650 part_code
= FindWindow (er
.where
, &window_ptr
);
9651 if (tip_window
&& window_ptr
== tip_window
)
9653 HideWindow (tip_window
);
9654 part_code
= FindWindow (er
.where
, &window_ptr
);
9658 if (er
.what
!= mouseDown
&&
9659 (part_code
!= inContent
|| dpyinfo
->grabbed
== 0))
9665 f
= mac_focus_frame (dpyinfo
);
9666 saved_menu_event_location
= er
.where
;
9667 inev
.kind
= MENU_BAR_ACTIVATE_EVENT
;
9668 XSETFRAME (inev
.frame_or_window
, f
);
9672 if (window_ptr
!= FRAME_MAC_WINDOW (mac_focus_frame (dpyinfo
)))
9673 SelectWindow (window_ptr
);
9676 ControlPartCode control_part_code
;
9678 Point mouse_loc
= er
.where
;
9680 ControlKind control_kind
;
9683 f
= mac_window_to_frame (window_ptr
);
9684 /* convert to local coordinates of new window */
9685 SetPortWindowPort (window_ptr
);
9687 GlobalToLocal (&mouse_loc
);
9688 #if TARGET_API_MAC_CARBON
9689 ch
= FindControlUnderMouse (mouse_loc
, window_ptr
,
9690 &control_part_code
);
9693 GetControlKind (ch
, &control_kind
);
9696 control_part_code
= FindControl (mouse_loc
, window_ptr
,
9700 #if USE_CARBON_EVENTS
9701 inev
.code
= mac_get_mouse_btn (eventRef
);
9702 inev
.modifiers
= mac_event_to_emacs_modifiers (eventRef
);
9704 inev
.code
= mac_get_emulated_btn (er
.modifiers
);
9705 inev
.modifiers
= mac_to_emacs_modifiers (er
.modifiers
);
9707 XSETINT (inev
.x
, mouse_loc
.h
);
9708 XSETINT (inev
.y
, mouse_loc
.v
);
9710 if (dpyinfo
->grabbed
&& tracked_scroll_bar
9712 #ifndef USE_TOOLKIT_SCROLL_BARS
9713 /* control_part_code becomes kControlNoPart if
9714 a progress indicator is clicked. */
9715 && control_part_code
!= kControlNoPart
9716 #else /* USE_TOOLKIT_SCROLL_BARS */
9718 && control_kind
.kind
== kControlKindScrollBar
9719 #endif /* MAC_OSX */
9720 #endif /* USE_TOOLKIT_SCROLL_BARS */
9723 struct scroll_bar
*bar
;
9725 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
9727 bar
= tracked_scroll_bar
;
9728 #ifndef USE_TOOLKIT_SCROLL_BARS
9729 control_part_code
= kControlIndicatorPart
;
9733 bar
= (struct scroll_bar
*) GetControlReference (ch
);
9734 #ifdef USE_TOOLKIT_SCROLL_BARS
9735 /* Make the "Ctrl-Mouse-2 splits window" work
9736 for toolkit scroll bars. */
9737 if (er
.modifiers
& controlKey
)
9738 x_scroll_bar_handle_click (bar
, control_part_code
,
9740 else if (er
.what
== mouseDown
)
9741 x_scroll_bar_handle_press (bar
, control_part_code
,
9744 x_scroll_bar_handle_release (bar
, &inev
);
9745 #else /* not USE_TOOLKIT_SCROLL_BARS */
9746 x_scroll_bar_handle_click (bar
, control_part_code
,
9748 if (er
.what
== mouseDown
9749 && control_part_code
== kControlIndicatorPart
)
9750 tracked_scroll_bar
= bar
;
9752 tracked_scroll_bar
= NULL
;
9753 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9758 int x
= mouse_loc
.h
;
9759 int y
= mouse_loc
.v
;
9761 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
9762 if (EQ (window
, f
->tool_bar_window
))
9764 if (er
.what
== mouseDown
)
9765 handle_tool_bar_click (f
, x
, y
, 1, 0);
9767 handle_tool_bar_click (f
, x
, y
, 0,
9773 XSETFRAME (inev
.frame_or_window
, f
);
9774 inev
.kind
= MOUSE_CLICK_EVENT
;
9778 if (er
.what
== mouseDown
)
9780 dpyinfo
->grabbed
|= (1 << inev
.code
);
9781 last_mouse_frame
= f
;
9784 last_tool_bar_item
= -1;
9788 if ((dpyinfo
->grabbed
& (1 << inev
.code
)) == 0)
9789 /* If a button is released though it was not
9790 previously pressed, that would be because
9791 of multi-button emulation. */
9792 dpyinfo
->grabbed
= 0;
9794 dpyinfo
->grabbed
&= ~(1 << inev
.code
);
9797 /* Ignore any mouse motion that happened before
9798 this event; any subsequent mouse-movement Emacs
9799 events should reflect only motion after the
9804 #ifdef USE_TOOLKIT_SCROLL_BARS
9805 if (inev
.kind
== MOUSE_CLICK_EVENT
)
9810 inev
.modifiers
|= down_modifier
;
9813 inev
.modifiers
|= up_modifier
;
9820 #if TARGET_API_MAC_CARBON
9821 DragWindow (window_ptr
, er
.where
, NULL
);
9822 #else /* not TARGET_API_MAC_CARBON */
9823 DragWindow (window_ptr
, er
.where
, &qd
.screenBits
.bounds
);
9824 #endif /* not TARGET_API_MAC_CARBON */
9825 /* Update the frame parameters. */
9827 struct frame
*f
= mac_window_to_frame (window_ptr
);
9829 if (f
&& !f
->async_iconified
)
9830 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
9835 if (TrackGoAway (window_ptr
, er
.where
))
9837 inev
.kind
= DELETE_WINDOW_EVENT
;
9838 XSETFRAME (inev
.frame_or_window
,
9839 mac_window_to_frame (window_ptr
));
9843 /* window resize handling added --ben */
9845 do_grow_window (window_ptr
, &er
);
9848 /* window zoom handling added --ben */
9851 if (TrackBox (window_ptr
, er
.where
, part_code
))
9852 do_zoom_window (window_ptr
, part_code
);
9862 #if USE_CARBON_EVENTS
9863 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
9864 != eventNotHandledErr
)
9867 do_window_update ((WindowPtr
) er
.message
);
9872 #if USE_CARBON_EVENTS
9873 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
9874 != eventNotHandledErr
)
9877 switch ((er
.message
>> 24) & 0x000000FF)
9879 case suspendResumeMessage
:
9880 if ((er
.message
& resumeFlag
) == 1)
9886 case mouseMovedMessage
:
9887 #if !USE_CARBON_EVENTS
9888 SetRectRgn (mouse_region
, er
.where
.h
, er
.where
.v
,
9889 er
.where
.h
+ 1, er
.where
.v
+ 1);
9891 previous_help_echo_string
= help_echo_string
;
9892 help_echo_string
= Qnil
;
9894 if (dpyinfo
->grabbed
&& last_mouse_frame
9895 && FRAME_LIVE_P (last_mouse_frame
))
9896 f
= last_mouse_frame
;
9898 f
= dpyinfo
->x_focus_frame
;
9900 if (dpyinfo
->mouse_face_hidden
)
9902 dpyinfo
->mouse_face_hidden
= 0;
9903 clear_mouse_face (dpyinfo
);
9908 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
9909 Point mouse_pos
= er
.where
;
9911 SetPortWindowPort (wp
);
9913 GlobalToLocal (&mouse_pos
);
9915 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
9916 #ifdef USE_TOOLKIT_SCROLL_BARS
9917 x_scroll_bar_handle_drag (wp
, tracked_scroll_bar
,
9919 #else /* not USE_TOOLKIT_SCROLL_BARS */
9920 x_scroll_bar_note_movement (tracked_scroll_bar
,
9922 - XINT (tracked_scroll_bar
->top
),
9923 er
.when
* (1000 / 60));
9924 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9927 /* Generate SELECT_WINDOW_EVENTs when needed. */
9928 if (mouse_autoselect_window
)
9932 window
= window_from_coordinates (f
,
9937 /* Window will be selected only when it is
9938 not selected now and last mouse movement
9939 event was not in it. Minibuffer window
9940 will be selected iff it is active. */
9941 if (WINDOWP (window
)
9942 && !EQ (window
, last_window
)
9943 && !EQ (window
, selected_window
))
9945 inev
.kind
= SELECT_WINDOW_EVENT
;
9946 inev
.frame_or_window
= window
;
9951 if (!note_mouse_movement (f
, &mouse_pos
))
9952 help_echo_string
= previous_help_echo_string
;
9956 /* If the contents of the global variable
9957 help_echo_string has changed, generate a
9959 if (!NILP (help_echo_string
) || !NILP (previous_help_echo_string
))
9967 WindowPtr window_ptr
= (WindowPtr
) er
.message
;
9969 #if USE_CARBON_EVENTS
9970 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
9971 != eventNotHandledErr
)
9974 if (window_ptr
== tip_window
)
9976 HideWindow (tip_window
);
9980 if (!is_emacs_window (window_ptr
))
9983 if ((er
.modifiers
& activeFlag
) != 0)
9985 /* A window has been activated */
9986 Point mouse_loc
= er
.where
;
9988 x_detect_focus_change (dpyinfo
, &er
, &inev
);
9990 SetPortWindowPort (window_ptr
);
9991 GlobalToLocal (&mouse_loc
);
9992 /* Window-activated event counts as mouse movement,
9993 so update things that depend on mouse position. */
9994 note_mouse_movement (mac_window_to_frame (window_ptr
),
9999 /* A window has been deactivated */
10000 #if USE_TOOLKIT_SCROLL_BARS
10001 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
10003 struct input_event event
;
10005 EVENT_INIT (event
);
10006 event
.kind
= NO_EVENT
;
10007 x_scroll_bar_handle_release (tracked_scroll_bar
, &event
);
10008 if (event
.kind
!= NO_EVENT
)
10010 event
.timestamp
= timestamp
;
10011 kbd_buffer_store_event_hold (&event
, hold_quit
);
10016 dpyinfo
->grabbed
= 0;
10018 x_detect_focus_change (dpyinfo
, &er
, &inev
);
10020 f
= mac_window_to_frame (window_ptr
);
10021 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10023 /* If we move outside the frame, then we're
10024 certainly no longer on any text in the
10026 clear_mouse_face (dpyinfo
);
10027 dpyinfo
->mouse_face_mouse_frame
= 0;
10030 /* Generate a nil HELP_EVENT to cancel a help-echo.
10031 Do it only if there's something to cancel.
10032 Otherwise, the startup message is cleared when the
10033 mouse leaves the frame. */
10034 if (any_help_event_p
)
10043 int keycode
= (er
.message
& keyCodeMask
) >> 8;
10046 #if USE_CARBON_EVENTS && defined (MAC_OSX)
10047 /* When using Carbon Events, we need to pass raw keyboard
10048 events to the TSM ourselves. If TSM handles it, it
10049 will pass back noErr, otherwise it will pass back
10050 "eventNotHandledErr" and we can process it
10052 if ((mac_pass_command_to_system
10053 || !(er
.modifiers
& cmdKey
))
10054 && (mac_pass_control_to_system
10055 || !(er
.modifiers
& controlKey
))
10056 && (NILP (Vmac_option_modifier
)
10057 || !(er
.modifiers
& optionKey
)))
10058 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
10059 != eventNotHandledErr
)
10064 if (dpyinfo
->x_focus_frame
== NULL
)
10066 /* Beep if keyboard input occurs when all the frames
10074 static SInt16 last_key_script
= -1;
10075 SInt16 current_key_script
= GetScriptManagerVariable (smKeyScript
);
10077 if (last_key_script
!= current_key_script
)
10079 struct input_event event
;
10081 EVENT_INIT (event
);
10082 event
.kind
= LANGUAGE_CHANGE_EVENT
;
10084 event
.code
= current_key_script
;
10085 event
.timestamp
= timestamp
;
10086 kbd_buffer_store_event (&event
);
10089 last_key_script
= current_key_script
;
10094 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
10096 clear_mouse_face (dpyinfo
);
10097 dpyinfo
->mouse_face_hidden
= 1;
10100 /* translate the keycode back to determine the original key */
10101 /* Convert key code if function key is pressed.
10102 Otherwise, if non-ASCII-event, take care of that
10103 without re-translating the key code. */
10104 #if USE_CARBON_EVENTS
10105 if (convert_fn_keycode (eventRef
, keycode
, &xkeysym
))
10107 inev
.code
= xkeysym
;
10108 /* this doesn't work - tried to add shift modifiers */
10110 backtranslate_modified_keycode(er
.modifiers
& (~0x2200),
10111 xkeysym
| 0x80, xkeysym
);
10112 inev
.kind
= ASCII_KEYSTROKE_EVENT
;
10116 if (keycode_to_xkeysym (keycode
, &xkeysym
))
10118 inev
.code
= 0xff00 | xkeysym
;
10119 inev
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
10124 backtranslate_modified_keycode(er
.modifiers
, keycode
,
10125 er
.message
& charCodeMask
);
10126 inev
.kind
= ASCII_KEYSTROKE_EVENT
;
10130 #if USE_CARBON_EVENTS
10131 inev
.modifiers
= mac_event_to_emacs_modifiers (eventRef
);
10133 inev
.modifiers
= mac_to_emacs_modifiers (er
.modifiers
);
10135 inev
.modifiers
|= (extra_keyboard_modifiers
10136 & (meta_modifier
| alt_modifier
10137 | hyper_modifier
| super_modifier
));
10138 XSETFRAME (inev
.frame_or_window
, mac_focus_frame (dpyinfo
));
10141 case kHighLevelEvent
:
10142 read_socket_inev
= &inev
;
10143 AEProcessAppleEvent (&er
);
10144 read_socket_inev
= NULL
;
10150 #if USE_CARBON_EVENTS
10151 ReleaseEvent (eventRef
);
10154 if (inev
.kind
!= NO_EVENT
)
10156 inev
.timestamp
= timestamp
;
10157 kbd_buffer_store_event_hold (&inev
, hold_quit
);
10162 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
10167 XSETFRAME (frame
, f
);
10173 any_help_event_p
= 1;
10174 gen_help_event (help_echo_string
, frame
, help_echo_window
,
10175 help_echo_object
, help_echo_pos
);
10179 help_echo_string
= Qnil
;
10180 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
10187 /* If the focus was just given to an autoraising frame,
10189 /* ??? This ought to be able to handle more than one such frame. */
10190 if (pending_autoraise_frame
)
10192 x_raise_frame (pending_autoraise_frame
);
10193 pending_autoraise_frame
= 0;
10196 #if !USE_CARBON_EVENTS
10197 /* Check which frames are still visible. We do this here because
10198 there doesn't seem to be any direct notification from the Window
10199 Manager that the visibility of a window has changed (at least,
10200 not in all cases). */
10202 Lisp_Object tail
, frame
;
10204 FOR_EACH_FRAME (tail
, frame
)
10206 struct frame
*f
= XFRAME (frame
);
10208 /* The tooltip has been drawn already. Avoid the
10209 SET_FRAME_GARBAGED in mac_handle_visibility_change. */
10210 if (EQ (frame
, tip_frame
))
10213 if (FRAME_MAC_P (f
))
10214 mac_handle_visibility_change (f
);
10224 /* Need to override CodeWarrior's input function so no conversion is
10225 done on newlines Otherwise compiled functions in .elc files will be
10226 read incorrectly. Defined in ...:MSL C:MSL
10227 Common:Source:buffer_io.c. */
10230 __convert_to_newlines (unsigned char * p
, size_t * n
)
10232 #pragma unused(p,n)
10236 __convert_from_newlines (unsigned char * p
, size_t * n
)
10238 #pragma unused(p,n)
10244 make_mac_terminal_frame (struct frame
*f
)
10249 XSETFRAME (frame
, f
);
10251 f
->output_method
= output_mac
;
10252 f
->output_data
.mac
= (struct mac_output
*)
10253 xmalloc (sizeof (struct mac_output
));
10254 bzero (f
->output_data
.mac
, sizeof (struct mac_output
));
10256 XSETFRAME (FRAME_KBOARD (f
)->Vdefault_minibuffer_frame
, f
);
10258 FRAME_COLS (f
) = 96;
10259 FRAME_LINES (f
) = 4;
10261 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
10262 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_right
;
10264 FRAME_DESIRED_CURSOR (f
) = FILLED_BOX_CURSOR
;
10266 f
->output_data
.mac
->cursor_pixel
= 0;
10267 f
->output_data
.mac
->border_pixel
= 0x00ff00;
10268 f
->output_data
.mac
->mouse_pixel
= 0xff00ff;
10269 f
->output_data
.mac
->cursor_foreground_pixel
= 0x0000ff;
10271 f
->output_data
.mac
->text_cursor
= kThemeIBeamCursor
;
10272 f
->output_data
.mac
->nontext_cursor
= kThemeArrowCursor
;
10273 f
->output_data
.mac
->modeline_cursor
= kThemeArrowCursor
;
10274 f
->output_data
.mac
->hand_cursor
= kThemePointingHandCursor
;
10275 f
->output_data
.mac
->hourglass_cursor
= kThemeWatchCursor
;
10276 f
->output_data
.mac
->horizontal_drag_cursor
= kThemeResizeLeftRightCursor
;
10278 FRAME_FONTSET (f
) = -1;
10279 f
->output_data
.mac
->explicit_parent
= 0;
10282 f
->border_width
= 0;
10284 f
->internal_border_width
= 0;
10289 f
->new_text_cols
= 0;
10290 f
->new_text_lines
= 0;
10292 SetRect (&r
, f
->left_pos
, f
->top_pos
,
10293 f
->left_pos
+ FRAME_PIXEL_WIDTH (f
),
10294 f
->top_pos
+ FRAME_PIXEL_HEIGHT (f
));
10298 if (!(FRAME_MAC_WINDOW (f
) =
10299 NewCWindow (NULL
, &r
, "\p", true, dBoxProc
,
10300 (WindowPtr
) -1, 1, (long) f
->output_data
.mac
)))
10302 /* so that update events can find this mac_output struct */
10303 f
->output_data
.mac
->mFP
= f
; /* point back to emacs frame */
10309 /* Need to be initialized for unshow_buffer in window.c. */
10310 selected_window
= f
->selected_window
;
10312 Fmodify_frame_parameters (frame
,
10313 Fcons (Fcons (Qfont
,
10314 build_string ("-*-monaco-medium-r-*--*-90-*-*-*-*-mac-roman")), Qnil
));
10315 Fmodify_frame_parameters (frame
,
10316 Fcons (Fcons (Qforeground_color
,
10317 build_string ("black")), Qnil
));
10318 Fmodify_frame_parameters (frame
,
10319 Fcons (Fcons (Qbackground_color
,
10320 build_string ("white")), Qnil
));
10325 /***********************************************************************
10327 ***********************************************************************/
10329 int mac_initialized
= 0;
10332 mac_initialize_display_info ()
10334 struct mac_display_info
*dpyinfo
= &one_mac_display_info
;
10335 GDHandle main_device_handle
;
10337 bzero (dpyinfo
, sizeof (*dpyinfo
));
10340 dpyinfo
->mac_id_name
10341 = (char *) xmalloc (SCHARS (Vinvocation_name
)
10342 + SCHARS (Vsystem_name
)
10344 sprintf (dpyinfo
->mac_id_name
, "%s@%s",
10345 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
10347 dpyinfo
->mac_id_name
= (char *) xmalloc (strlen ("Mac Display") + 1);
10348 strcpy (dpyinfo
->mac_id_name
, "Mac Display");
10351 main_device_handle
= LMGetMainDevice();
10353 dpyinfo
->reference_count
= 0;
10354 dpyinfo
->resx
= 72.0;
10355 dpyinfo
->resy
= 72.0;
10356 dpyinfo
->color_p
= TestDeviceAttribute (main_device_handle
, gdDevType
);
10358 /* HasDepth returns true if it is possible to have a 32 bit display,
10359 but this may not be what is actually used. Mac OSX can do better.
10360 CGMainDisplayID is only available on OSX 10.2 and higher, but the
10361 header for CGGetActiveDisplayList says that the first display returned
10362 is the active one, so we use that. */
10364 CGDirectDisplayID disp_id
[1];
10365 CGDisplayCount disp_count
;
10366 CGDisplayErr error_code
;
10368 error_code
= CGGetActiveDisplayList (1, disp_id
, &disp_count
);
10369 if (error_code
!= 0)
10370 error ("No display found, CGGetActiveDisplayList error %d", error_code
);
10372 dpyinfo
->n_planes
= CGDisplayBitsPerPixel (disp_id
[0]);
10375 for (dpyinfo
->n_planes
= 32; dpyinfo
->n_planes
> 0; dpyinfo
->n_planes
>>= 1)
10376 if (HasDepth (main_device_handle
, dpyinfo
->n_planes
,
10377 gdDevType
, dpyinfo
->color_p
))
10380 dpyinfo
->height
= (**main_device_handle
).gdRect
.bottom
;
10381 dpyinfo
->width
= (**main_device_handle
).gdRect
.right
;
10382 dpyinfo
->grabbed
= 0;
10383 dpyinfo
->root_window
= NULL
;
10384 dpyinfo
->image_cache
= make_image_cache ();
10386 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
10387 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10388 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10389 dpyinfo
->mouse_face_window
= Qnil
;
10390 dpyinfo
->mouse_face_overlay
= Qnil
;
10391 dpyinfo
->mouse_face_hidden
= 0;
10396 mac_make_rdb (xrm_option
)
10399 XrmDatabase database
;
10401 database
= xrm_get_preference_database (NULL
);
10403 xrm_merge_string_database (database
, xrm_option
);
10408 struct mac_display_info
*
10409 mac_term_init (display_name
, xrm_option
, resource_name
)
10410 Lisp_Object display_name
;
10412 char *resource_name
;
10414 struct mac_display_info
*dpyinfo
;
10418 if (!mac_initialized
)
10421 mac_initialized
= 1;
10424 if (x_display_list
)
10425 error ("Sorry, this version can only handle one display");
10427 mac_initialize_display_info ();
10429 dpyinfo
= &one_mac_display_info
;
10431 dpyinfo
->xrdb
= mac_make_rdb (xrm_option
);
10433 /* Put this display on the chain. */
10434 dpyinfo
->next
= x_display_list
;
10435 x_display_list
= dpyinfo
;
10437 /* Put it on x_display_name_list. */
10438 x_display_name_list
= Fcons (Fcons (display_name
,
10439 Fcons (Qnil
, dpyinfo
->xrdb
)),
10440 x_display_name_list
);
10441 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
10447 /* Get rid of display DPYINFO, assuming all frames are already gone. */
10450 x_delete_display (dpyinfo
)
10451 struct mac_display_info
*dpyinfo
;
10455 /* Discard this display from x_display_name_list and x_display_list.
10456 We can't use Fdelq because that can quit. */
10457 if (! NILP (x_display_name_list
)
10458 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10459 x_display_name_list
= XCDR (x_display_name_list
);
10464 tail
= x_display_name_list
;
10465 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10467 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10469 XSETCDR (tail
, XCDR (XCDR (tail
)));
10472 tail
= XCDR (tail
);
10476 if (x_display_list
== dpyinfo
)
10477 x_display_list
= dpyinfo
->next
;
10480 struct x_display_info
*tail
;
10482 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10483 if (tail
->next
== dpyinfo
)
10484 tail
->next
= tail
->next
->next
;
10487 /* Free the font names in the font table. */
10488 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10489 if (dpyinfo
->font_table
[i
].name
)
10491 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
10492 xfree (dpyinfo
->font_table
[i
].full_name
);
10493 xfree (dpyinfo
->font_table
[i
].name
);
10496 if (dpyinfo
->font_table
->font_encoder
)
10497 xfree (dpyinfo
->font_table
->font_encoder
);
10499 xfree (dpyinfo
->font_table
);
10500 xfree (dpyinfo
->mac_id_name
);
10502 if (x_display_list
== 0)
10504 mac_clear_font_name_table ();
10505 bzero (dpyinfo
, sizeof (*dpyinfo
));
10514 extern int inhibit_window_system
;
10515 extern int noninteractive
;
10516 CFBundleRef appsBundle
;
10519 /* No need to test if already -nw*/
10520 if (inhibit_window_system
|| noninteractive
)
10523 appsBundle
= CFBundleGetMainBundle();
10524 if (appsBundle
!= NULL
)
10526 CFStringRef cfBI
= CFSTR("CFBundleIdentifier");
10527 CFTypeRef res
= CFBundleGetValueForInfoDictionaryKey(appsBundle
, cfBI
);
10528 /* We found the bundle identifier, now we know we are valid. */
10535 /* MAC_TODO: Have this start the bundled executable */
10537 /* For now, prevent the fatal error by bringing it up in the terminal */
10538 inhibit_window_system
= 1;
10542 MakeMeTheFrontProcess ()
10544 ProcessSerialNumber psn
;
10547 err
= GetCurrentProcess (&psn
);
10549 (void) SetFrontProcess (&psn
);
10552 /***** Code to handle C-g testing *****/
10554 /* Contains the Mac modifier formed from quit_char */
10555 int mac_quit_char_modifiers
= 0;
10556 int mac_quit_char_keycode
;
10557 extern int quit_char
;
10560 mac_determine_quit_char_modifiers()
10562 /* Todo: Determine modifiers from quit_char. */
10563 UInt32 qc_modifiers
= ctrl_modifier
;
10565 /* Map modifiers */
10566 mac_quit_char_modifiers
= 0;
10567 if (qc_modifiers
& ctrl_modifier
) mac_quit_char_modifiers
|= controlKey
;
10568 if (qc_modifiers
& shift_modifier
) mac_quit_char_modifiers
|= shiftKey
;
10569 if (qc_modifiers
& alt_modifier
) mac_quit_char_modifiers
|= optionKey
;
10573 init_quit_char_handler ()
10575 /* TODO: Let this support keys other the 'g' */
10576 mac_quit_char_keycode
= 5;
10577 /* Look at <architecture/adb_kb_map.h> for details */
10578 /* http://gemma.apple.com/techpubs/mac/Toolbox/Toolbox-40.html#MARKER-9-184*/
10580 mac_determine_quit_char_modifiers();
10582 #endif /* MAC_OSX */
10590 MenuItemIndex menu_index
;
10592 err
= GetIndMenuItemWithCommandID (NULL
, kHICommandQuit
, 1,
10593 &menu
, &menu_index
);
10595 SetMenuItemCommandKey (menu
, menu_index
, false, 0);
10596 #if USE_CARBON_EVENTS
10597 EnableMenuCommand (NULL
, kHICommandPreferences
);
10598 err
= GetIndMenuItemWithCommandID (NULL
, kHICommandPreferences
, 1,
10599 &menu
, &menu_index
);
10602 SetMenuItemCommandKey (menu
, menu_index
, false, 0);
10603 InsertMenuItemTextWithCFString (menu
, NULL
,
10604 0, kMenuItemAttrSeparator
, 0);
10605 InsertMenuItemTextWithCFString (menu
, CFSTR ("About Emacs"),
10606 0, 0, kHICommandAbout
);
10608 #endif /* USE_CARBON_EVENTS */
10609 #else /* !MAC_OSX */
10610 #if USE_CARBON_EVENTS
10611 SetMenuItemCommandID (GetMenuHandle (M_APPLE
), I_ABOUT
, kHICommandAbout
);
10617 /* Set up use of X before we make the first connection. */
10619 extern frame_parm_handler mac_frame_parm_handlers
[];
10621 static struct redisplay_interface x_redisplay_interface
=
10623 mac_frame_parm_handlers
,
10627 x_clear_end_of_line
,
10629 x_after_update_window_line
,
10630 x_update_window_begin
,
10631 x_update_window_end
,
10634 0, /* flush_display_optional */
10635 x_clear_window_mouse_face
,
10636 x_get_glyph_overhangs
,
10637 x_fix_overlapping_area
,
10638 x_draw_fringe_bitmap
,
10639 0, /* define_fringe_bitmap */
10640 0, /* destroy_fringe_bitmap */
10641 mac_per_char_metric
,
10643 mac_compute_glyph_string_overhangs
,
10644 x_draw_glyph_string
,
10645 mac_define_frame_cursor
,
10646 mac_clear_frame_area
,
10647 mac_draw_window_cursor
,
10648 mac_draw_vertical_window_border
,
10649 mac_shift_glyphs_for_insert
10655 rif
= &x_redisplay_interface
;
10657 clear_frame_hook
= x_clear_frame
;
10658 ins_del_lines_hook
= x_ins_del_lines
;
10659 delete_glyphs_hook
= x_delete_glyphs
;
10660 ring_bell_hook
= XTring_bell
;
10661 reset_terminal_modes_hook
= XTreset_terminal_modes
;
10662 set_terminal_modes_hook
= XTset_terminal_modes
;
10663 update_begin_hook
= x_update_begin
;
10664 update_end_hook
= x_update_end
;
10665 set_terminal_window_hook
= XTset_terminal_window
;
10666 read_socket_hook
= XTread_socket
;
10667 frame_up_to_date_hook
= XTframe_up_to_date
;
10668 mouse_position_hook
= XTmouse_position
;
10669 frame_rehighlight_hook
= XTframe_rehighlight
;
10670 frame_raise_lower_hook
= XTframe_raise_lower
;
10672 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10673 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10674 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10675 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10677 scroll_region_ok
= 1; /* we'll scroll partial frames */
10678 char_ins_del_ok
= 1;
10679 line_ins_del_ok
= 1; /* we'll just blt 'em */
10680 fast_clear_end_of_line
= 1; /* X does this well */
10681 memory_below_frame
= 0; /* we don't remember what scrolls
10685 last_tool_bar_item
= -1;
10686 any_help_event_p
= 0;
10688 /* Try to use interrupt input; if we can't, then start polling. */
10689 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
10693 #if TARGET_API_MAC_CARBON
10695 #if USE_CARBON_EVENTS
10697 init_service_handler ();
10699 init_quit_char_handler ();
10700 #endif /* MAC_OSX */
10702 init_command_handler ();
10705 #endif /* USE_CARBON_EVENTS */
10708 init_apple_event_handler ();
10710 if (!inhibit_window_system
)
10711 MakeMeTheFrontProcess ();
10722 staticpro (&x_error_message_string
);
10723 x_error_message_string
= Qnil
;
10726 Qcontrol
= intern ("control"); staticpro (&Qcontrol
);
10727 Qmeta
= intern ("meta"); staticpro (&Qmeta
);
10728 Qalt
= intern ("alt"); staticpro (&Qalt
);
10729 Qhyper
= intern ("hyper"); staticpro (&Qhyper
);
10730 Qsuper
= intern ("super"); staticpro (&Qsuper
);
10731 Qmodifier_value
= intern ("modifier-value");
10732 staticpro (&Qmodifier_value
);
10734 Fput (Qcontrol
, Qmodifier_value
, make_number (ctrl_modifier
));
10735 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10736 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10737 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10738 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10740 #if USE_CARBON_EVENTS
10741 Qhicommand
= intern ("hicommand"); staticpro (&Qhicommand
);
10743 Qservices
= intern ("services"); staticpro (&Qservices
);
10744 Qpaste
= intern ("paste"); staticpro (&Qpaste
);
10745 Qperform
= intern ("perform"); staticpro (&Qperform
);
10750 Fprovide (intern ("mac-carbon"), Qnil
);
10753 staticpro (&Qreverse
);
10754 Qreverse
= intern ("reverse");
10756 staticpro (&x_display_name_list
);
10757 x_display_name_list
= Qnil
;
10759 staticpro (&last_mouse_scroll_bar
);
10760 last_mouse_scroll_bar
= Qnil
;
10762 staticpro (&fm_font_family_alist
);
10763 fm_font_family_alist
= Qnil
;
10766 staticpro (&atsu_font_id_hash
);
10767 atsu_font_id_hash
= Qnil
;
10770 /* We don't yet support this, but defining this here avoids whining
10771 from cus-start.el and other places, like "M-x set-variable". */
10772 DEFVAR_BOOL ("x-use-underline-position-properties",
10773 &x_use_underline_position_properties
,
10774 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
10775 nil means ignore them. If you encounter fonts with bogus
10776 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10777 to 4.1, set this to nil.
10779 NOTE: Not supported on Mac yet. */);
10780 x_use_underline_position_properties
= 0;
10782 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
10783 doc
: /* If not nil, Emacs uses toolkit scroll bars. */);
10784 #ifdef USE_TOOLKIT_SCROLL_BARS
10785 Vx_toolkit_scroll_bars
= Qt
;
10787 Vx_toolkit_scroll_bars
= Qnil
;
10790 staticpro (&last_mouse_motion_frame
);
10791 last_mouse_motion_frame
= Qnil
;
10793 /* Variables to configure modifier key assignment. */
10795 DEFVAR_LISP ("mac-control-modifier", &Vmac_control_modifier
,
10796 doc
: /* *Modifier key assumed when the Mac control key is pressed.
10797 The value can be `control', `meta', `alt', `hyper', or `super' for the
10798 respective modifier. The default is `control'. */);
10799 Vmac_control_modifier
= Qcontrol
;
10801 DEFVAR_LISP ("mac-option-modifier", &Vmac_option_modifier
,
10802 doc
: /* *Modifier key assumed when the Mac alt/option key is pressed.
10803 The value can be `control', `meta', `alt', `hyper', or `super' for the
10804 respective modifier. If the value is nil then the key will act as the
10805 normal Mac control modifier, and the option key can be used to compose
10806 characters depending on the chosen Mac keyboard setting. */);
10807 Vmac_option_modifier
= Qnil
;
10809 DEFVAR_LISP ("mac-command-modifier", &Vmac_command_modifier
,
10810 doc
: /* *Modifier key assumed when the Mac command key is pressed.
10811 The value can be `control', `meta', `alt', `hyper', or `super' for the
10812 respective modifier. The default is `meta'. */);
10813 Vmac_command_modifier
= Qmeta
;
10815 DEFVAR_LISP ("mac-function-modifier", &Vmac_function_modifier
,
10816 doc
: /* *Modifier key assumed when the Mac function key is pressed.
10817 The value can be `control', `meta', `alt', `hyper', or `super' for the
10818 respective modifier. Note that remapping the function key may lead to
10819 unexpected results for some keys on non-US/GB keyboards. */);
10820 Vmac_function_modifier
= Qnil
;
10822 DEFVAR_LISP ("mac-emulate-three-button-mouse",
10823 &Vmac_emulate_three_button_mouse
,
10824 doc
: /* *Specify a way of three button mouse emulation.
10825 The value can be nil, t, or the symbol `reverse'.
10826 nil means that no emulation should be done and the modifiers should be
10827 placed on the mouse-1 event.
10828 t means that when the option-key is held down while pressing the mouse
10829 button, the click will register as mouse-2 and while the command-key
10830 is held down, the click will register as mouse-3.
10831 The symbol `reverse' means that the option-key will register for
10832 mouse-3 and the command-key will register for mouse-2. */);
10833 Vmac_emulate_three_button_mouse
= Qnil
;
10835 #if USE_CARBON_EVENTS
10836 DEFVAR_BOOL ("mac-wheel-button-is-mouse-2", &mac_wheel_button_is_mouse_2
,
10837 doc
: /* *Non-nil if the wheel button is mouse-2 and the right click mouse-3.
10838 Otherwise, the right click will be treated as mouse-2 and the wheel
10839 button will be mouse-3. */);
10840 mac_wheel_button_is_mouse_2
= 1;
10842 DEFVAR_BOOL ("mac-pass-command-to-system", &mac_pass_command_to_system
,
10843 doc
: /* *Non-nil if command key presses are passed on to the Mac Toolbox. */);
10844 mac_pass_command_to_system
= 1;
10846 DEFVAR_BOOL ("mac-pass-control-to-system", &mac_pass_control_to_system
,
10847 doc
: /* *Non-nil if control key presses are passed on to the Mac Toolbox. */);
10848 mac_pass_control_to_system
= 1;
10852 DEFVAR_BOOL ("mac-allow-anti-aliasing", &mac_use_core_graphics
,
10853 doc
: /* *If non-nil, allow anti-aliasing.
10854 The text will be rendered using Core Graphics text rendering which
10855 may anti-alias the text. */);
10856 mac_use_core_graphics
= 0;
10858 /* Register an entry for `mac-roman' so that it can be used when
10859 creating the terminal frame on Mac OS 9 before loading
10860 term/mac-win.elc. */
10861 DEFVAR_LISP ("mac-charset-info-alist", &Vmac_charset_info_alist
,
10862 doc
: /* Alist of Emacs character sets vs text encodings and coding systems.
10863 Each entry should be of the form:
10865 (CHARSET-NAME TEXT-ENCODING CODING-SYSTEM)
10867 where CHARSET-NAME is a string used in font names to identify the
10868 charset, TEXT-ENCODING is a TextEncodingBase value in Mac, and
10869 CODING_SYSTEM is a coding system corresponding to TEXT-ENCODING. */);
10870 Vmac_charset_info_alist
=
10871 Fcons (list3 (build_string ("mac-roman"),
10872 make_number (smRoman
), Qnil
), Qnil
);
10875 /* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b
10876 (do not change this comment) */