1 /* Implementation of GUI terminal on the Mac OS.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
21 /* Contributed by Andrew Choi (akochoi@mac.com). */
29 #include "blockinput.h"
37 #if TARGET_API_MAC_CARBON
38 /* USE_CARBON_EVENTS determines if the Carbon Event Manager is used to
39 obtain events from the event queue. If set to 0, WaitNextEvent is
41 #define USE_CARBON_EVENTS 1
42 #else /* not TARGET_API_MAC_CARBON */
43 #include <Quickdraw.h>
44 #include <ToolUtils.h>
48 #include <Resources.h>
50 #include <TextUtils.h>
54 #if defined (__MRC__) || (__MSL__ >= 0x6000)
55 #include <ControlDefinitions.h>
61 #endif /* not TARGET_API_MAC_CARBON */
70 #include <sys/param.h>
75 #include "dispextern.h"
77 #include "termhooks.h"
85 #include "intervals.h"
88 #include "character.h"
91 /* Set of macros that handle mapping of Mac modifier keys to emacs. */
92 #define macCtrlKey (NILP (Vmac_reverse_ctrl_meta) ? controlKey : \
93 (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey))
94 #define macShiftKey (shiftKey)
95 #define macMetaKey (NILP (Vmac_reverse_ctrl_meta) ? \
96 (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey) \
98 #define macAltKey (NILP (Vmac_command_key_is_meta) ? cmdKey : optionKey)
101 /* Non-nil means Emacs uses toolkit scroll bars. */
103 Lisp_Object Vx_toolkit_scroll_bars
;
105 /* If Non-nil, the text will be rendered using Core Graphics text rendering which may anti-alias the text. */
106 Lisp_Object Vmac_use_core_graphics
;
109 /* Non-zero means that a HELP_EVENT has been generated since Emacs
112 static int any_help_event_p
;
114 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
115 static Lisp_Object last_window
;
117 /* This is a chain of structures for all the X displays currently in
120 struct x_display_info
*x_display_list
;
122 /* This is a list of cons cells, each of the form (NAME
123 FONT-LIST-CACHE . RESOURCE-DATABASE), one for each element of
124 x_display_list and in the same order. NAME is the name of the
125 frame. FONT-LIST-CACHE records previous values returned by
126 x-list-fonts. RESOURCE-DATABASE preserves the X Resource Database
127 equivalent, which is implemented with a Lisp object, for the
130 Lisp_Object x_display_name_list
;
132 /* This is display since Mac does not support multiple ones. */
133 struct mac_display_info one_mac_display_info
;
135 /* Frame being updated by update_frame. This is declared in term.c.
136 This is set by update_begin and looked at by all the XT functions.
137 It is zero while not inside an update. In that case, the XT
138 functions assume that `selected_frame' is the frame to apply to. */
140 extern struct frame
*updating_frame
;
142 /* This is a frame waiting to be auto-raised, within XTread_socket. */
144 struct frame
*pending_autoraise_frame
;
148 Formerly, we used PointerMotionHintMask (in standard_event_mask)
149 so that we would have to call XQueryPointer after each MotionNotify
150 event to ask for another such event. However, this made mouse tracking
151 slow, and there was a bug that made it eventually stop.
153 Simply asking for MotionNotify all the time seems to work better.
155 In order to avoid asking for motion events and then throwing most
156 of them away or busy-polling the server for mouse positions, we ask
157 the server for pointer motion hints. This means that we get only
158 one event per group of mouse movements. "Groups" are delimited by
159 other kinds of events (focus changes and button clicks, for
160 example), or by XQueryPointer calls; when one of these happens, we
161 get another MotionNotify event the next time the mouse moves. This
162 is at least as efficient as getting motion events when mouse
163 tracking is on, and I suspect only negligibly worse when tracking
166 /* Where the mouse was last time we reported a mouse event. */
168 static Rect last_mouse_glyph
;
170 /* The scroll bar in which the last X motion event occurred.
172 If the last X motion event occurred in a scroll bar, we set this so
173 XTmouse_position can know whether to report a scroll bar motion or
176 If the last X motion event didn't occur in a scroll bar, we set
177 this to Qnil, to tell XTmouse_position to return an ordinary motion
180 static Lisp_Object last_mouse_scroll_bar
;
182 /* This is a hack. We would really prefer that XTmouse_position would
183 return the time associated with the position it returns, but there
184 doesn't seem to be any way to wrest the time-stamp from the server
185 along with the position query. So, we just keep track of the time
186 of the last movement we received, and return that in hopes that
187 it's somewhat accurate. */
189 static Time last_mouse_movement_time
;
191 struct scroll_bar
*tracked_scroll_bar
= NULL
;
193 /* Incremented by XTread_socket whenever it really tries to read
197 static int volatile input_signal_count
;
199 static int input_signal_count
;
202 extern Lisp_Object Vsystem_name
;
204 /* A mask of extra modifier bits to put into every keyboard char. */
206 extern EMACS_INT extra_keyboard_modifiers
;
208 /* The keysyms to use for the various modifiers. */
210 static Lisp_Object Qalt
, Qhyper
, Qsuper
, Qmodifier_value
;
212 extern int inhibit_window_system
;
214 #if __MRC__ && !TARGET_API_MAC_CARBON
215 QDGlobals qd
; /* QuickDraw global information structure. */
218 #define mac_window_to_frame(wp) (((mac_output *) GetWRefCon (wp))->mFP)
220 struct mac_display_info
*mac_display_info_for_display (Display
*);
221 static void x_update_window_end
P_ ((struct window
*, int, int));
222 static int x_io_error_quitter
P_ ((Display
*));
223 int x_catch_errors
P_ ((Display
*));
224 void x_uncatch_errors
P_ ((Display
*, int));
225 void x_lower_frame
P_ ((struct frame
*));
226 void x_scroll_bar_clear
P_ ((struct frame
*));
227 int x_had_errors_p
P_ ((Display
*));
228 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
229 void x_raise_frame
P_ ((struct frame
*));
230 void x_set_window_size
P_ ((struct frame
*, int, int, int));
231 void x_wm_set_window_state
P_ ((struct frame
*, int));
232 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
233 void mac_initialize
P_ ((void));
234 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
235 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
236 static void x_update_end
P_ ((struct frame
*));
237 static void XTframe_up_to_date
P_ ((struct frame
*));
238 static void XTset_terminal_modes
P_ ((void));
239 static void XTreset_terminal_modes
P_ ((void));
240 static void x_clear_frame
P_ ((void));
241 static void frame_highlight
P_ ((struct frame
*));
242 static void frame_unhighlight
P_ ((struct frame
*));
243 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
244 static void mac_focus_changed
P_ ((int, struct mac_display_info
*,
245 struct frame
*, struct input_event
*));
246 static void x_detect_focus_change
P_ ((struct mac_display_info
*,
247 EventRecord
*, struct input_event
*));
248 static void XTframe_rehighlight
P_ ((struct frame
*));
249 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
250 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
251 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
252 enum text_cursor_kinds
));
254 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*, int, GC
));
255 static void x_flush
P_ ((struct frame
*f
));
256 static void x_update_begin
P_ ((struct frame
*));
257 static void x_update_window_begin
P_ ((struct window
*));
258 static void x_after_update_window_line
P_ ((struct glyph_row
*));
259 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
260 enum scroll_bar_part
*,
261 Lisp_Object
*, Lisp_Object
*,
264 static int is_emacs_window
P_ ((WindowPtr
));
266 static void XSetFont
P_ ((Display
*, GC
, XFontStruct
*));
268 /* Defined in macmenu.h. */
269 extern void menubar_selection_callback (FRAME_PTR
, int);
271 #define GC_FORE_COLOR(gc) (&(gc)->fore_color)
272 #define GC_BACK_COLOR(gc) (&(gc)->back_color)
273 #define GC_FONT(gc) ((gc)->xgcv.font)
274 #define MAC_WINDOW_NORMAL_GC(w) (((mac_output *) GetWRefCon (w))->normal_gc)
277 /* X display function emulation */
280 XFreePixmap (display
, pixmap
)
281 Display
*display
; /* not used */
284 DisposeGWorld (pixmap
);
288 /* Mac version of XDrawLine. */
291 XDrawLine (display
, w
, gc
, x1
, y1
, x2
, y2
)
297 SetPortWindowPort (w
);
299 RGBForeColor (GC_FORE_COLOR (gc
));
306 mac_draw_line_to_pixmap (display
, p
, gc
, x1
, y1
, x2
, y2
)
315 GetGWorld (&old_port
, &old_gdh
);
318 RGBForeColor (GC_FORE_COLOR (gc
));
320 LockPixels (GetGWorldPixMap (p
));
323 UnlockPixels (GetGWorldPixMap (p
));
325 SetGWorld (old_port
, old_gdh
);
330 mac_erase_rectangle (w
, gc
, x
, y
, width
, height
)
334 unsigned int width
, height
;
338 SetPortWindowPort (w
);
340 RGBBackColor (GC_BACK_COLOR (gc
));
341 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
345 RGBBackColor (GC_BACK_COLOR (MAC_WINDOW_NORMAL_GC (w
)));
349 /* Mac version of XClearArea. */
352 XClearArea (display
, w
, x
, y
, width
, height
, exposures
)
356 unsigned int width
, height
;
359 mac_erase_rectangle (w
, MAC_WINDOW_NORMAL_GC (w
), x
, y
, width
, height
);
362 /* Mac version of XClearWindow. */
365 XClearWindow (display
, w
)
369 SetPortWindowPort (w
);
371 RGBBackColor (GC_BACK_COLOR (MAC_WINDOW_NORMAL_GC (w
)));
373 #if TARGET_API_MAC_CARBON
377 GetWindowPortBounds (w
, &r
);
380 #else /* not TARGET_API_MAC_CARBON */
381 EraseRect (&(w
->portRect
));
382 #endif /* not TARGET_API_MAC_CARBON */
386 /* Mac replacement for XCopyArea. */
389 mac_draw_bitmap (display
, w
, gc
, x
, y
, width
, height
, bits
, overlay_p
)
393 int x
, y
, width
, height
;
394 unsigned short *bits
;
400 bitmap
.rowBytes
= sizeof(unsigned short);
401 bitmap
.baseAddr
= (char *)bits
;
402 SetRect (&(bitmap
.bounds
), 0, 0, width
, height
);
404 SetPortWindowPort (w
);
406 RGBForeColor (GC_FORE_COLOR (gc
));
407 RGBBackColor (GC_BACK_COLOR (gc
));
408 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
410 #if TARGET_API_MAC_CARBON
411 LockPortBits (GetWindowPort (w
));
412 CopyBits (&bitmap
, GetPortBitMapForCopyBits (GetWindowPort (w
)),
413 &(bitmap
.bounds
), &r
, overlay_p
? srcOr
: srcCopy
, 0);
414 UnlockPortBits (GetWindowPort (w
));
415 #else /* not TARGET_API_MAC_CARBON */
416 CopyBits (&bitmap
, &(w
->portBits
), &(bitmap
.bounds
), &r
,
417 overlay_p
? srcOr
: srcCopy
, 0);
418 #endif /* not TARGET_API_MAC_CARBON */
420 RGBBackColor (GC_BACK_COLOR (MAC_WINDOW_NORMAL_GC (w
)));
424 /* Mac replacement for XSetClipRectangles. */
427 mac_set_clip_rectangle (display
, w
, r
)
432 SetPortWindowPort (w
);
438 /* Mac replacement for XSetClipMask. */
441 mac_reset_clipping (display
, w
)
447 SetPortWindowPort (w
);
449 SetRect (&r
, -32767, -32767, 32767, 32767);
454 /* Mac replacement for XCreateBitmapFromBitmapData. */
457 mac_create_bitmap_from_bitmap_data (bitmap
, bits
, w
, h
)
462 static unsigned char swap_nibble
[16]
463 = { 0x0, 0x8, 0x4, 0xc, /* 0000 1000 0100 1100 */
464 0x2, 0xa, 0x6, 0xe, /* 0010 1010 0110 1110 */
465 0x1, 0x9, 0x5, 0xd, /* 0001 1001 0101 1101 */
466 0x3, 0xb, 0x7, 0xf }; /* 0011 1011 0111 1111 */
470 w1
= (w
+ 7) / 8; /* nb of 8bits elt in X bitmap */
471 bitmap
->rowBytes
= ((w
+ 15) / 16) * 2; /* nb of 16bits elt in Mac bitmap */
472 bitmap
->baseAddr
= xmalloc (bitmap
->rowBytes
* h
);
473 bzero (bitmap
->baseAddr
, bitmap
->rowBytes
* h
);
474 for (i
= 0; i
< h
; i
++)
476 p
= bitmap
->baseAddr
+ i
* bitmap
->rowBytes
;
477 for (j
= 0; j
< w1
; j
++)
479 /* Bitswap XBM bytes to match how Mac does things. */
480 unsigned char c
= *bits
++;
481 *p
++ = (unsigned char)((swap_nibble
[c
& 0xf] << 4)
482 | (swap_nibble
[(c
>>4) & 0xf]));;
486 SetRect (&(bitmap
->bounds
), 0, 0, w
, h
);
491 mac_free_bitmap (bitmap
)
494 xfree (bitmap
->baseAddr
);
499 XCreatePixmap (display
, w
, width
, height
, depth
)
500 Display
*display
; /* not used */
502 unsigned int width
, height
;
509 SetPortWindowPort (w
);
511 SetRect (&r
, 0, 0, width
, height
);
512 err
= NewGWorld (&pixmap
, depth
, &r
, NULL
, NULL
, 0);
520 XCreatePixmapFromBitmapData (display
, w
, data
, width
, height
, fg
, bg
, depth
)
521 Display
*display
; /* not used */
524 unsigned int width
, height
;
525 unsigned long fg
, bg
;
532 static GC gc
= NULL
; /* not reentrant */
535 gc
= XCreateGC (display
, w
, 0, NULL
);
537 pixmap
= XCreatePixmap (display
, w
, width
, height
, depth
);
541 GetGWorld (&old_port
, &old_gdh
);
542 SetGWorld (pixmap
, NULL
);
543 mac_create_bitmap_from_bitmap_data (&bitmap
, data
, width
, height
);
544 XSetForeground (display
, gc
, fg
);
545 XSetBackground (display
, gc
, bg
);
546 RGBForeColor (GC_FORE_COLOR (gc
));
547 RGBBackColor (GC_BACK_COLOR (gc
));
548 LockPixels (GetGWorldPixMap (pixmap
));
549 #if TARGET_API_MAC_CARBON
550 CopyBits (&bitmap
, GetPortBitMapForCopyBits (pixmap
),
551 &bitmap
.bounds
, &bitmap
.bounds
, srcCopy
, 0);
552 #else /* not TARGET_API_MAC_CARBON */
553 CopyBits (&bitmap
, &(((GrafPtr
)pixmap
)->portBits
),
554 &bitmap
.bounds
, &bitmap
.bounds
, srcCopy
, 0);
555 #endif /* not TARGET_API_MAC_CARBON */
556 UnlockPixels (GetGWorldPixMap (pixmap
));
557 SetGWorld (old_port
, old_gdh
);
558 mac_free_bitmap (&bitmap
);
564 /* Mac replacement for XFillRectangle. */
567 XFillRectangle (display
, w
, gc
, x
, y
, width
, height
)
572 unsigned int width
, height
;
576 SetPortWindowPort (w
);
578 RGBForeColor (GC_FORE_COLOR (gc
));
579 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
581 PaintRect (&r
); /* using foreground color of gc */
585 #if 0 /* TODO: figure out if we need to do this on Mac. */
587 mac_fill_rectangle_to_pixmap (display
, p
, gc
, x
, y
, width
, height
)
592 unsigned int width
, height
;
598 GetGWorld (&old_port
, &old_gdh
);
600 RGBForeColor (GC_FORE_COLOR (gc
));
601 SetRect (&r
, x
, y
, x
+ width
, y
+ height
);
603 LockPixels (GetGWorldPixMap (p
));
604 PaintRect (&r
); /* using foreground color of gc */
605 UnlockPixels (GetGWorldPixMap (p
));
607 SetGWorld (old_port
, old_gdh
);
612 /* Mac replacement for XDrawRectangle: dest is a window. */
615 mac_draw_rectangle (display
, w
, gc
, x
, y
, width
, height
)
620 unsigned int width
, height
;
624 SetPortWindowPort (w
);
626 RGBForeColor (GC_FORE_COLOR (gc
));
627 SetRect (&r
, x
, y
, x
+ width
+ 1, y
+ height
+ 1);
629 FrameRect (&r
); /* using foreground color of gc */
633 #if 0 /* TODO: figure out if we need to do this on Mac. */
634 /* Mac replacement for XDrawRectangle: dest is a Pixmap. */
637 mac_draw_rectangle_to_pixmap (display
, p
, gc
, x
, y
, width
, height
)
642 unsigned int width
, height
;
648 GetGWorld (&old_port
, &old_gdh
);
650 RGBForeColor (GC_FORE_COLOR (gc
));
651 SetRect (&r
, x
, y
, x
+ width
+ 1, y
+ height
+ 1);
653 LockPixels (GetGWorldPixMap (p
));
654 FrameRect (&r
); /* using foreground color of gc */
655 UnlockPixels (GetGWorldPixMap (p
));
657 SetGWorld (old_port
, old_gdh
);
663 mac_draw_string_common (display
, w
, gc
, x
, y
, buf
, nchars
, mode
,
670 int nchars
, mode
, bytes_per_char
;
672 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
673 UInt32 textFlags
, savedFlags
;
674 if (!NILP(Vmac_use_core_graphics
)) {
675 textFlags
= kQDUseCGTextRendering
;
676 savedFlags
= SwapQDTextFlags(textFlags
);
680 SetPortWindowPort (w
);
682 RGBForeColor (GC_FORE_COLOR (gc
));
684 RGBBackColor (GC_BACK_COLOR (gc
));
686 TextFont (GC_FONT (gc
)->mac_fontnum
);
687 TextSize (GC_FONT (gc
)->mac_fontsize
);
688 TextFace (GC_FONT (gc
)->mac_fontface
);
692 DrawText (buf
, 0, nchars
* bytes_per_char
);
695 RGBBackColor (GC_BACK_COLOR (MAC_WINDOW_NORMAL_GC (w
)));
696 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
697 if (!NILP(Vmac_use_core_graphics
))
698 SwapQDTextFlags(savedFlags
);
703 /* Mac replacement for XDrawString. */
706 XDrawString (display
, w
, gc
, x
, y
, buf
, nchars
)
714 mac_draw_string_common (display
, w
, gc
, x
, y
, buf
, nchars
, srcOr
, 1);
718 /* Mac replacement for XDrawString16. */
721 XDrawString16 (display
, w
, gc
, x
, y
, buf
, nchars
)
729 mac_draw_string_common (display
, w
, gc
, x
, y
, (char *) buf
, nchars
, srcOr
,
734 /* Mac replacement for XDrawImageString. */
737 XDrawImageString (display
, w
, gc
, x
, y
, buf
, nchars
)
745 mac_draw_string_common (display
, w
, gc
, x
, y
, buf
, nchars
, srcCopy
, 1);
749 /* Mac replacement for XDrawString16. */
752 XDrawImageString16 (display
, w
, gc
, x
, y
, buf
, nchars
)
760 mac_draw_string_common (display
, w
, gc
, x
, y
, (char *) buf
, nchars
, srcCopy
,
765 /* Mac replacement for XCopyArea: dest must be window. */
768 mac_copy_area (display
, src
, dest
, gc
, src_x
, src_y
, width
, height
, dest_x
,
775 unsigned int width
, height
;
780 SetPortWindowPort (dest
);
782 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
783 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
785 ForeColor (blackColor
);
786 BackColor (whiteColor
);
788 LockPixels (GetGWorldPixMap (src
));
789 #if TARGET_API_MAC_CARBON
790 LockPortBits (GetWindowPort (dest
));
791 CopyBits (GetPortBitMapForCopyBits (src
),
792 GetPortBitMapForCopyBits (GetWindowPort (dest
)),
793 &src_r
, &dest_r
, srcCopy
, 0);
794 UnlockPortBits (GetWindowPort (dest
));
795 #else /* not TARGET_API_MAC_CARBON */
796 CopyBits (&(((GrafPtr
)src
)->portBits
), &(dest
->portBits
),
797 &src_r
, &dest_r
, srcCopy
, 0);
798 #endif /* not TARGET_API_MAC_CARBON */
799 UnlockPixels (GetGWorldPixMap (src
));
804 mac_copy_area_with_mask (display
, src
, mask
, dest
, gc
, src_x
, src_y
,
805 width
, height
, dest_x
, dest_y
)
811 unsigned int width
, height
;
816 SetPortWindowPort (dest
);
818 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
819 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
821 ForeColor (blackColor
);
822 BackColor (whiteColor
);
824 LockPixels (GetGWorldPixMap (src
));
825 LockPixels (GetGWorldPixMap (mask
));
826 #if TARGET_API_MAC_CARBON
827 LockPortBits (GetWindowPort (dest
));
828 CopyMask (GetPortBitMapForCopyBits (src
), GetPortBitMapForCopyBits (mask
),
829 GetPortBitMapForCopyBits (GetWindowPort (dest
)),
830 &src_r
, &src_r
, &dest_r
);
831 UnlockPortBits (GetWindowPort (dest
));
832 #else /* not TARGET_API_MAC_CARBON */
833 CopyMask (&(((GrafPtr
)src
)->portBits
), &(((GrafPtr
)mask
)->portBits
),
834 &(dest
->portBits
), &src_r
, &src_r
, &dest_r
);
835 #endif /* not TARGET_API_MAC_CARBON */
836 UnlockPixels (GetGWorldPixMap (mask
));
837 UnlockPixels (GetGWorldPixMap (src
));
841 /* Mac replacement for XCopyArea: used only for scrolling. */
844 mac_scroll_area (display
, w
, gc
, src_x
, src_y
, width
, height
, dest_x
, dest_y
)
849 unsigned int width
, height
;
852 #if TARGET_API_MAC_CARBON
854 RgnHandle dummy
= NewRgn (); /* For avoiding update events. */
856 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
857 ScrollWindowRect (w
, &src_r
, dest_x
- src_x
, dest_y
- src_y
,
858 kScrollWindowNoOptions
, dummy
);
860 #else /* not TARGET_API_MAC_CARBON */
865 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
866 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
868 /* In Color QuickDraw, set ForeColor and BackColor as follows to avoid
869 color mapping in CopyBits. Otherwise, it will be slow. */
870 ForeColor (blackColor
);
871 BackColor (whiteColor
);
872 CopyBits (&(w
->portBits
), &(w
->portBits
), &src_r
, &dest_r
, srcCopy
, 0);
874 RGBBackColor (GC_BACK_COLOR (MAC_WINDOW_NORMAL_GC (w
)));
875 #endif /* not TARGET_API_MAC_CARBON */
879 #if 0 /* TODO: figure out if we need to do this on Mac. */
880 /* Mac replacement for XCopyArea: dest must be Pixmap. */
883 mac_copy_area_to_pixmap (display
, src
, dest
, gc
, src_x
, src_y
, width
, height
,
889 unsigned int width
, height
;
896 GetGWorld (&old_port
, &old_gdh
);
897 SetGWorld (dest
, NULL
);
898 ForeColor (blackColor
);
899 BackColor (whiteColor
);
901 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
902 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
904 LockPixels (GetGWorldPixMap (src
));
905 LockPixels (GetGWorldPixMap (dest
));
906 #if TARGET_API_MAC_CARBON
907 CopyBits (GetPortBitMapForCopyBits (src
), GetPortBitMapForCopyBits (dest
),
908 &src_r
, &dest_r
, srcCopy
, 0);
909 #else /* not TARGET_API_MAC_CARBON */
910 CopyBits (&(((GrafPtr
)src
)->portBits
), &(((GrafPtr
)dest
)->portBits
),
911 &src_r
, &dest_r
, srcCopy
, 0);
912 #endif /* not TARGET_API_MAC_CARBON */
913 UnlockPixels (GetGWorldPixMap (dest
));
914 UnlockPixels (GetGWorldPixMap (src
));
916 SetGWorld (old_port
, old_gdh
);
921 mac_copy_area_with_mask_to_pixmap (display
, src
, mask
, dest
, gc
, src_x
, src_y
,
922 width
, height
, dest_x
, dest_y
)
924 Pixmap src
, mask
, dest
;
927 unsigned int width
, height
;
934 GetGWorld (&old_port
, &old_gdh
);
935 SetGWorld (dest
, NULL
);
936 ForeColor (blackColor
);
937 BackColor (whiteColor
);
939 SetRect (&src_r
, src_x
, src_y
, src_x
+ width
, src_y
+ height
);
940 SetRect (&dest_r
, dest_x
, dest_y
, dest_x
+ width
, dest_y
+ height
);
942 LockPixels (GetGWorldPixMap (src
));
943 LockPixels (GetGWorldPixMap (mask
));
944 LockPixels (GetGWorldPixMap (dest
));
945 #if TARGET_API_MAC_CARBON
946 CopyMask (GetPortBitMapForCopyBits (src
), GetPortBitMapForCopyBits (mask
),
947 GetPortBitMapForCopyBits (dest
), &src_r
, &src_r
, &dest_r
);
948 #else /* not TARGET_API_MAC_CARBON */
949 CopyMask (&(((GrafPtr
)src
)->portBits
), &(((GrafPtr
)mask
)->portBits
),
950 &(((GrafPtr
)dest
)->portBits
), &src_r
, &src_r
, &dest_r
);
951 #endif /* not TARGET_API_MAC_CARBON */
952 UnlockPixels (GetGWorldPixMap (dest
));
953 UnlockPixels (GetGWorldPixMap (mask
));
954 UnlockPixels (GetGWorldPixMap (src
));
956 SetGWorld (old_port
, old_gdh
);
961 /* Mac replacement for XChangeGC. */
964 XChangeGC (display
, gc
, mask
, xgcv
)
970 if (mask
& GCForeground
)
971 XSetForeground (display
, gc
, xgcv
->foreground
);
972 if (mask
& GCBackground
)
973 XSetBackground (display
, gc
, xgcv
->background
);
975 XSetFont (display
, gc
, xgcv
->font
);
979 /* Mac replacement for XCreateGC. */
982 XCreateGC (display
, window
, mask
, xgcv
)
988 GC gc
= xmalloc (sizeof (*gc
));
992 bzero (gc
, sizeof (*gc
));
993 XChangeGC (display
, gc
, mask
, xgcv
);
1000 /* Used in xfaces.c. */
1003 XFreeGC (display
, gc
)
1011 /* Mac replacement for XGetGCValues. */
1014 XGetGCValues (display
, gc
, mask
, xgcv
)
1020 if (mask
& GCForeground
)
1021 xgcv
->foreground
= gc
->xgcv
.foreground
;
1022 if (mask
& GCBackground
)
1023 xgcv
->background
= gc
->xgcv
.background
;
1025 xgcv
->font
= gc
->xgcv
.font
;
1029 /* Mac replacement for XSetForeground. */
1032 XSetForeground (display
, gc
, color
)
1035 unsigned long color
;
1037 if (gc
->xgcv
.foreground
!= color
)
1039 gc
->xgcv
.foreground
= color
;
1040 gc
->fore_color
.red
= RED16_FROM_ULONG (color
);
1041 gc
->fore_color
.green
= GREEN16_FROM_ULONG (color
);
1042 gc
->fore_color
.blue
= BLUE16_FROM_ULONG (color
);
1047 /* Mac replacement for XSetBackground. */
1050 XSetBackground (display
, gc
, color
)
1053 unsigned long color
;
1055 if (gc
->xgcv
.background
!= color
)
1057 gc
->xgcv
.background
= color
;
1058 gc
->back_color
.red
= RED16_FROM_ULONG (color
);
1059 gc
->back_color
.green
= GREEN16_FROM_ULONG (color
);
1060 gc
->back_color
.blue
= BLUE16_FROM_ULONG (color
);
1065 /* Mac replacement for XSetFont. */
1068 XSetFont (display
, gc
, font
)
1073 gc
->xgcv
.font
= font
;
1077 /* Mac replacement for XSetWindowBackground. */
1080 XSetWindowBackground (display
, w
, color
)
1083 unsigned long color
;
1085 #if !TARGET_API_MAC_CARBON
1086 AuxWinHandle aw_handle
;
1087 CTabHandle ctab_handle
;
1088 ColorSpecPtr ct_table
;
1093 bg_color
.red
= RED16_FROM_ULONG (color
);
1094 bg_color
.green
= GREEN16_FROM_ULONG (color
);
1095 bg_color
.blue
= BLUE16_FROM_ULONG (color
);
1097 #if TARGET_API_MAC_CARBON
1098 SetWindowContentColor (w
, &bg_color
);
1100 if (GetAuxWin (w
, &aw_handle
))
1102 ctab_handle
= (*aw_handle
)->awCTable
;
1103 HandToHand ((Handle
*) &ctab_handle
);
1104 ct_table
= (*ctab_handle
)->ctTable
;
1105 ct_size
= (*ctab_handle
)->ctSize
;
1106 while (ct_size
> -1)
1108 if (ct_table
->value
== 0)
1110 ct_table
->rgb
= bg_color
;
1111 CTabChanged (ctab_handle
);
1112 SetWinColor (w
, (WCTabHandle
) ctab_handle
);
1120 /* x_sync is a no-op on Mac. */
1128 /* Flush display of frame F, or of all frames if F is null. */
1134 #if TARGET_API_MAC_CARBON
1137 QDFlushPortBuffer (GetWindowPort (FRAME_MAC_WINDOW (f
)), NULL
);
1139 QDFlushPortBuffer (GetQDGlobalsThePort (), NULL
);
1145 /* Remove calls to XFlush by defining XFlush to an empty replacement.
1146 Calls to XFlush should be unnecessary because the X output buffer
1147 is flushed automatically as needed by calls to XPending,
1148 XNextEvent, or XWindowEvent according to the XFlush man page.
1149 XTread_socket calls XPending. Removing XFlush improves
1152 #define XFlush(DISPLAY) (void) 0
1155 /* Return the struct mac_display_info corresponding to DPY. There's
1158 struct mac_display_info
*
1159 mac_display_info_for_display (dpy
)
1162 return &one_mac_display_info
;
1167 /***********************************************************************
1168 Starting and ending an update
1169 ***********************************************************************/
1171 /* Start an update of frame F. This function is installed as a hook
1172 for update_begin, i.e. it is called when update_begin is called.
1173 This function is called prior to calls to x_update_window_begin for
1174 each window being updated. */
1180 #if TARGET_API_MAC_CARBON
1181 /* During update of a frame, availability of input events is
1182 periodically checked with ReceiveNextEvent if
1183 redisplay-dont-pause is nil. That normally flushes window buffer
1184 changes for every check, and thus screen update looks waving even
1185 if no input is available. So we disable screen updates during
1186 update of a frame. */
1188 DisableScreenUpdates ();
1194 /* Start update of window W. Set the global variable updated_window
1195 to the window being updated and set output_cursor to the cursor
1199 x_update_window_begin (w
)
1202 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1203 struct mac_display_info
*display_info
= FRAME_MAC_DISPLAY_INFO (f
);
1206 set_output_cursor (&w
->cursor
);
1210 if (f
== display_info
->mouse_face_mouse_frame
)
1212 /* Don't do highlighting for mouse motion during the update. */
1213 display_info
->mouse_face_defer
= 1;
1215 /* If F needs to be redrawn, simply forget about any prior mouse
1217 if (FRAME_GARBAGED_P (f
))
1218 display_info
->mouse_face_window
= Qnil
;
1220 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
1221 their mouse_face_p flag set, which means that they are always
1222 unequal to rows in a desired matrix which never have that
1223 flag set. So, rows containing mouse-face glyphs are never
1224 scrolled, and we don't have to switch the mouse highlight off
1225 here to prevent it from being scrolled. */
1227 /* Can we tell that this update does not affect the window
1228 where the mouse highlight is? If so, no need to turn off.
1229 Likewise, don't do anything if the frame is garbaged;
1230 in that case, the frame's current matrix that we would use
1231 is all wrong, and we will redisplay that line anyway. */
1232 if (!NILP (display_info
->mouse_face_window
)
1233 && w
== XWINDOW (display_info
->mouse_face_window
))
1237 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
1238 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
1241 if (i
< w
->desired_matrix
->nrows
)
1242 clear_mouse_face (display_info
);
1251 /* Draw a vertical window border from (x,y0) to (x,y1) */
1254 mac_draw_vertical_window_border (w
, x
, y0
, y1
)
1258 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1261 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
1263 XSetForeground (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->normal_gc
,
1266 XDrawLine (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
1267 f
->output_data
.mac
->normal_gc
, x
, y0
, x
, y1
);
1270 /* End update of window W (which is equal to updated_window).
1272 Draw vertical borders between horizontally adjacent windows, and
1273 display W's cursor if CURSOR_ON_P is non-zero.
1275 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
1276 glyphs in mouse-face were overwritten. In that case we have to
1277 make sure that the mouse-highlight is properly redrawn.
1279 W may be a menu bar pseudo-window in case we don't have X toolkit
1280 support. Such windows don't have a cursor, so don't display it
1284 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
1286 int cursor_on_p
, mouse_face_overwritten_p
;
1288 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (XFRAME (w
->frame
));
1290 if (!w
->pseudo_window_p
)
1295 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
1297 output_cursor
.x
, output_cursor
.y
);
1299 if (draw_window_fringes (w
, 1))
1300 x_draw_vertical_border (w
);
1305 /* If a row with mouse-face was overwritten, arrange for
1306 XTframe_up_to_date to redisplay the mouse highlight. */
1307 if (mouse_face_overwritten_p
)
1309 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
1310 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
1311 dpyinfo
->mouse_face_window
= Qnil
;
1314 updated_window
= NULL
;
1318 /* End update of frame F. This function is installed as a hook in
1325 /* Mouse highlight may be displayed again. */
1326 FRAME_MAC_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
1329 #if TARGET_API_MAC_CARBON
1330 EnableScreenUpdates ();
1332 XFlush (FRAME_MAC_DISPLAY (f
));
1337 /* This function is called from various places in xdisp.c whenever a
1338 complete update has been performed. The global variable
1339 updated_window is not available here. */
1342 XTframe_up_to_date (f
)
1345 if (FRAME_MAC_P (f
))
1347 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
1349 if (dpyinfo
->mouse_face_deferred_gc
1350 || f
== dpyinfo
->mouse_face_mouse_frame
)
1353 if (dpyinfo
->mouse_face_mouse_frame
)
1354 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
1355 dpyinfo
->mouse_face_mouse_x
,
1356 dpyinfo
->mouse_face_mouse_y
);
1357 dpyinfo
->mouse_face_deferred_gc
= 0;
1364 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
1365 arrow bitmaps, or clear the fringes if no bitmaps are required
1366 before DESIRED_ROW is made current. The window being updated is
1367 found in updated_window. This function is called from
1368 update_window_line only if it is known that there are differences
1369 between bitmaps to be drawn between current row and DESIRED_ROW. */
1372 x_after_update_window_line (desired_row
)
1373 struct glyph_row
*desired_row
;
1375 struct window
*w
= updated_window
;
1381 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
1382 desired_row
->redraw_fringe_bitmaps_p
= 1;
1384 /* When a window has disappeared, make sure that no rest of
1385 full-width rows stays visible in the internal border. Could
1386 check here if updated_window is the leftmost/rightmost window,
1387 but I guess it's not worth doing since vertically split windows
1388 are almost never used, internal border is rarely set, and the
1389 overhead is very small. */
1390 if (windows_or_buffers_changed
1391 && desired_row
->full_width_p
1392 && (f
= XFRAME (w
->frame
),
1393 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
1395 && (height
= desired_row
->visible_height
,
1398 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
1400 /* Internal border is drawn below the tool bar. */
1401 if (WINDOWP (f
->tool_bar_window
)
1402 && w
== XWINDOW (f
->tool_bar_window
))
1406 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
1407 0, y
, width
, height
, 0);
1408 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
1409 FRAME_PIXEL_WIDTH (f
) - width
, y
,
1416 /* Draw the bitmap WHICH in one of the left or right fringes of
1417 window W. ROW is the glyph row for which to display the bitmap; it
1418 determines the vertical position at which the bitmap has to be
1422 x_draw_fringe_bitmap (w
, row
, p
)
1424 struct glyph_row
*row
;
1425 struct draw_fringe_bitmap_params
*p
;
1427 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1428 Display
*display
= FRAME_MAC_DISPLAY (f
);
1429 WindowPtr window
= FRAME_MAC_WINDOW (f
);
1430 GC gc
= f
->output_data
.mac
->normal_gc
;
1431 struct face
*face
= p
->face
;
1434 /* Must clip because of partially visible lines. */
1435 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
1438 /* Adjust position of "bottom aligned" bitmap on partially
1439 visible last row. */
1441 int oldVH
= row
->visible_height
;
1442 row
->visible_height
= p
->h
;
1443 row
->y
-= rowY
- p
->y
;
1444 x_clip_to_row (w
, row
, -1, gc
);
1446 row
->visible_height
= oldVH
;
1449 x_clip_to_row (w
, row
, -1, gc
);
1451 if (p
->bx
>= 0 && !p
->overlay_p
)
1453 #if 0 /* MAC_TODO: stipple */
1454 /* In case the same realized face is used for fringes and
1455 for something displayed in the text (e.g. face `region' on
1456 mono-displays, the fill style may have been changed to
1457 FillSolid in x_draw_glyph_string_background. */
1459 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
1461 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
1464 mac_erase_rectangle (window
, face
->gc
, p
->bx
, p
->by
, p
->nx
, p
->ny
);
1466 #if 0 /* MAC_TODO: stipple */
1468 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
1474 unsigned short *bits
= p
->bits
+ p
->dh
;
1477 XGetGCValues (display
, face
->gc
, GCForeground
, &gcv
);
1478 XSetForeground (display
, face
->gc
,
1480 ? (p
->overlay_p
? face
->background
1481 : f
->output_data
.mac
->cursor_pixel
)
1482 : face
->foreground
));
1483 mac_draw_bitmap (display
, window
, face
->gc
, p
->x
, p
->y
,
1484 p
->wd
, p
->h
, bits
, p
->overlay_p
);
1485 XSetForeground (display
, face
->gc
, gcv
.foreground
);
1488 mac_reset_clipping (display
, window
);
1493 /* This is called when starting Emacs and when restarting after
1494 suspend. When starting Emacs, no window is mapped. And nothing
1495 must be done to Emacs's own window if it is suspended (though that
1499 XTset_terminal_modes ()
1503 /* This is called when exiting or suspending Emacs. Exiting will make
1504 the windows go away, and suspending requires no action. */
1507 XTreset_terminal_modes ()
1513 /***********************************************************************
1515 ***********************************************************************/
1517 /* Function prototypes of this page. */
1519 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1520 static int mac_encode_char
P_ ((int, XChar2b
*, struct font_info
*,
1521 struct charset
*, int *));
1524 /* Return a pointer to per-char metric information in FONT of a
1525 character pointed by B which is a pointer to an XChar2b. */
1527 #define PER_CHAR_METRIC(font, b) \
1529 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
1530 + (((font)->min_byte1 || (font)->max_byte1) \
1531 ? (((b)->byte1 - (font)->min_byte1) \
1532 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
1534 : &((font)->max_bounds))
1537 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1538 is not contained in the font. */
1540 static INLINE XCharStruct
*
1541 x_per_char_metric (font
, char2b
)
1545 /* The result metric information. */
1546 XCharStruct
*pcm
= NULL
;
1548 xassert (font
&& char2b
);
1550 if (font
->per_char
!= NULL
)
1552 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1554 /* min_char_or_byte2 specifies the linear character index
1555 corresponding to the first element of the per_char array,
1556 max_char_or_byte2 is the index of the last character. A
1557 character with non-zero CHAR2B->byte1 is not in the font.
1558 A character with byte2 less than min_char_or_byte2 or
1559 greater max_char_or_byte2 is not in the font. */
1560 if (char2b
->byte1
== 0
1561 && char2b
->byte2
>= font
->min_char_or_byte2
1562 && char2b
->byte2
<= font
->max_char_or_byte2
)
1563 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1567 /* If either min_byte1 or max_byte1 are nonzero, both
1568 min_char_or_byte2 and max_char_or_byte2 are less than
1569 256, and the 2-byte character index values corresponding
1570 to the per_char array element N (counting from 0) are:
1572 byte1 = N/D + min_byte1
1573 byte2 = N\D + min_char_or_byte2
1577 D = max_char_or_byte2 - min_char_or_byte2 + 1
1578 / = integer division
1579 \ = integer modulus */
1580 if (char2b
->byte1
>= font
->min_byte1
1581 && char2b
->byte1
<= font
->max_byte1
1582 && char2b
->byte2
>= font
->min_char_or_byte2
1583 && char2b
->byte2
<= font
->max_char_or_byte2
)
1585 pcm
= (font
->per_char
1586 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1587 * (char2b
->byte1
- font
->min_byte1
))
1588 + (char2b
->byte2
- font
->min_char_or_byte2
));
1594 /* If the per_char pointer is null, all glyphs between the first
1595 and last character indexes inclusive have the same
1596 information, as given by both min_bounds and max_bounds. */
1597 if (char2b
->byte2
>= font
->min_char_or_byte2
1598 && char2b
->byte2
<= font
->max_char_or_byte2
)
1599 pcm
= &font
->max_bounds
;
1602 return ((pcm
== NULL
1603 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1610 static XCharStruct
*
1611 mac_per_char_metric (font
, char2b
, font_type
)
1616 return x_per_char_metric (font
, char2b
);
1620 Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1621 the two-byte form of C. Encoding is returned in *CHAR2B. */
1624 mac_encode_char (c
, char2b
, font_info
, charset
, two_byte_p
)
1627 struct font_info
*font_info
;
1628 struct charset
*charset
;
1631 XFontStruct
*font
= font_info
->font
;
1633 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1634 This may be either a program in a special encoder language or a
1636 if (font_info
->font_encoder
)
1638 /* It's a program. */
1639 struct ccl_program
*ccl
= font_info
->font_encoder
;
1641 check_ccl_update (ccl
);
1642 if (CHARSET_DIMENSION (charset
) == 1)
1644 ccl
->reg
[0] = CHARSET_ID (charset
);
1645 ccl
->reg
[1] = XCHAR2B_BYTE2 (char2b
);
1650 ccl
->reg
[0] = CHARSET_ID (charset
);
1651 ccl
->reg
[1] = XCHAR2B_BYTE1 (char2b
);
1652 ccl
->reg
[2] = XCHAR2B_BYTE2 (char2b
);
1655 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1657 /* We assume that MSBs are appropriately set/reset by CCL
1659 if (font
->max_byte1
== 0) /* 1-byte font */
1660 STORE_XCHAR2B (char2b
, 0, ccl
->reg
[1]);
1662 STORE_XCHAR2B (char2b
, ccl
->reg
[1], ccl
->reg
[2]);
1664 else if (font_info
->encoding_type
)
1666 /* Fixed encoding scheme. See fontset.h for the meaning of the
1667 encoding numbers. */
1668 unsigned char enc
= font_info
->encoding_type
;
1670 if ((enc
== 1 || enc
== 2)
1671 && CHARSET_DIMENSION (charset
) == 2)
1672 char2b
->byte1
|= 0x80;
1674 if (enc
== 1 || enc
== 3)
1675 char2b
->byte2
|= 0x80;
1682 ENCODE_SJIS (char2b->byte1, char2b->byte2, sjis1, sjis2);
1683 char2b->byte1 = sjis1;
1684 char2b->byte2 = sjis2;
1690 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1692 return FONT_TYPE_UNKNOWN
;
1697 /***********************************************************************
1699 ***********************************************************************/
1703 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
1704 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
1705 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
1707 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
1708 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
1709 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
1710 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
1711 static void mac_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
1712 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
1713 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
1714 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
1715 /*static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap,
1716 unsigned long *, double, int));*/
1717 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
1718 double, int, unsigned long));
1719 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
1720 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
1721 static void x_draw_image_relief
P_ ((struct glyph_string
*));
1722 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
1723 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
1724 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
1726 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
1727 int, int, int, int, int, int,
1729 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
1730 int, int, int, Rect
*));
1733 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
1737 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
1742 struct glyph_string
*s
;
1744 if (s
->font
== FRAME_FONT (s
->f
)
1745 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
1746 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
1748 s
->gc
= s
->f
->output_data
.mac
->cursor_gc
;
1751 /* Cursor on non-default face: must merge. */
1755 xgcv
.background
= s
->f
->output_data
.mac
->cursor_pixel
;
1756 xgcv
.foreground
= s
->face
->background
;
1758 /* If the glyph would be invisible, try a different foreground. */
1759 if (xgcv
.foreground
== xgcv
.background
)
1760 xgcv
.foreground
= s
->face
->foreground
;
1761 if (xgcv
.foreground
== xgcv
.background
)
1762 xgcv
.foreground
= s
->f
->output_data
.mac
->cursor_foreground_pixel
;
1763 if (xgcv
.foreground
== xgcv
.background
)
1764 xgcv
.foreground
= s
->face
->foreground
;
1766 /* Make sure the cursor is distinct from text in this face. */
1767 if (xgcv
.background
== s
->face
->background
1768 && xgcv
.foreground
== s
->face
->foreground
)
1770 xgcv
.background
= s
->face
->foreground
;
1771 xgcv
.foreground
= s
->face
->background
;
1774 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1775 xgcv
.font
= s
->font
;
1776 mask
= GCForeground
| GCBackground
| GCFont
;
1778 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1779 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1782 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1783 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1785 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1790 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1793 x_set_mouse_face_gc (s
)
1794 struct glyph_string
*s
;
1799 /* What face has to be used last for the mouse face? */
1800 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
1801 face
= FACE_FROM_ID (s
->f
, face_id
);
1803 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1805 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1806 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1808 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1809 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1810 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1812 /* If font in this face is same as S->font, use it. */
1813 if (s
->font
== s
->face
->font
)
1814 s
->gc
= s
->face
->gc
;
1817 /* Otherwise construct scratch_cursor_gc with values from FACE
1822 xgcv
.background
= s
->face
->background
;
1823 xgcv
.foreground
= s
->face
->foreground
;
1824 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1825 xgcv
.font
= s
->font
;
1826 mask
= GCForeground
| GCBackground
| GCFont
;
1828 if (FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1829 XChangeGC (s
->display
, FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1832 FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1833 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1835 s
->gc
= FRAME_MAC_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1838 xassert (s
->gc
!= 0);
1842 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1843 Faces to use in the mode line have already been computed when the
1844 matrix was built, so there isn't much to do, here. */
1847 x_set_mode_line_face_gc (s
)
1848 struct glyph_string
*s
;
1850 s
->gc
= s
->face
->gc
;
1854 /* Set S->gc of glyph string S for drawing that glyph string. Set
1855 S->stippled_p to a non-zero value if the face of S has a stipple
1859 x_set_glyph_string_gc (s
)
1860 struct glyph_string
*s
;
1862 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1864 if (s
->hl
== DRAW_NORMAL_TEXT
)
1866 s
->gc
= s
->face
->gc
;
1867 s
->stippled_p
= s
->face
->stipple
!= 0;
1869 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1871 x_set_mode_line_face_gc (s
);
1872 s
->stippled_p
= s
->face
->stipple
!= 0;
1874 else if (s
->hl
== DRAW_CURSOR
)
1876 x_set_cursor_gc (s
);
1879 else if (s
->hl
== DRAW_MOUSE_FACE
)
1881 x_set_mouse_face_gc (s
);
1882 s
->stippled_p
= s
->face
->stipple
!= 0;
1884 else if (s
->hl
== DRAW_IMAGE_RAISED
1885 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1887 s
->gc
= s
->face
->gc
;
1888 s
->stippled_p
= s
->face
->stipple
!= 0;
1892 s
->gc
= s
->face
->gc
;
1893 s
->stippled_p
= s
->face
->stipple
!= 0;
1896 /* GC must have been set. */
1897 xassert (s
->gc
!= 0);
1901 /* Set clipping for output of glyph string S. S may be part of a mode
1902 line or menu if we don't have X toolkit support. */
1905 x_set_glyph_string_clipping (s
)
1906 struct glyph_string
*s
;
1909 get_glyph_string_clip_rect (s
, &r
);
1910 mac_set_clip_rectangle (s
->display
, s
->window
, &r
);
1915 Compute left and right overhang of glyph string S. If S is a glyph
1916 string for a composition, assume overhangs don't exist. */
1919 mac_compute_glyph_string_overhangs (s
)
1920 struct glyph_string
*s
;
1923 && s
->first_glyph
->type
== CHAR_GLYPH
)
1926 MacFontStruct
*font
= s
->font
;
1928 TextFont (font
->mac_fontnum
);
1929 TextSize (font
->mac_fontsize
);
1930 TextFace (font
->mac_fontface
);
1933 QDTextBounds (s
->nchars
* 2, (char *)s
->char2b
, &r
);
1937 char *buf
= xmalloc (s
->nchars
);
1940 SetRect (&r
, 0, 0, 0, 0);
1943 for (i
= 0; i
< s
->nchars
; ++i
)
1944 buf
[i
] = s
->char2b
[i
].byte2
;
1945 QDTextBounds (s
->nchars
, buf
, &r
);
1950 s
->right_overhang
= r
.right
> s
->width
? r
.right
- s
->width
: 0;
1951 s
->left_overhang
= r
.left
< 0 ? -r
.left
: 0;
1956 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1959 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
1960 struct glyph_string
*s
;
1963 mac_erase_rectangle (s
->window
, s
->gc
, x
, y
, w
, h
);
1967 /* We prefer not to use XDrawImageString (srcCopy text transfer mode)
1968 on Mac OS X because:
1969 - Screen is double-buffered. (In srcCopy mode, a text is drawn
1970 into an offscreen graphics world first. So performance gain
1971 cannot be expected.)
1972 - It lowers rendering quality.
1973 - Some fonts leave garbage on cursor movement. */
1975 /* Draw the background of glyph_string S. If S->background_filled_p
1976 is non-zero don't draw it. FORCE_P non-zero means draw the
1977 background even if it wouldn't be drawn normally. This is used
1978 when a string preceding S draws into the background of S, or S
1979 contains the first component of a composition. */
1982 x_draw_glyph_string_background (s
, force_p
)
1983 struct glyph_string
*s
;
1986 /* Nothing to do if background has already been drawn or if it
1987 shouldn't be drawn in the first place. */
1988 if (!s
->background_filled_p
)
1990 int box_line_width
= max (s
->face
->box_line_width
, 0);
1992 #if 0 /* MAC_TODO: stipple */
1995 /* Fill background with a stipple pattern. */
1996 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1997 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1998 s
->y
+ box_line_width
,
1999 s
->background_width
,
2000 s
->height
- 2 * box_line_width
);
2001 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2002 s
->background_filled_p
= 1;
2007 if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
2008 || s
->font_not_found_p
2009 || s
->extends_to_end_of_line_p
2013 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
2014 s
->background_width
,
2015 s
->height
- 2 * box_line_width
);
2016 s
->background_filled_p
= 1;
2022 /* Draw the foreground of glyph string S. */
2025 x_draw_glyph_string_foreground (s
)
2026 struct glyph_string
*s
;
2030 /* If first glyph of S has a left box line, start drawing the text
2031 of S to the right of that box line. */
2032 if (s
->face
->box
!= FACE_NO_BOX
2033 && s
->first_glyph
->left_box_line_p
)
2034 x
= s
->x
+ abs (s
->face
->box_line_width
);
2038 /* Draw characters of S as rectangles if S's font could not be
2040 if (s
->font_not_found_p
)
2042 for (i
= 0; i
< s
->nchars
; ++i
)
2044 struct glyph
*g
= s
->first_glyph
+ i
;
2045 mac_draw_rectangle (s
->display
, s
->window
,
2046 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
2048 x
+= g
->pixel_width
;
2053 char *char1b
= (char *) s
->char2b
;
2054 int boff
= s
->font_info
->baseline_offset
;
2056 if (s
->font_info
->vertical_centering
)
2057 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
2059 /* If we can use 8-bit functions, condense S->char2b. */
2061 for (i
= 0; i
< s
->nchars
; ++i
)
2062 char1b
[i
] = s
->char2b
[i
].byte2
;
2065 /* Draw text with XDrawString if background has already been
2066 filled. Otherwise, use XDrawImageString. (Note that
2067 XDrawImageString is usually faster than XDrawString.) Always
2068 use XDrawImageString when drawing the cursor so that there is
2069 no chance that characters under a box cursor are invisible. */
2070 if (s
->for_overlaps_p
2071 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
2074 /* Draw characters with 16-bit or 8-bit functions. */
2076 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
2077 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
2079 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
2080 s
->ybase
- boff
, char1b
, s
->nchars
);
2086 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
2087 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
2089 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
2090 s
->ybase
- boff
, char1b
, s
->nchars
);
2096 /* Draw the foreground of composite glyph string S. */
2099 x_draw_composite_glyph_string_foreground (s
)
2100 struct glyph_string
*s
;
2104 /* If first glyph of S has a left box line, start drawing the text
2105 of S to the right of that box line. */
2106 if (s
->face
->box
!= FACE_NO_BOX
2107 && s
->first_glyph
->left_box_line_p
)
2108 x
= s
->x
+ abs (s
->face
->box_line_width
);
2112 /* S is a glyph string for a composition. S->gidx is the index of
2113 the first character drawn for glyphs of this composition.
2114 S->gidx == 0 means we are drawing the very first character of
2115 this composition. */
2117 /* Draw a rectangle for the composition if the font for the very
2118 first character of the composition could not be loaded. */
2119 if (s
->font_not_found_p
)
2122 mac_draw_rectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
2123 s
->width
- 1, s
->height
- 1);
2127 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
2128 XDrawString16 (s
->display
, s
->window
, s
->gc
,
2129 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
2130 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
2136 #ifdef USE_X_TOOLKIT
2138 static struct frame
*x_frame_of_widget
P_ ((Widget
));
2141 /* Return the frame on which widget WIDGET is used.. Abort if frame
2142 cannot be determined. */
2144 static struct frame
*
2145 x_frame_of_widget (widget
)
2148 struct x_display_info
*dpyinfo
;
2152 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
2154 /* Find the top-level shell of the widget. Note that this function
2155 can be called when the widget is not yet realized, so XtWindow
2156 (widget) == 0. That's the reason we can't simply use
2157 x_any_window_to_frame. */
2158 while (!XtIsTopLevelShell (widget
))
2159 widget
= XtParent (widget
);
2161 /* Look for a frame with that top-level widget. Allocate the color
2162 on that frame to get the right gamma correction value. */
2163 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
2164 if (GC_FRAMEP (XCAR (tail
))
2165 && (f
= XFRAME (XCAR (tail
)),
2166 (f
->output_data
.nothing
!= 1
2167 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
2168 && f
->output_data
.x
->widget
== widget
)
2175 /* Allocate the color COLOR->pixel on the screen and display of
2176 widget WIDGET in colormap CMAP. If an exact match cannot be
2177 allocated, try the nearest color available. Value is non-zero
2178 if successful. This is called from lwlib. */
2181 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
2186 struct frame
*f
= x_frame_of_widget (widget
);
2187 return x_alloc_nearest_color (f
, cmap
, color
);
2191 #endif /* USE_X_TOOLKIT */
2193 #if 0 /* MAC_TODO */
2195 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
2196 CMAP. If an exact match can't be allocated, try the nearest color
2197 available. Value is non-zero if successful. Set *COLOR to the
2201 x_alloc_nearest_color (f
, cmap
, color
)
2206 Display
*display
= FRAME_X_DISPLAY (f
);
2207 Screen
*screen
= FRAME_X_SCREEN (f
);
2210 gamma_correct (f
, color
);
2211 rc
= XAllocColor (display
, cmap
, color
);
2214 /* If we got to this point, the colormap is full, so we're going
2215 to try to get the next closest color. The algorithm used is
2216 a least-squares matching, which is what X uses for closest
2217 color matching with StaticColor visuals. */
2219 unsigned long nearest_delta
= ~0;
2220 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
2221 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
2223 for (i
= 0; i
< ncells
; ++i
)
2225 XQueryColors (display
, cmap
, cells
, ncells
);
2227 for (nearest
= i
= 0; i
< ncells
; ++i
)
2229 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
2230 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
2231 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
2232 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
2234 if (delta
< nearest_delta
)
2237 nearest_delta
= delta
;
2241 color
->red
= cells
[nearest
].red
;
2242 color
->green
= cells
[nearest
].green
;
2243 color
->blue
= cells
[nearest
].blue
;
2244 rc
= XAllocColor (display
, cmap
, color
);
2247 #ifdef DEBUG_X_COLORS
2249 register_color (color
->pixel
);
2250 #endif /* DEBUG_X_COLORS */
2256 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
2257 It's necessary to do this instead of just using PIXEL directly to
2258 get color reference counts right. */
2261 x_copy_color (f
, pixel
)
2263 unsigned long pixel
;
2267 color
.pixel
= pixel
;
2269 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2270 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2272 #ifdef DEBUG_X_COLORS
2273 register_color (pixel
);
2279 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
2280 It's necessary to do this instead of just using PIXEL directly to
2281 get color reference counts right. */
2284 x_copy_dpy_color (dpy
, cmap
, pixel
)
2287 unsigned long pixel
;
2291 color
.pixel
= pixel
;
2293 XQueryColor (dpy
, cmap
, &color
);
2294 XAllocColor (dpy
, cmap
, &color
);
2296 #ifdef DEBUG_X_COLORS
2297 register_color (pixel
);
2302 #endif /* MAC_TODO */
2305 /* Brightness beyond which a color won't have its highlight brightness
2308 Nominally, highlight colors for `3d' faces are calculated by
2309 brightening an object's color by a constant scale factor, but this
2310 doesn't yield good results for dark colors, so for colors who's
2311 brightness is less than this value (on a scale of 0-255) have to
2312 use an additional additive factor.
2314 The value here is set so that the default menu-bar/mode-line color
2315 (grey75) will not have its highlights changed at all. */
2316 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 187
2319 /* Allocate a color which is lighter or darker than *COLOR by FACTOR
2320 or DELTA. Try a color with RGB values multiplied by FACTOR first.
2321 If this produces the same color as COLOR, try a color where all RGB
2322 values have DELTA added. Return the allocated color in *COLOR.
2323 DISPLAY is the X display, CMAP is the colormap to operate on.
2324 Value is non-zero if successful. */
2327 mac_alloc_lighter_color (f
, color
, factor
, delta
)
2329 unsigned long *color
;
2336 /* On Mac, RGB values are 0-255, not 0-65535, so scale delta. */
2339 /* Change RGB values by specified FACTOR. Avoid overflow! */
2340 xassert (factor
>= 0);
2341 new = RGB_TO_ULONG (min (0xff, (int) (factor
* RED_FROM_ULONG (*color
))),
2342 min (0xff, (int) (factor
* GREEN_FROM_ULONG (*color
))),
2343 min (0xff, (int) (factor
* BLUE_FROM_ULONG (*color
))));
2345 /* Calculate brightness of COLOR. */
2346 bright
= (2 * RED_FROM_ULONG (*color
) + 3 * GREEN_FROM_ULONG (*color
)
2347 + BLUE_FROM_ULONG (*color
)) / 6;
2349 /* We only boost colors that are darker than
2350 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
2351 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
2352 /* Make an additive adjustment to NEW, because it's dark enough so
2353 that scaling by FACTOR alone isn't enough. */
2355 /* How far below the limit this color is (0 - 1, 1 being darker). */
2356 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
2357 /* The additive adjustment. */
2358 int min_delta
= delta
* dimness
* factor
/ 2;
2361 new = RGB_TO_ULONG (max (0, min (0xff, (int) (RED_FROM_ULONG (*color
)) - min_delta
)),
2362 max (0, min (0xff, (int) (GREEN_FROM_ULONG (*color
)) - min_delta
)),
2363 max (0, min (0xff, (int) (BLUE_FROM_ULONG (*color
)) - min_delta
)));
2365 new = RGB_TO_ULONG (max (0, min (0xff, (int) (min_delta
+ RED_FROM_ULONG (*color
)))),
2366 max (0, min (0xff, (int) (min_delta
+ GREEN_FROM_ULONG (*color
)))),
2367 max (0, min (0xff, (int) (min_delta
+ BLUE_FROM_ULONG (*color
)))));
2371 new = RGB_TO_ULONG (max (0, min (0xff, (int) (delta
+ RED_FROM_ULONG (*color
)))),
2372 max (0, min (0xff, (int) (delta
+ GREEN_FROM_ULONG (*color
)))),
2373 max (0, min (0xff, (int) (delta
+ BLUE_FROM_ULONG (*color
)))));
2375 /* MAC_TODO: Map to palette and retry with delta if same? */
2376 /* MAC_TODO: Free colors (if using palette)? */
2387 /* Set up the foreground color for drawing relief lines of glyph
2388 string S. RELIEF is a pointer to a struct relief containing the GC
2389 with which lines will be drawn. Use a color that is FACTOR or
2390 DELTA lighter or darker than the relief's background which is found
2391 in S->f->output_data.x->relief_background. If such a color cannot
2392 be allocated, use DEFAULT_PIXEL, instead. */
2395 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
2397 struct relief
*relief
;
2400 unsigned long default_pixel
;
2403 struct mac_output
*di
= f
->output_data
.mac
;
2404 unsigned long mask
= GCForeground
;
2405 unsigned long pixel
;
2406 unsigned long background
= di
->relief_background
;
2407 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
2409 /* MAC_TODO: Free colors (if using palette)? */
2411 /* Allocate new color. */
2412 xgcv
.foreground
= default_pixel
;
2414 if (dpyinfo
->n_planes
!= 1
2415 && mac_alloc_lighter_color (f
, &pixel
, factor
, delta
))
2417 relief
->allocated_p
= 1;
2418 xgcv
.foreground
= relief
->pixel
= pixel
;
2421 if (relief
->gc
== 0)
2423 #if 0 /* MAC_TODO: stipple */
2424 xgcv
.stipple
= dpyinfo
->gray
;
2427 relief
->gc
= XCreateGC (NULL
, FRAME_MAC_WINDOW (f
), mask
, &xgcv
);
2430 XChangeGC (NULL
, relief
->gc
, mask
, &xgcv
);
2434 /* Set up colors for the relief lines around glyph string S. */
2437 x_setup_relief_colors (s
)
2438 struct glyph_string
*s
;
2440 struct mac_output
*di
= s
->f
->output_data
.mac
;
2441 unsigned long color
;
2443 if (s
->face
->use_box_color_for_shadows_p
)
2444 color
= s
->face
->box_color
;
2445 else if (s
->first_glyph
->type
== IMAGE_GLYPH
2447 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
2448 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
2453 /* Get the background color of the face. */
2454 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
2455 color
= xgcv
.background
;
2458 if (di
->white_relief
.gc
== 0
2459 || color
!= di
->relief_background
)
2461 di
->relief_background
= color
;
2462 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
2463 WHITE_PIX_DEFAULT (s
->f
));
2464 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
2465 BLACK_PIX_DEFAULT (s
->f
));
2470 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2471 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2472 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
2473 relief. LEFT_P non-zero means draw a relief on the left side of
2474 the rectangle. RIGHT_P non-zero means draw a relief on the right
2475 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2479 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
2480 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
2482 int left_x
, top_y
, right_x
, bottom_y
, width
;
2483 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
2486 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
2487 Window window
= FRAME_MAC_WINDOW (f
);
2492 gc
= f
->output_data
.mac
->white_relief
.gc
;
2494 gc
= f
->output_data
.mac
->black_relief
.gc
;
2495 mac_set_clip_rectangle (dpy
, window
, clip_rect
);
2499 for (i
= 0; i
< width
; ++i
)
2500 XDrawLine (dpy
, window
, gc
,
2501 left_x
+ i
* left_p
, top_y
+ i
,
2502 right_x
- i
* right_p
, top_y
+ i
);
2506 for (i
= 0; i
< width
; ++i
)
2507 XDrawLine (dpy
, window
, gc
,
2508 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
2510 mac_reset_clipping (dpy
, window
);
2512 gc
= f
->output_data
.mac
->black_relief
.gc
;
2514 gc
= f
->output_data
.mac
->white_relief
.gc
;
2515 mac_set_clip_rectangle (dpy
, window
,
2520 for (i
= 0; i
< width
; ++i
)
2521 XDrawLine (dpy
, window
, gc
,
2522 left_x
+ i
* left_p
, bottom_y
- i
,
2523 right_x
- i
* right_p
, bottom_y
- i
);
2527 for (i
= 0; i
< width
; ++i
)
2528 XDrawLine (dpy
, window
, gc
,
2529 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
- 1);
2531 mac_reset_clipping (dpy
, window
);
2535 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2536 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2537 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2538 left side of the rectangle. RIGHT_P non-zero means draw a line
2539 on the right side of the rectangle. CLIP_RECT is the clipping
2540 rectangle to use when drawing. */
2543 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2544 left_p
, right_p
, clip_rect
)
2545 struct glyph_string
*s
;
2546 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2551 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2552 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2553 mac_set_clip_rectangle (s
->display
, s
->window
, clip_rect
);
2556 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2557 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2561 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2562 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2565 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2566 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2570 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2571 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2573 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2574 mac_reset_clipping (s
->display
, s
->window
);
2578 /* Draw a box around glyph string S. */
2581 x_draw_glyph_string_box (s
)
2582 struct glyph_string
*s
;
2584 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2585 int left_p
, right_p
;
2586 struct glyph
*last_glyph
;
2589 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2590 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2591 : window_box_right (s
->w
, s
->area
));
2593 /* The glyph that may have a right box line. */
2594 last_glyph
= (s
->cmp
|| s
->img
2596 : s
->first_glyph
+ s
->nchars
- 1);
2598 width
= abs (s
->face
->box_line_width
);
2599 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2601 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2603 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2605 bottom_y
= top_y
+ s
->height
- 1;
2607 left_p
= (s
->first_glyph
->left_box_line_p
2608 || (s
->hl
== DRAW_MOUSE_FACE
2610 || s
->prev
->hl
!= s
->hl
)));
2611 right_p
= (last_glyph
->right_box_line_p
2612 || (s
->hl
== DRAW_MOUSE_FACE
2614 || s
->next
->hl
!= s
->hl
)));
2616 get_glyph_string_clip_rect (s
, &clip_rect
);
2618 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2619 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2620 left_p
, right_p
, &clip_rect
);
2623 x_setup_relief_colors (s
);
2624 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2625 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2630 /* Draw foreground of image glyph string S. */
2633 x_draw_image_foreground (s
)
2634 struct glyph_string
*s
;
2637 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2639 /* If first glyph of S has a left box line, start drawing it to the
2640 right of that line. */
2641 if (s
->face
->box
!= FACE_NO_BOX
2642 && s
->first_glyph
->left_box_line_p
2644 x
+= abs (s
->face
->box_line_width
);
2646 /* If there is a margin around the image, adjust x- and y-position
2648 if (s
->slice
.x
== 0)
2649 x
+= s
->img
->hmargin
;
2650 if (s
->slice
.y
== 0)
2651 y
+= s
->img
->vmargin
;
2655 x_set_glyph_string_clipping (s
);
2658 mac_copy_area_with_mask (s
->display
, s
->img
->pixmap
, s
->img
->mask
,
2659 s
->window
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
2660 s
->slice
.width
, s
->slice
.height
, x
, y
);
2663 mac_copy_area (s
->display
, s
->img
->pixmap
,
2664 s
->window
, s
->gc
, s
->slice
.x
, s
->slice
.y
,
2665 s
->slice
.width
, s
->slice
.height
, x
, y
);
2667 /* When the image has a mask, we can expect that at
2668 least part of a mouse highlight or a block cursor will
2669 be visible. If the image doesn't have a mask, make
2670 a block cursor visible by drawing a rectangle around
2671 the image. I believe it's looking better if we do
2672 nothing here for mouse-face. */
2673 if (s
->hl
== DRAW_CURSOR
)
2675 int r
= s
->img
->relief
;
2677 mac_draw_rectangle (s
->display
, s
->window
, s
->gc
,
2679 s
->slice
.width
+ r
*2 - 1,
2680 s
->slice
.height
+ r
*2 - 1);
2685 /* Draw a rectangle if image could not be loaded. */
2686 mac_draw_rectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2687 s
->slice
.width
- 1, s
->slice
.height
- 1);
2691 /* Draw a relief around the image glyph string S. */
2694 x_draw_image_relief (s
)
2695 struct glyph_string
*s
;
2697 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2700 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2702 /* If first glyph of S has a left box line, start drawing it to the
2703 right of that line. */
2704 if (s
->face
->box
!= FACE_NO_BOX
2705 && s
->first_glyph
->left_box_line_p
2707 x
+= abs (s
->face
->box_line_width
);
2709 /* If there is a margin around the image, adjust x- and y-position
2711 if (s
->slice
.x
== 0)
2712 x
+= s
->img
->hmargin
;
2713 if (s
->slice
.y
== 0)
2714 y
+= s
->img
->vmargin
;
2716 if (s
->hl
== DRAW_IMAGE_SUNKEN
2717 || s
->hl
== DRAW_IMAGE_RAISED
)
2719 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2720 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2724 thick
= abs (s
->img
->relief
);
2725 raised_p
= s
->img
->relief
> 0;
2730 x1
= x
+ s
->slice
.width
+ thick
- 1;
2731 y1
= y
+ s
->slice
.height
+ thick
- 1;
2733 x_setup_relief_colors (s
);
2734 get_glyph_string_clip_rect (s
, &r
);
2735 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
2737 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
2739 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
2744 #if 0 /* TODO: figure out if we need to do this on Mac. */
2745 /* Draw the foreground of image glyph string S to PIXMAP. */
2748 x_draw_image_foreground_1 (s
, pixmap
)
2749 struct glyph_string
*s
;
2753 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2755 /* If first glyph of S has a left box line, start drawing it to the
2756 right of that line. */
2757 if (s
->face
->box
!= FACE_NO_BOX
2758 && s
->first_glyph
->left_box_line_p
2760 x
+= abs (s
->face
->box_line_width
);
2762 /* If there is a margin around the image, adjust x- and y-position
2764 if (s
->slice
.x
== 0)
2765 x
+= s
->img
->hmargin
;
2766 if (s
->slice
.y
== 0)
2767 y
+= s
->img
->vmargin
;
2772 mac_copy_area_with_mask_to_pixmap (s
->display
, s
->img
->pixmap
,
2773 s
->img
->mask
, pixmap
, s
->gc
,
2774 s
->slice
.x
, s
->slice
.y
,
2775 s
->slice
.width
, s
->slice
.height
,
2779 mac_copy_area_to_pixmap (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2780 s
->slice
.x
, s
->slice
.y
,
2781 s
->slice
.width
, s
->slice
.height
,
2784 /* When the image has a mask, we can expect that at
2785 least part of a mouse highlight or a block cursor will
2786 be visible. If the image doesn't have a mask, make
2787 a block cursor visible by drawing a rectangle around
2788 the image. I believe it's looking better if we do
2789 nothing here for mouse-face. */
2790 if (s
->hl
== DRAW_CURSOR
)
2792 int r
= s
->img
->relief
;
2794 mac_draw_rectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2795 s
->slice
.width
+ r
*2 - 1,
2796 s
->slice
.height
+ r
*2 - 1);
2801 /* Draw a rectangle if image could not be loaded. */
2802 mac_draw_rectangle_to_pixmap (s
->display
, pixmap
, s
->gc
, x
, y
,
2803 s
->slice
.width
- 1, s
->slice
.height
- 1);
2808 /* Draw part of the background of glyph string S. X, Y, W, and H
2809 give the rectangle to draw. */
2812 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
2813 struct glyph_string
*s
;
2816 #if 0 /* MAC_TODO: stipple */
2819 /* Fill background with a stipple pattern. */
2820 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2821 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2822 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2825 #endif /* MAC_TODO */
2826 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2830 /* Draw image glyph string S.
2833 s->x +-------------------------
2836 | +-------------------------
2839 | | +-------------------
2845 x_draw_image_glyph_string (s
)
2846 struct glyph_string
*s
;
2849 int box_line_hwidth
= abs (s
->face
->box_line_width
);
2850 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2854 height
= s
->height
- 2 * box_line_vwidth
;
2857 /* Fill background with face under the image. Do it only if row is
2858 taller than image or if image has a clip mask to reduce
2860 s
->stippled_p
= s
->face
->stipple
!= 0;
2861 if (height
> s
->slice
.height
2865 || s
->img
->pixmap
== 0
2866 || s
->width
!= s
->background_width
)
2869 if (s
->first_glyph
->left_box_line_p
2871 x
+= box_line_hwidth
;
2874 if (s
->slice
.y
== 0)
2875 y
+= box_line_vwidth
;
2877 #if 0 /* TODO: figure out if we need to do this on Mac. */
2880 /* Create a pixmap as large as the glyph string. Fill it
2881 with the background color. Copy the image to it, using
2882 its mask. Copy the temporary pixmap to the display. */
2883 int depth
= one_mac_display_info
.n_planes
;
2885 /* Create a pixmap as large as the glyph string. */
2886 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2887 s
->background_width
,
2890 /* Fill the pixmap with the background color/stipple. */
2891 #if 0 /* TODO: stipple */
2894 /* Fill background with a stipple pattern. */
2895 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2896 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2897 0, 0, s
->background_width
, s
->height
);
2898 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2904 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2906 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2907 mac_fill_rectangle_to_pixmap (s
->display
, pixmap
, s
->gc
,
2908 0, 0, s
->background_width
,
2910 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2915 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2917 s
->background_filled_p
= 1;
2920 /* Draw the foreground. */
2921 #if 0 /* TODO: figure out if we need to do this on Mac. */
2924 x_draw_image_foreground_1 (s
, pixmap
);
2925 x_set_glyph_string_clipping (s
);
2926 mac_copy_area (s
->display
, pixmap
, s
->window
, s
->gc
,
2927 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2928 mac_reset_clipping (s
->display
, s
->window
);
2929 XFreePixmap (s
->display
, pixmap
);
2933 x_draw_image_foreground (s
);
2935 /* If we must draw a relief around the image, do it. */
2937 || s
->hl
== DRAW_IMAGE_RAISED
2938 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2939 x_draw_image_relief (s
);
2943 /* Draw stretch glyph string S. */
2946 x_draw_stretch_glyph_string (s
)
2947 struct glyph_string
*s
;
2949 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2950 s
->stippled_p
= s
->face
->stipple
!= 0;
2952 if (s
->hl
== DRAW_CURSOR
2953 && !x_stretch_cursor_p
)
2955 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2956 as wide as the stretch glyph. */
2957 int width
= min (FRAME_COLUMN_WIDTH (s
->f
), s
->background_width
);
2960 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
2962 /* Clear rest using the GC of the original non-cursor face. */
2963 if (width
< s
->background_width
)
2965 int x
= s
->x
+ width
, y
= s
->y
;
2966 int w
= s
->background_width
- width
, h
= s
->height
;
2970 if (s
->row
->mouse_face_p
2971 && cursor_in_mouse_face_p (s
->w
))
2973 x_set_mouse_face_gc (s
);
2979 get_glyph_string_clip_rect (s
, &r
);
2980 mac_set_clip_rectangle (s
->display
, s
->window
, &r
);
2982 #if 0 /* MAC_TODO: stipple */
2983 if (s
->face
->stipple
)
2985 /* Fill background with a stipple pattern. */
2986 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2987 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2988 XSetFillStyle (s
->display
, gc
, FillSolid
);
2991 #endif /* MAC_TODO */
2992 mac_erase_rectangle (s
->window
, gc
, x
, y
, w
, h
);
2994 mac_reset_clipping (s
->display
, s
->window
);
2997 else if (!s
->background_filled_p
)
2998 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
3001 s
->background_filled_p
= 1;
3005 /* Draw glyph string S. */
3008 x_draw_glyph_string (s
)
3009 struct glyph_string
*s
;
3011 int relief_drawn_p
= 0;
3013 /* If S draws into the background of its successor that does not
3014 draw a cursor, draw the background of the successor first so that
3015 S can draw into it. This makes S->next use XDrawString instead
3016 of XDrawImageString. */
3017 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
3018 && s
->next
->hl
!= DRAW_CURSOR
)
3020 xassert (s
->next
->img
== NULL
);
3021 x_set_glyph_string_gc (s
->next
);
3022 x_set_glyph_string_clipping (s
->next
);
3023 x_draw_glyph_string_background (s
->next
, 1);
3026 /* Set up S->gc, set clipping and draw S. */
3027 x_set_glyph_string_gc (s
);
3029 /* Draw relief (if any) in advance for char/composition so that the
3030 glyph string can be drawn over it. */
3031 if (!s
->for_overlaps_p
3032 && s
->face
->box
!= FACE_NO_BOX
3033 && (s
->first_glyph
->type
== CHAR_GLYPH
3034 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
3037 x_set_glyph_string_clipping (s
);
3038 x_draw_glyph_string_background (s
, 1);
3039 x_draw_glyph_string_box (s
);
3040 x_set_glyph_string_clipping (s
);
3044 x_set_glyph_string_clipping (s
);
3046 switch (s
->first_glyph
->type
)
3049 x_draw_image_glyph_string (s
);
3053 x_draw_stretch_glyph_string (s
);
3057 if (s
->for_overlaps_p
)
3058 s
->background_filled_p
= 1;
3060 x_draw_glyph_string_background (s
, 0);
3061 x_draw_glyph_string_foreground (s
);
3064 case COMPOSITE_GLYPH
:
3065 if (s
->for_overlaps_p
|| s
->gidx
> 0)
3066 s
->background_filled_p
= 1;
3068 x_draw_glyph_string_background (s
, 1);
3069 x_draw_composite_glyph_string_foreground (s
);
3076 if (!s
->for_overlaps_p
)
3078 /* Draw underline. */
3079 if (s
->face
->underline_p
)
3081 unsigned long h
= 1;
3082 unsigned long dy
= s
->height
- h
;
3084 if (s
->face
->underline_defaulted_p
)
3085 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3090 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3091 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
3092 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3094 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3098 /* Draw overline. */
3099 if (s
->face
->overline_p
)
3101 unsigned long dy
= 0, h
= 1;
3103 if (s
->face
->overline_color_defaulted_p
)
3104 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3109 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3110 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
3111 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3113 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3117 /* Draw strike-through. */
3118 if (s
->face
->strike_through_p
)
3120 unsigned long h
= 1;
3121 unsigned long dy
= (s
->height
- h
) / 2;
3123 if (s
->face
->strike_through_color_defaulted_p
)
3124 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3129 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3130 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
3131 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3133 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3137 /* Draw relief if not yet drawn. */
3138 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3139 x_draw_glyph_string_box (s
);
3142 /* Reset clipping. */
3143 mac_reset_clipping (s
->display
, s
->window
);
3146 /* Shift display to make room for inserted glyphs. */
3149 mac_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
3151 int x
, y
, width
, height
, shift_by
;
3153 mac_scroll_area (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
3154 f
->output_data
.mac
->normal_gc
,
3155 x
, y
, width
, height
,
3159 /* Delete N glyphs at the nominal cursor position. Not implemented
3170 /* Clear entire frame. If updating_frame is non-null, clear that
3171 frame. Otherwise clear the selected frame. */
3181 f
= SELECTED_FRAME ();
3183 /* Clearing the frame will erase any cursor, so mark them all as no
3185 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3186 output_cursor
.hpos
= output_cursor
.vpos
= 0;
3187 output_cursor
.x
= -1;
3189 /* We don't set the output cursor here because there will always
3190 follow an explicit cursor_to. */
3192 XClearWindow (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
));
3194 /* We have to clear the scroll bars, too. If we have changed
3195 colors or something like that, then they should be notified. */
3196 x_scroll_bar_clear (f
);
3198 XFlush (FRAME_MAC_DISPLAY (f
));
3204 /* Invert the middle quarter of the frame for .15 sec. */
3206 /* We use the select system call to do the waiting, so we have to make
3207 sure it's available. If it isn't, we just won't do visual bells. */
3209 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3212 /* Subtract the `struct timeval' values X and Y, storing the result in
3213 *RESULT. Return 1 if the difference is negative, otherwise 0. */
3216 timeval_subtract (result
, x
, y
)
3217 struct timeval
*result
, x
, y
;
3219 /* Perform the carry for the later subtraction by updating y. This
3220 is safer because on some systems the tv_sec member is unsigned. */
3221 if (x
.tv_usec
< y
.tv_usec
)
3223 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
3224 y
.tv_usec
-= 1000000 * nsec
;
3228 if (x
.tv_usec
- y
.tv_usec
> 1000000)
3230 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
3231 y
.tv_usec
+= 1000000 * nsec
;
3235 /* Compute the time remaining to wait. tv_usec is certainly
3237 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
3238 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
3240 /* Return indication of whether the result should be considered
3242 return x
.tv_sec
< y
.tv_sec
;
3254 struct timeval wakeup
;
3256 EMACS_GET_TIME (wakeup
);
3258 /* Compute time to wait until, propagating carry from usecs. */
3259 wakeup
.tv_usec
+= 150000;
3260 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
3261 wakeup
.tv_usec
%= 1000000;
3263 /* Keep waiting until past the time wakeup. */
3266 struct timeval timeout
;
3268 EMACS_GET_TIME (timeout
);
3270 /* In effect, timeout = wakeup - timeout.
3271 Break if result would be negative. */
3272 if (timeval_subtract (&timeout
, wakeup
, timeout
))
3275 /* Try to wait that long--but we might wake up sooner. */
3276 select (0, NULL
, NULL
, NULL
, &timeout
);
3285 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3288 /* Make audible bell. */
3293 struct frame
*f
= SELECTED_FRAME ();
3295 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3303 XFlush (FRAME_MAC_DISPLAY (f
));
3309 /* Specify how many text lines, from the top of the window,
3310 should be affected by insert-lines and delete-lines operations.
3311 This, and those operations, are used only within an update
3312 that is bounded by calls to x_update_begin and x_update_end. */
3315 XTset_terminal_window (n
)
3318 /* This function intentionally left blank. */
3323 /***********************************************************************
3325 ***********************************************************************/
3327 /* Perform an insert-lines or delete-lines operation, inserting N
3328 lines or deleting -N lines at vertical position VPOS. */
3331 x_ins_del_lines (vpos
, n
)
3338 /* Scroll part of the display as described by RUN. */
3341 x_scroll_run (w
, run
)
3345 struct frame
*f
= XFRAME (w
->frame
);
3346 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3348 /* Get frame-relative bounding box of the text display area of W,
3349 without mode lines. Include in this box the left and right
3351 window_box (w
, -1, &x
, &y
, &width
, &height
);
3353 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3354 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3355 bottom_y
= y
+ height
;
3359 /* Scrolling up. Make sure we don't copy part of the mode
3360 line at the bottom. */
3361 if (from_y
+ run
->height
> bottom_y
)
3362 height
= bottom_y
- from_y
;
3364 height
= run
->height
;
3368 /* Scolling down. Make sure we don't copy over the mode line.
3370 if (to_y
+ run
->height
> bottom_y
)
3371 height
= bottom_y
- to_y
;
3373 height
= run
->height
;
3378 /* Cursor off. Will be switched on again in x_update_window_end. */
3382 mac_scroll_area (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
3383 f
->output_data
.mac
->normal_gc
,
3393 /***********************************************************************
3395 ***********************************************************************/
3403 ControlRef root_control
;
3406 err
= GetRootControl (FRAME_MAC_WINDOW (f
), &root_control
);
3408 ActivateControl (root_control
);
3410 x_update_cursor (f
, 1);
3414 frame_unhighlight (f
)
3418 ControlRef root_control
;
3421 err
= GetRootControl (FRAME_MAC_WINDOW (f
), &root_control
);
3423 DeactivateControl (root_control
);
3425 x_update_cursor (f
, 1);
3428 /* The focus has changed. Update the frames as necessary to reflect
3429 the new situation. Note that we can't change the selected frame
3430 here, because the Lisp code we are interrupting might become confused.
3431 Each event gets marked with the frame in which it occurred, so the
3432 Lisp code can tell when the switch took place by examining the events. */
3435 x_new_focus_frame (dpyinfo
, frame
)
3436 struct x_display_info
*dpyinfo
;
3437 struct frame
*frame
;
3439 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3441 if (frame
!= dpyinfo
->x_focus_frame
)
3443 /* Set this before calling other routines, so that they see
3444 the correct value of x_focus_frame. */
3445 dpyinfo
->x_focus_frame
= frame
;
3447 if (old_focus
&& old_focus
->auto_lower
)
3448 x_lower_frame (old_focus
);
3451 selected_frame
= frame
;
3452 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
3454 Fselect_window (selected_frame
->selected_window
, Qnil
);
3455 choose_minibuf_frame ();
3458 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3459 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3461 pending_autoraise_frame
= 0;
3464 x_frame_rehighlight (dpyinfo
);
3467 /* Handle FocusIn and FocusOut state changes for FRAME.
3468 If FRAME has focus and there exists more than one frame, puts
3469 a FOCUS_IN_EVENT into *BUFP. */
3472 mac_focus_changed (type
, dpyinfo
, frame
, bufp
)
3474 struct mac_display_info
*dpyinfo
;
3475 struct frame
*frame
;
3476 struct input_event
*bufp
;
3478 if (type
== activeFlag
)
3480 if (dpyinfo
->x_focus_event_frame
!= frame
)
3482 x_new_focus_frame (dpyinfo
, frame
);
3483 dpyinfo
->x_focus_event_frame
= frame
;
3485 /* Don't stop displaying the initial startup message
3486 for a switch-frame event we don't need. */
3487 if (GC_NILP (Vterminal_frame
)
3488 && GC_CONSP (Vframe_list
)
3489 && !GC_NILP (XCDR (Vframe_list
)))
3491 bufp
->kind
= FOCUS_IN_EVENT
;
3492 XSETFRAME (bufp
->frame_or_window
, frame
);
3498 if (dpyinfo
->x_focus_event_frame
== frame
)
3500 dpyinfo
->x_focus_event_frame
= 0;
3501 x_new_focus_frame (dpyinfo
, 0);
3506 /* The focus may have changed. Figure out if it is a real focus change,
3507 by checking both FocusIn/Out and Enter/LeaveNotify events.
3509 Returns FOCUS_IN_EVENT event in *BUFP. */
3512 x_detect_focus_change (dpyinfo
, event
, bufp
)
3513 struct mac_display_info
*dpyinfo
;
3515 struct input_event
*bufp
;
3517 struct frame
*frame
;
3519 frame
= mac_window_to_frame ((WindowPtr
) event
->message
);
3523 /* On Mac, this is only called from focus events, so no switch needed. */
3524 mac_focus_changed ((event
->modifiers
& activeFlag
),
3525 dpyinfo
, frame
, bufp
);
3529 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3532 x_mouse_leave (dpyinfo
)
3533 struct x_display_info
*dpyinfo
;
3535 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3538 /* The focus has changed, or we have redirected a frame's focus to
3539 another frame (this happens when a frame uses a surrogate
3540 mini-buffer frame). Shift the highlight as appropriate.
3542 The FRAME argument doesn't necessarily have anything to do with which
3543 frame is being highlighted or un-highlighted; we only use it to find
3544 the appropriate X display info. */
3547 XTframe_rehighlight (frame
)
3548 struct frame
*frame
;
3550 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3554 x_frame_rehighlight (dpyinfo
)
3555 struct x_display_info
*dpyinfo
;
3557 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3559 if (dpyinfo
->x_focus_frame
)
3561 dpyinfo
->x_highlight_frame
3562 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3563 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3564 : dpyinfo
->x_focus_frame
);
3565 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3567 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
3568 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3572 dpyinfo
->x_highlight_frame
= 0;
3574 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3577 frame_unhighlight (old_highlight
);
3578 if (dpyinfo
->x_highlight_frame
)
3579 frame_highlight (dpyinfo
->x_highlight_frame
);
3585 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3587 #if 0 /* MAC_TODO */
3588 /* Initialize mode_switch_bit and modifier_meaning. */
3590 x_find_modifier_meanings (dpyinfo
)
3591 struct x_display_info
*dpyinfo
;
3593 int min_code
, max_code
;
3596 XModifierKeymap
*mods
;
3598 dpyinfo
->meta_mod_mask
= 0;
3599 dpyinfo
->shift_lock_mask
= 0;
3600 dpyinfo
->alt_mod_mask
= 0;
3601 dpyinfo
->super_mod_mask
= 0;
3602 dpyinfo
->hyper_mod_mask
= 0;
3605 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3607 min_code
= dpyinfo
->display
->min_keycode
;
3608 max_code
= dpyinfo
->display
->max_keycode
;
3611 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3612 min_code
, max_code
- min_code
+ 1,
3614 mods
= XGetModifierMapping (dpyinfo
->display
);
3616 /* Scan the modifier table to see which modifier bits the Meta and
3617 Alt keysyms are on. */
3619 int row
, col
; /* The row and column in the modifier table. */
3621 for (row
= 3; row
< 8; row
++)
3622 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3625 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3627 /* Zeroes are used for filler. Skip them. */
3631 /* Are any of this keycode's keysyms a meta key? */
3635 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3637 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3643 dpyinfo
->meta_mod_mask
|= (1 << row
);
3648 dpyinfo
->alt_mod_mask
|= (1 << row
);
3653 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3658 dpyinfo
->super_mod_mask
|= (1 << row
);
3662 /* Ignore this if it's not on the lock modifier. */
3663 if ((1 << row
) == LockMask
)
3664 dpyinfo
->shift_lock_mask
= LockMask
;
3672 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3673 if (! dpyinfo
->meta_mod_mask
)
3675 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3676 dpyinfo
->alt_mod_mask
= 0;
3679 /* If some keys are both alt and meta,
3680 make them just meta, not alt. */
3681 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3683 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3686 XFree ((char *) syms
);
3687 XFreeModifiermap (mods
);
3690 #endif /* MAC_TODO */
3692 /* Convert between the modifier bits X uses and the modifier bits
3696 x_mac_to_emacs_modifiers (dpyinfo
, state
)
3697 struct x_display_info
*dpyinfo
;
3698 unsigned short state
;
3700 return (((state
& shiftKey
) ? shift_modifier
: 0)
3701 | ((state
& controlKey
) ? ctrl_modifier
: 0)
3702 | ((state
& cmdKey
) ? meta_modifier
: 0)
3703 | ((state
& optionKey
) ? alt_modifier
: 0));
3706 #if 0 /* MAC_TODO */
3707 static unsigned short
3708 x_emacs_to_x_modifiers (dpyinfo
, state
)
3709 struct x_display_info
*dpyinfo
;
3712 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
3713 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
3714 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
3715 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3716 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3717 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
3719 #endif /* MAC_TODO */
3721 /* Convert a keysym to its name. */
3724 x_get_keysym_name (keysym
)
3731 value
= XKeysymToString (keysym
);
3742 /* Function to report a mouse movement to the mainstream Emacs code.
3743 The input handler calls this.
3745 We have received a mouse movement event, which is given in *event.
3746 If the mouse is over a different glyph than it was last time, tell
3747 the mainstream emacs code by setting mouse_moved. If not, ask for
3748 another motion event, so we can check again the next time it moves. */
3750 static Point last_mouse_motion_position
;
3751 static Lisp_Object last_mouse_motion_frame
;
3754 note_mouse_movement (frame
, pos
)
3758 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (frame
);
3759 #if TARGET_API_MAC_CARBON
3763 last_mouse_movement_time
= TickCount () * (1000 / 60); /* to milliseconds */
3764 last_mouse_motion_position
= *pos
;
3765 XSETFRAME (last_mouse_motion_frame
, frame
);
3767 #if TARGET_API_MAC_CARBON
3768 if (!PtInRect (*pos
, GetWindowPortBounds (FRAME_MAC_WINDOW (frame
), &r
)))
3770 if (!PtInRect (*pos
, &FRAME_MAC_WINDOW (frame
)->portRect
))
3773 if (frame
== dpyinfo
->mouse_face_mouse_frame
)
3774 /* This case corresponds to LeaveNotify in X11. */
3776 /* If we move outside the frame, then we're certainly no
3777 longer on any text in the frame. */
3778 clear_mouse_face (dpyinfo
);
3779 dpyinfo
->mouse_face_mouse_frame
= 0;
3780 if (!dpyinfo
->grabbed
)
3781 rif
->define_frame_cursor (frame
,
3782 frame
->output_data
.mac
->nontext_cursor
);
3785 /* Has the mouse moved off the glyph it was on at the last sighting? */
3786 else if (pos
->h
< last_mouse_glyph
.left
3787 || pos
->h
>= last_mouse_glyph
.right
3788 || pos
->v
< last_mouse_glyph
.top
3789 || pos
->v
>= last_mouse_glyph
.bottom
)
3791 frame
->mouse_moved
= 1;
3792 last_mouse_scroll_bar
= Qnil
;
3793 note_mouse_highlight (frame
, pos
->h
, pos
->v
);
3798 /************************************************************************
3800 ************************************************************************/
3802 static int glyph_rect
P_ ((struct frame
*f
, int, int, Rect
*));
3805 /* MAC TODO: This should be called from somewhere (or removed) ++KFS */
3808 redo_mouse_highlight ()
3810 if (!NILP (last_mouse_motion_frame
)
3811 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3812 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3813 last_mouse_motion_position
.h
,
3814 last_mouse_motion_position
.v
);
3818 /* Try to determine frame pixel position and size of the glyph under
3819 frame pixel coordinates X/Y on frame F . Return the position and
3820 size in *RECT. Value is non-zero if we could compute these
3824 glyph_rect (f
, x
, y
, rect
)
3831 window
= window_from_coordinates (f
, x
, y
, 0, &x
, &y
, 0);
3835 struct window
*w
= XWINDOW (window
);
3836 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
3837 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
3839 for (; r
< end
&& r
->enabled_p
; ++r
)
3840 if (r
->y
<= y
&& r
->y
+ r
->height
> y
)
3842 /* Found the row at y. */
3843 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
3844 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
3847 rect
->top
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
3848 rect
->bottom
= rect
->top
+ r
->height
;
3852 /* x is to the left of the first glyph in the row. */
3853 /* Shouldn't this be a pixel value?
3854 WINDOW_LEFT_EDGE_X (w) seems to be the right value.
3856 rect
->left
= WINDOW_LEFT_EDGE_COL (w
);
3857 rect
->right
= WINDOW_TO_FRAME_PIXEL_X (w
, r
->x
);
3861 for (gx
= r
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
3862 if (gx
<= x
&& gx
+ g
->pixel_width
> x
)
3864 /* x is on a glyph. */
3865 rect
->left
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
3866 rect
->right
= rect
->left
+ g
->pixel_width
;
3870 /* x is to the right of the last glyph in the row. */
3871 rect
->left
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
3872 /* Shouldn't this be a pixel value?
3873 WINDOW_RIGHT_EDGE_X (w) seems to be the right value.
3875 rect
->right
= WINDOW_RIGHT_EDGE_COL (w
);
3880 /* The y is not on any row. */
3884 /* MAC TODO: This should be called from somewhere (or removed) ++KFS */
3886 /* Record the position of the mouse in last_mouse_glyph. */
3888 remember_mouse_glyph (f1
, gx
, gy
)
3892 if (!glyph_rect (f1
, gx
, gy
, &last_mouse_glyph
))
3894 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
3895 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
3897 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
3898 round down even for negative values. */
3904 /* This was the original code from XTmouse_position, but it seems
3905 to give the position of the glyph diagonally next to the one
3906 the mouse is over. */
3907 gx
= (gx
+ width
- 1) / width
* width
;
3908 gy
= (gy
+ height
- 1) / height
* height
;
3910 gx
= gx
/ width
* width
;
3911 gy
= gy
/ height
* height
;
3914 last_mouse_glyph
.left
= gx
;
3915 last_mouse_glyph
.top
= gy
;
3916 last_mouse_glyph
.right
= gx
+ width
;
3917 last_mouse_glyph
.bottom
= gy
+ height
;
3922 static struct frame
*
3923 mac_focus_frame (dpyinfo
)
3924 struct mac_display_info
*dpyinfo
;
3926 if (dpyinfo
->x_focus_frame
)
3927 return dpyinfo
->x_focus_frame
;
3929 /* Mac version may get events, such as a menu bar click, even when
3930 all the frames are invisible. In this case, we regard the
3931 event came to the selected frame. */
3932 return SELECTED_FRAME ();
3936 /* Return the current position of the mouse.
3937 *fp should be a frame which indicates which display to ask about.
3939 If the mouse movement started in a scroll bar, set *fp, *bar_window,
3940 and *part to the frame, window, and scroll bar part that the mouse
3941 is over. Set *x and *y to the portion and whole of the mouse's
3942 position on the scroll bar.
3944 If the mouse movement started elsewhere, set *fp to the frame the
3945 mouse is on, *bar_window to nil, and *x and *y to the character cell
3948 Set *time to the server time-stamp for the time at which the mouse
3949 was at this position.
3951 Don't store anything if we don't have a valid set of values to report.
3953 This clears the mouse_moved flag, so we can wait for the next mouse
3957 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
3960 Lisp_Object
*bar_window
;
3961 enum scroll_bar_part
*part
;
3963 unsigned long *time
;
3966 int ignore1
, ignore2
;
3967 struct frame
*f
= mac_focus_frame (FRAME_MAC_DISPLAY_INFO (*fp
));
3968 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
3969 Lisp_Object frame
, tail
;
3973 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3974 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3977 /* Clear the mouse-moved flag for every frame on this display. */
3978 FOR_EACH_FRAME (tail
, frame
)
3979 XFRAME (frame
)->mouse_moved
= 0;
3981 last_mouse_scroll_bar
= Qnil
;
3983 SetPortWindowPort (wp
);
3985 GetMouse (&mouse_pos
);
3987 pixel_to_glyph_coords (f
, mouse_pos
.h
, mouse_pos
.v
, &ignore1
, &ignore2
,
3988 &last_mouse_glyph
, insist
);
3991 *part
= scroll_bar_handle
;
3993 XSETINT (*x
, mouse_pos
.h
);
3994 XSETINT (*y
, mouse_pos
.v
);
3995 *time
= last_mouse_movement_time
;
4002 /************************************************************************
4004 ************************************************************************/
4006 #ifdef USE_TOOLKIT_SCROLL_BARS
4008 static pascal void scroll_bar_timer_callback
P_ ((EventLoopTimerRef
, void *));
4009 static OSStatus install_scroll_bar_timer
P_ ((void));
4010 static OSStatus set_scroll_bar_timer
P_ ((EventTimerInterval
));
4011 static int control_part_code_to_scroll_bar_part
P_ ((ControlPartCode
));
4012 static void construct_scroll_bar_click
P_ ((struct scroll_bar
*, int,
4013 struct input_event
*));
4014 static OSErr get_control_part_bounds
P_ ((ControlHandle
, ControlPartCode
,
4016 static void x_scroll_bar_handle_press
P_ ((struct scroll_bar
*,
4018 struct input_event
*));
4019 static void x_scroll_bar_handle_release
P_ ((struct scroll_bar
*,
4020 struct input_event
*));
4021 static void x_scroll_bar_handle_drag
P_ ((WindowPtr
, struct scroll_bar
*,
4022 Point
, struct input_event
*));
4023 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
4026 /* Last scroll bar part sent in x_scroll_bar_handle_*. */
4028 static int last_scroll_bar_part
;
4030 static EventLoopTimerRef scroll_bar_timer
;
4032 static int scroll_bar_timer_event_posted_p
;
4034 #define SCROLL_BAR_FIRST_DELAY 0.5
4035 #define SCROLL_BAR_CONTINUOUS_DELAY (1.0 / 15)
4038 scroll_bar_timer_callback (timer
, data
)
4039 EventLoopTimerRef timer
;
4042 EventRef event
= NULL
;
4045 err
= CreateEvent (NULL
, kEventClassMouse
, kEventMouseMoved
, 0,
4046 kEventAttributeNone
, &event
);
4051 GetMouse (&mouse_pos
);
4052 LocalToGlobal (&mouse_pos
);
4053 err
= SetEventParameter (event
, kEventParamMouseLocation
, typeQDPoint
,
4054 sizeof (Point
), &mouse_pos
);
4058 UInt32 modifiers
= GetCurrentKeyModifiers ();
4060 err
= SetEventParameter (event
, kEventParamKeyModifiers
, typeUInt32
,
4061 sizeof (UInt32
), &modifiers
);
4064 err
= PostEventToQueue (GetCurrentEventQueue (), event
,
4065 kEventPriorityStandard
);
4067 scroll_bar_timer_event_posted_p
= 1;
4070 ReleaseEvent (event
);
4074 install_scroll_bar_timer ()
4076 static EventLoopTimerUPP scroll_bar_timer_callbackUPP
= NULL
;
4078 if (scroll_bar_timer_callbackUPP
== NULL
)
4079 scroll_bar_timer_callbackUPP
=
4080 NewEventLoopTimerUPP (scroll_bar_timer_callback
);
4082 if (scroll_bar_timer
== NULL
)
4083 /* Mac OS X and CarbonLib 1.5 and later allow us to specify
4084 kEventDurationForever as delays. */
4086 InstallEventLoopTimer (GetCurrentEventLoop (),
4087 kEventDurationForever
, kEventDurationForever
,
4088 scroll_bar_timer_callbackUPP
, NULL
,
4093 set_scroll_bar_timer (delay
)
4094 EventTimerInterval delay
;
4096 if (scroll_bar_timer
== NULL
)
4097 install_scroll_bar_timer ();
4099 scroll_bar_timer_event_posted_p
= 0;
4101 return SetEventLoopTimerNextFireTime (scroll_bar_timer
, delay
);
4105 control_part_code_to_scroll_bar_part (part_code
)
4106 ControlPartCode part_code
;
4110 case kControlUpButtonPart
: return scroll_bar_up_arrow
;
4111 case kControlDownButtonPart
: return scroll_bar_down_arrow
;
4112 case kControlPageUpPart
: return scroll_bar_above_handle
;
4113 case kControlPageDownPart
: return scroll_bar_below_handle
;
4114 case kControlIndicatorPart
: return scroll_bar_handle
;
4121 construct_scroll_bar_click (bar
, part
, bufp
)
4122 struct scroll_bar
*bar
;
4124 struct input_event
*bufp
;
4126 bufp
->kind
= SCROLL_BAR_CLICK_EVENT
;
4127 bufp
->frame_or_window
= bar
->window
;
4131 XSETINT (bufp
->x
, 0);
4132 XSETINT (bufp
->y
, 0);
4133 bufp
->modifiers
= 0;
4137 get_control_part_bounds (ch
, part_code
, rect
)
4139 ControlPartCode part_code
;
4142 RgnHandle region
= NewRgn ();
4145 err
= GetControlRegion (ch
, part_code
, region
);
4147 GetRegionBounds (region
, rect
);
4148 DisposeRgn (region
);
4154 x_scroll_bar_handle_press (bar
, part_code
, bufp
)
4155 struct scroll_bar
*bar
;
4156 ControlPartCode part_code
;
4157 struct input_event
*bufp
;
4159 int part
= control_part_code_to_scroll_bar_part (part_code
);
4164 if (part
!= scroll_bar_handle
)
4166 construct_scroll_bar_click (bar
, part
, bufp
);
4167 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), part_code
);
4168 set_scroll_bar_timer (SCROLL_BAR_FIRST_DELAY
);
4171 last_scroll_bar_part
= part
;
4172 bar
->dragging
= Qnil
;
4173 tracked_scroll_bar
= bar
;
4177 x_scroll_bar_handle_release (bar
, bufp
)
4178 struct scroll_bar
*bar
;
4179 struct input_event
*bufp
;
4181 if (last_scroll_bar_part
!= scroll_bar_handle
4182 || !GC_NILP (bar
->dragging
))
4183 construct_scroll_bar_click (bar
, scroll_bar_end_scroll
, bufp
);
4185 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), 0);
4186 set_scroll_bar_timer (kEventDurationForever
);
4188 last_scroll_bar_part
= -1;
4189 bar
->dragging
= Qnil
;
4190 tracked_scroll_bar
= NULL
;
4194 x_scroll_bar_handle_drag (win
, bar
, mouse_pos
, bufp
)
4196 struct scroll_bar
*bar
;
4198 struct input_event
*bufp
;
4200 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4202 if (last_scroll_bar_part
== scroll_bar_handle
)
4207 get_control_part_bounds (SCROLL_BAR_CONTROL_HANDLE (bar
),
4208 kControlIndicatorPart
, &r
);
4210 if (GC_NILP (bar
->dragging
))
4211 XSETINT (bar
->dragging
, mouse_pos
.v
- r
.top
);
4213 top
= mouse_pos
.v
- XINT (bar
->dragging
) - XINT (bar
->track_top
);
4214 top_range
= (XINT (bar
->track_height
) - (r
.bottom
- r
.top
)) *
4215 (1.0 + (float) GetControlViewSize (ch
) / GetControl32BitMaximum (ch
))
4220 if (top
> top_range
)
4223 construct_scroll_bar_click (bar
, scroll_bar_handle
, bufp
);
4224 XSETINT (bufp
->x
, top
);
4225 XSETINT (bufp
->y
, top_range
);
4229 ControlPartCode part_code
;
4230 int unhilite_p
= 0, part
;
4232 if (ch
!= FindControlUnderMouse (mouse_pos
, win
, &part_code
))
4236 part
= control_part_code_to_scroll_bar_part (part_code
);
4238 switch (last_scroll_bar_part
)
4240 case scroll_bar_above_handle
:
4241 case scroll_bar_below_handle
:
4242 if (part
!= scroll_bar_above_handle
4243 && part
!= scroll_bar_below_handle
)
4247 case scroll_bar_up_arrow
:
4248 case scroll_bar_down_arrow
:
4249 if (part
!= scroll_bar_up_arrow
4250 && part
!= scroll_bar_down_arrow
)
4257 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), 0);
4258 else if (part
!= last_scroll_bar_part
4259 || scroll_bar_timer_event_posted_p
)
4261 construct_scroll_bar_click (bar
, part
, bufp
);
4262 last_scroll_bar_part
= part
;
4263 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar
), part_code
);
4264 set_scroll_bar_timer (SCROLL_BAR_CONTINUOUS_DELAY
);
4269 /* Set the thumb size and position of scroll bar BAR. We are currently
4270 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4273 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4274 struct scroll_bar
*bar
;
4275 int portion
, position
, whole
;
4277 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4279 int value
, viewsize
, maximum
;
4281 if (whole
== 0 || XINT (bar
->track_height
) == 0)
4282 value
= 0, viewsize
= 1, maximum
= 0;
4287 maximum
= max (0, whole
- portion
);
4292 SetControl32BitMinimum (ch
, 0);
4293 SetControl32BitMaximum (ch
, maximum
);
4294 SetControl32BitValue (ch
, value
);
4295 SetControlViewSize (ch
, viewsize
);
4300 #endif /* USE_TOOLKIT_SCROLL_BARS */
4304 /************************************************************************
4305 Scroll bars, general
4306 ************************************************************************/
4308 /* Create a scroll bar and return the scroll bar vector for it. W is
4309 the Emacs window on which to create the scroll bar. TOP, LEFT,
4310 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4313 static struct scroll_bar
*
4314 x_scroll_bar_create (w
, top
, left
, width
, height
, disp_top
, disp_height
)
4316 int top
, left
, width
, height
, disp_top
, disp_height
;
4318 struct frame
*f
= XFRAME (w
->frame
);
4319 struct scroll_bar
*bar
4320 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
4328 r
.right
= left
+ width
;
4329 r
.bottom
= disp_top
+ disp_height
;
4331 #if TARGET_API_MAC_CARBON
4332 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p", width
< disp_height
,
4333 0, 0, 0, kControlScrollBarProc
, (long) bar
);
4335 ch
= NewControl (FRAME_MAC_WINDOW (f
), &r
, "\p", width
< disp_height
,
4336 0, 0, 0, scrollBarProc
, (long) bar
);
4338 SET_SCROLL_BAR_CONTROL_HANDLE (bar
, ch
);
4340 XSETWINDOW (bar
->window
, w
);
4341 XSETINT (bar
->top
, top
);
4342 XSETINT (bar
->left
, left
);
4343 XSETINT (bar
->width
, width
);
4344 XSETINT (bar
->height
, height
);
4345 XSETINT (bar
->start
, 0);
4346 XSETINT (bar
->end
, 0);
4347 bar
->dragging
= Qnil
;
4348 #ifdef USE_TOOLKIT_SCROLL_BARS
4349 bar
->track_top
= Qnil
;
4350 bar
->track_height
= Qnil
;
4353 /* Add bar to its frame's list of scroll bars. */
4354 bar
->next
= FRAME_SCROLL_BARS (f
);
4356 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4357 if (!NILP (bar
->next
))
4358 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4365 /* Draw BAR's handle in the proper position.
4367 If the handle is already drawn from START to END, don't bother
4368 redrawing it, unless REBUILD is non-zero; in that case, always
4369 redraw it. (REBUILD is handy for drawing the handle after expose
4372 Normally, we want to constrain the start and end of the handle to
4373 fit inside its rectangle, but if the user is dragging the scroll
4374 bar handle, we want to let them drag it down all the way, so that
4375 the bar's top is as far down as it goes; otherwise, there's no way
4376 to move to the very end of the buffer. */
4378 #ifndef USE_TOOLKIT_SCROLL_BARS
4381 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
4382 struct scroll_bar
*bar
;
4386 int dragging
= ! NILP (bar
->dragging
);
4387 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4388 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4389 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
4390 int length
= end
- start
;
4392 /* If the display is already accurate, do nothing. */
4394 && start
== XINT (bar
->start
)
4395 && end
== XINT (bar
->end
))
4400 /* Make sure the values are reasonable, and try to preserve the
4401 distance between start and end. */
4404 else if (start
> top_range
)
4406 end
= start
+ length
;
4410 else if (end
> top_range
&& ! dragging
)
4413 /* Store the adjusted setting in the scroll bar. */
4414 XSETINT (bar
->start
, start
);
4415 XSETINT (bar
->end
, end
);
4417 /* Clip the end position, just for display. */
4418 if (end
> top_range
)
4421 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
4422 top positions, to make sure the handle is always at least that
4423 many pixels tall. */
4424 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4426 SetControlMinimum (ch
, 0);
4427 /* Don't inadvertently activate deactivated scroll bars */
4428 if (GetControlMaximum (ch
) != -1)
4429 SetControlMaximum (ch
, top_range
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
4431 SetControlValue (ch
, start
);
4432 #if TARGET_API_MAC_CARBON
4433 SetControlViewSize (ch
, end
- start
);
4439 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4441 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4445 x_scroll_bar_remove (bar
)
4446 struct scroll_bar
*bar
;
4448 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4452 /* Destroy the Mac scroll bar control */
4453 DisposeControl (SCROLL_BAR_CONTROL_HANDLE (bar
));
4455 /* Disassociate this scroll bar from its window. */
4456 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
4462 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4463 that we are displaying PORTION characters out of a total of WHOLE
4464 characters, starting at POSITION. If WINDOW has no scroll bar,
4468 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
4470 int portion
, whole
, position
;
4472 struct frame
*f
= XFRAME (w
->frame
);
4473 struct scroll_bar
*bar
;
4474 int top
, height
, left
, sb_left
, width
, sb_width
, disp_top
, disp_height
;
4475 int window_y
, window_height
;
4477 /* Get window dimensions. */
4478 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
4480 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
4481 height
= window_height
;
4483 /* Compute the left edge of the scroll bar area. */
4484 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
4486 /* Compute the width of the scroll bar which might be less than
4487 the width of the area reserved for the scroll bar. */
4488 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
4489 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
4493 /* Compute the left edge of the scroll bar. */
4494 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
4497 sb_left
= left
+ width
- sb_width
;
4499 /* Adjustments according to Inside Macintosh to make it look nice */
4501 disp_height
= height
;
4507 else if (disp_top
== FRAME_PIXEL_HEIGHT (f
) - 16)
4513 if (sb_left
+ sb_width
== FRAME_PIXEL_WIDTH (f
))
4516 /* Does the scroll bar exist yet? */
4517 if (NILP (w
->vertical_scroll_bar
))
4520 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
4521 left
, top
, width
, height
, 0);
4523 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
, disp_top
,
4525 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
4529 /* It may just need to be moved and resized. */
4532 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
4533 ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4537 /* If already correctly positioned, do nothing. */
4538 if (!(XINT (bar
->left
) == sb_left
4539 && XINT (bar
->top
) == top
4540 && XINT (bar
->width
) == sb_width
4541 && XINT (bar
->height
) == height
))
4543 /* Since toolkit scroll bars are smaller than the space reserved
4544 for them on the frame, we have to clear "under" them. */
4545 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
4546 left
, top
, width
, height
, 0);
4549 if (sb_left
+ sb_width
>= FRAME_PIXEL_WIDTH (f
))
4550 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
4551 sb_left
- 1, top
, 1, height
, 0);
4555 MoveControl (ch
, sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
, disp_top
);
4556 SizeControl (ch
, sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4558 if (sb_width
< disp_height
)
4561 /* Remember new settings. */
4562 XSETINT (bar
->left
, sb_left
);
4563 XSETINT (bar
->top
, top
);
4564 XSETINT (bar
->width
, sb_width
);
4565 XSETINT (bar
->height
, height
);
4566 #ifdef USE_TOOLKIT_SCROLL_BARS
4567 bar
->track_top
= Qnil
;
4568 bar
->track_height
= Qnil
;
4575 #ifdef USE_TOOLKIT_SCROLL_BARS
4576 if (NILP (bar
->track_top
))
4578 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4583 SetControl32BitMinimum (ch
, 0);
4584 SetControl32BitMaximum (ch
, 1);
4585 SetControlViewSize (ch
, 1);
4587 /* Move the scroll bar thumb to the top. */
4588 SetControl32BitValue (ch
, 0);
4589 get_control_part_bounds (ch
, kControlIndicatorPart
, &r0
);
4591 /* Move the scroll bar thumb to the bottom. */
4592 SetControl32BitValue (ch
, 1);
4593 get_control_part_bounds (ch
, kControlIndicatorPart
, &r1
);
4595 UnionRect (&r0
, &r1
, &r0
);
4596 XSETINT (bar
->track_top
, r0
.top
);
4597 XSETINT (bar
->track_height
, r0
.bottom
- r0
.top
);
4602 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4603 #else /* not USE_TOOLKIT_SCROLL_BARS */
4604 /* Set the scroll bar's current state, unless we're currently being
4606 if (NILP (bar
->dragging
))
4608 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
4611 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
4614 int start
= ((double) position
* top_range
) / whole
;
4615 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
4616 x_scroll_bar_set_handle (bar
, start
, end
, 0);
4619 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4623 /* The following three hooks are used when we're doing a thorough
4624 redisplay of the frame. We don't explicitly know which scroll bars
4625 are going to be deleted, because keeping track of when windows go
4626 away is a real pain - "Can you say set-window-configuration, boys
4627 and girls?" Instead, we just assert at the beginning of redisplay
4628 that *all* scroll bars are to be removed, and then save a scroll bar
4629 from the fiery pit when we actually redisplay its window. */
4631 /* Arrange for all scroll bars on FRAME to be removed at the next call
4632 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
4633 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
4636 XTcondemn_scroll_bars (frame
)
4639 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
4640 while (! NILP (FRAME_SCROLL_BARS (frame
)))
4643 bar
= FRAME_SCROLL_BARS (frame
);
4644 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
4645 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
4646 XSCROLL_BAR (bar
)->prev
= Qnil
;
4647 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
4648 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
4649 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
4654 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
4655 Note that WINDOW isn't necessarily condemned at all. */
4658 XTredeem_scroll_bar (window
)
4659 struct window
*window
;
4661 struct scroll_bar
*bar
;
4664 /* We can't redeem this window's scroll bar if it doesn't have one. */
4665 if (NILP (window
->vertical_scroll_bar
))
4668 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
4670 /* Unlink it from the condemned list. */
4671 f
= XFRAME (WINDOW_FRAME (window
));
4672 if (NILP (bar
->prev
))
4674 /* If the prev pointer is nil, it must be the first in one of
4676 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
4677 /* It's not condemned. Everything's fine. */
4679 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
4680 window
->vertical_scroll_bar
))
4681 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
4683 /* If its prev pointer is nil, it must be at the front of
4684 one or the other! */
4688 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
4690 if (! NILP (bar
->next
))
4691 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
4693 bar
->next
= FRAME_SCROLL_BARS (f
);
4695 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4696 if (! NILP (bar
->next
))
4697 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4700 /* Remove all scroll bars on FRAME that haven't been saved since the
4701 last call to `*condemn_scroll_bars_hook'. */
4704 XTjudge_scroll_bars (f
)
4707 Lisp_Object bar
, next
;
4709 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
4711 /* Clear out the condemned list now so we won't try to process any
4712 more events on the hapless scroll bars. */
4713 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
4715 for (; ! NILP (bar
); bar
= next
)
4717 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
4719 x_scroll_bar_remove (b
);
4722 b
->next
= b
->prev
= Qnil
;
4725 /* Now there should be no references to the condemned scroll bars,
4726 and they should get garbage-collected. */
4730 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
4731 is set to something other than NO_EVENT, it is enqueued.
4733 This may be called from a signal handler, so we have to ignore GC
4737 x_scroll_bar_handle_click (bar
, part_code
, er
, bufp
)
4738 struct scroll_bar
*bar
;
4739 ControlPartCode part_code
;
4741 struct input_event
*bufp
;
4743 int win_y
, top_range
;
4745 if (! GC_WINDOWP (bar
->window
))
4748 bufp
->kind
= SCROLL_BAR_CLICK_EVENT
;
4749 bufp
->frame_or_window
= bar
->window
;
4752 bar
->dragging
= Qnil
;
4756 case kControlUpButtonPart
:
4757 bufp
->part
= scroll_bar_up_arrow
;
4759 case kControlDownButtonPart
:
4760 bufp
->part
= scroll_bar_down_arrow
;
4762 case kControlPageUpPart
:
4763 bufp
->part
= scroll_bar_above_handle
;
4765 case kControlPageDownPart
:
4766 bufp
->part
= scroll_bar_below_handle
;
4768 #if TARGET_API_MAC_CARBON
4771 case kControlIndicatorPart
:
4773 if (er
->what
== mouseDown
)
4774 bar
->dragging
= make_number (0);
4775 XSETVECTOR (last_mouse_scroll_bar
, bar
);
4776 bufp
->part
= scroll_bar_handle
;
4780 win_y
= XINT (bufp
->y
) - XINT (bar
->top
);
4781 top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (0/*dummy*/, XINT (bar
->height
));
4783 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
4787 if (! NILP (bar
->dragging
))
4788 win_y
-= XINT (bar
->dragging
);
4792 if (win_y
> top_range
)
4795 XSETINT (bufp
->x
, win_y
);
4796 XSETINT (bufp
->y
, top_range
);
4799 #ifndef USE_TOOLKIT_SCROLL_BARS
4801 /* Handle some mouse motion while someone is dragging the scroll bar.
4803 This may be called from a signal handler, so we have to ignore GC
4807 x_scroll_bar_note_movement (bar
, y_pos
, t
)
4808 struct scroll_bar
*bar
;
4812 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
4814 last_mouse_movement_time
= t
;
4817 XSETVECTOR (last_mouse_scroll_bar
, bar
);
4819 /* If we're dragging the bar, display it. */
4820 if (! GC_NILP (bar
->dragging
))
4822 /* Where should the handle be now? */
4823 int new_start
= y_pos
- 24;
4825 if (new_start
!= XINT (bar
->start
))
4827 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
4829 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
4834 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4836 /* Return information to the user about the current position of the mouse
4837 on the scroll bar. */
4840 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
4842 Lisp_Object
*bar_window
;
4843 enum scroll_bar_part
*part
;
4845 unsigned long *time
;
4847 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
4848 ControlHandle ch
= SCROLL_BAR_CONTROL_HANDLE (bar
);
4849 #if TARGET_API_MAC_CARBON
4850 WindowPtr wp
= GetControlOwner (ch
);
4852 WindowPtr wp
= (*ch
)->contrlOwner
;
4855 struct frame
*f
= mac_window_to_frame (wp
);
4856 int win_y
, top_range
;
4858 SetPortWindowPort (wp
);
4860 GetMouse (&mouse_pos
);
4862 win_y
= mouse_pos
.v
- XINT (bar
->top
);
4863 top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
4865 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
4869 if (! NILP (bar
->dragging
))
4870 win_y
-= XINT (bar
->dragging
);
4874 if (win_y
> top_range
)
4878 *bar_window
= bar
->window
;
4880 if (! NILP (bar
->dragging
))
4881 *part
= scroll_bar_handle
;
4882 else if (win_y
< XINT (bar
->start
))
4883 *part
= scroll_bar_above_handle
;
4884 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
4885 *part
= scroll_bar_handle
;
4887 *part
= scroll_bar_below_handle
;
4889 XSETINT (*x
, win_y
);
4890 XSETINT (*y
, top_range
);
4893 last_mouse_scroll_bar
= Qnil
;
4895 *time
= last_mouse_movement_time
;
4899 /* The screen has been cleared so we may have changed foreground or
4900 background colors, and the scroll bars may need to be redrawn.
4901 Clear out the scroll bars, and ask for expose events, so we can
4905 x_scroll_bar_clear (f
)
4908 XTcondemn_scroll_bars (f
);
4909 XTjudge_scroll_bars (f
);
4913 /***********************************************************************
4915 ***********************************************************************/
4917 /* Set clipping for output in glyph row ROW. W is the window in which
4918 we operate. GC is the graphics context to set clipping in.
4920 ROW may be a text row or, e.g., a mode line. Text rows must be
4921 clipped to the interior of the window dedicated to text display,
4922 mode lines must be clipped to the whole window. */
4925 x_clip_to_row (w
, row
, area
, gc
)
4927 struct glyph_row
*row
;
4931 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4933 int window_x
, window_y
, window_width
;
4935 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
4937 clip_rect
.left
= window_x
;
4938 clip_rect
.top
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4939 clip_rect
.top
= max (clip_rect
.top
, window_y
);
4940 clip_rect
.right
= clip_rect
.left
+ window_width
;
4941 clip_rect
.bottom
= clip_rect
.top
+ row
->visible_height
;
4943 mac_set_clip_rectangle (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), &clip_rect
);
4947 /* Draw a hollow box cursor on window W in glyph row ROW. */
4950 x_draw_hollow_cursor (w
, row
)
4952 struct glyph_row
*row
;
4954 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4955 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
4956 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
4959 struct glyph
*cursor_glyph
;
4962 /* Get the glyph the cursor is on. If we can't tell because
4963 the current matrix is invalid or such, give up. */
4964 cursor_glyph
= get_phys_cursor_glyph (w
);
4965 if (cursor_glyph
== NULL
)
4968 /* Compute frame-relative coordinates for phys cursor. */
4969 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
4970 y
= get_phys_cursor_geometry (w
, row
, cursor_glyph
, &h
);
4971 wd
= w
->phys_cursor_width
;
4973 /* The foreground of cursor_gc is typically the same as the normal
4974 background color, which can cause the cursor box to be invisible. */
4975 xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
4976 if (dpyinfo
->scratch_cursor_gc
)
4977 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
4979 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_MAC_WINDOW (f
),
4980 GCForeground
, &xgcv
);
4981 gc
= dpyinfo
->scratch_cursor_gc
;
4983 /* Set clipping, draw the rectangle, and reset clipping again. */
4984 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
4985 mac_draw_rectangle (dpy
, FRAME_MAC_WINDOW (f
), gc
, x
, y
, wd
, h
);
4986 mac_reset_clipping (dpy
, FRAME_MAC_WINDOW (f
));
4990 /* Draw a bar cursor on window W in glyph row ROW.
4992 Implementation note: One would like to draw a bar cursor with an
4993 angle equal to the one given by the font property XA_ITALIC_ANGLE.
4994 Unfortunately, I didn't find a font yet that has this property set.
4998 x_draw_bar_cursor (w
, row
, width
, kind
)
5000 struct glyph_row
*row
;
5002 enum text_cursor_kinds kind
;
5004 struct frame
*f
= XFRAME (w
->frame
);
5005 struct glyph
*cursor_glyph
;
5007 /* If cursor is out of bounds, don't draw garbage. This can happen
5008 in mini-buffer windows when switching between echo area glyphs
5010 cursor_glyph
= get_phys_cursor_glyph (w
);
5011 if (cursor_glyph
== NULL
)
5014 /* If on an image, draw like a normal cursor. That's usually better
5015 visible than drawing a bar, esp. if the image is large so that
5016 the bar might not be in the window. */
5017 if (cursor_glyph
->type
== IMAGE_GLYPH
)
5019 struct glyph_row
*row
;
5020 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
5021 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
5025 Display
*dpy
= FRAME_MAC_DISPLAY (f
);
5026 Window window
= FRAME_MAC_WINDOW (f
);
5027 GC gc
= FRAME_MAC_DISPLAY_INFO (f
)->scratch_cursor_gc
;
5028 unsigned long mask
= GCForeground
| GCBackground
;
5029 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
5032 /* If the glyph's background equals the color we normally draw
5033 the bar cursor in, the bar cursor in its normal color is
5034 invisible. Use the glyph's foreground color instead in this
5035 case, on the assumption that the glyph's colors are chosen so
5036 that the glyph is legible. */
5037 if (face
->background
== f
->output_data
.mac
->cursor_pixel
)
5038 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
5040 xgcv
.background
= xgcv
.foreground
= f
->output_data
.mac
->cursor_pixel
;
5043 XChangeGC (dpy
, gc
, mask
, &xgcv
);
5046 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
5047 FRAME_MAC_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
5051 width
= FRAME_CURSOR_WIDTH (f
);
5052 width
= min (cursor_glyph
->pixel_width
, width
);
5054 w
->phys_cursor_width
= width
;
5055 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
5057 if (kind
== BAR_CURSOR
)
5058 XFillRectangle (dpy
, window
, gc
,
5059 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
5060 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
5061 width
, row
->height
);
5063 XFillRectangle (dpy
, window
, gc
,
5064 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
5065 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
5066 row
->height
- width
),
5067 cursor_glyph
->pixel_width
,
5070 mac_reset_clipping (dpy
, FRAME_MAC_WINDOW (f
));
5075 /* RIF: Define cursor CURSOR on frame F. */
5078 mac_define_frame_cursor (f
, cursor
)
5082 SetThemeCursor (cursor
);
5086 /* RIF: Clear area on frame F. */
5089 mac_clear_frame_area (f
, x
, y
, width
, height
)
5091 int x
, y
, width
, height
;
5093 XClearArea (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
),
5094 x
, y
, width
, height
, 0);
5098 /* RIF: Draw cursor on window W. */
5101 mac_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
5103 struct glyph_row
*glyph_row
;
5105 int cursor_type
, cursor_width
;
5110 w
->phys_cursor_type
= cursor_type
;
5111 w
->phys_cursor_on_p
= 1;
5113 if (glyph_row
->exact_window_width_line_p
5114 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
5116 glyph_row
->cursor_in_fringe_p
= 1;
5117 draw_fringe_bitmap (w
, glyph_row
, 0);
5120 switch (cursor_type
)
5122 case HOLLOW_BOX_CURSOR
:
5123 x_draw_hollow_cursor (w
, glyph_row
);
5126 case FILLED_BOX_CURSOR
:
5127 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
5131 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
5135 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
5139 w
->phys_cursor_width
= 0;
5151 #if 0 /* MAC_TODO: no icon support yet. */
5153 x_bitmap_icon (f
, icon
)
5159 if (FRAME_W32_WINDOW (f
) == 0)
5163 hicon
= LoadIcon (hinst
, EMACS_CLASS
);
5164 else if (STRINGP (icon
))
5165 hicon
= LoadImage (NULL
, (LPCTSTR
) SDATA (icon
), IMAGE_ICON
, 0, 0,
5166 LR_DEFAULTSIZE
| LR_LOADFROMFILE
);
5167 else if (SYMBOLP (icon
))
5171 if (EQ (icon
, intern ("application")))
5172 name
= (LPCTSTR
) IDI_APPLICATION
;
5173 else if (EQ (icon
, intern ("hand")))
5174 name
= (LPCTSTR
) IDI_HAND
;
5175 else if (EQ (icon
, intern ("question")))
5176 name
= (LPCTSTR
) IDI_QUESTION
;
5177 else if (EQ (icon
, intern ("exclamation")))
5178 name
= (LPCTSTR
) IDI_EXCLAMATION
;
5179 else if (EQ (icon
, intern ("asterisk")))
5180 name
= (LPCTSTR
) IDI_ASTERISK
;
5181 else if (EQ (icon
, intern ("winlogo")))
5182 name
= (LPCTSTR
) IDI_WINLOGO
;
5186 hicon
= LoadIcon (NULL
, name
);
5194 PostMessage (FRAME_W32_WINDOW (f
), WM_SETICON
, (WPARAM
) ICON_BIG
,
5199 #endif /* MAC_TODO */
5201 /************************************************************************
5203 ************************************************************************/
5205 /* Display Error Handling functions not used on W32. Listing them here
5206 helps diff stay in step when comparing w32term.c with xterm.c.
5208 x_error_catcher (display, error)
5209 x_catch_errors (dpy)
5210 x_catch_errors_unwind (old_val)
5211 x_check_errors (dpy, format)
5212 x_had_errors_p (dpy)
5213 x_clear_errors (dpy)
5214 x_uncatch_errors (dpy, count)
5216 x_connection_signal (signalnum)
5217 x_connection_closed (dpy, error_message)
5218 x_error_quitter (display, error)
5219 x_error_handler (display, error)
5220 x_io_error_quitter (display)
5225 /* Changing the font of the frame. */
5227 /* Give frame F the font named FONTNAME as its default font, and
5228 return the full name of that font. FONTNAME may be a wildcard
5229 pattern; in that case, we choose some font that fits the pattern.
5230 The return value shows which font we chose. */
5233 x_new_font (f
, fontname
)
5235 register char *fontname
;
5237 struct font_info
*fontp
5238 = FS_LOAD_FONT (f
, fontname
);
5243 if (FRAME_FONT (f
) == (XFontStruct
*) (fontp
->font
))
5244 /* This font is already set in frame F. There's nothing more to
5246 return build_string (fontp
->full_name
);
5248 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
5249 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
5250 FRAME_FONTSET (f
) = -1;
5252 FRAME_COLUMN_WIDTH (f
) = fontp
->average_width
;
5253 FRAME_SPACE_WIDTH (f
) = fontp
->space_width
;
5254 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (FRAME_FONT (f
));
5256 compute_fringe_widths (f
, 1);
5258 /* Compute the scroll bar width in character columns. */
5259 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
5261 int wid
= FRAME_COLUMN_WIDTH (f
);
5262 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
5263 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
5267 int wid
= FRAME_COLUMN_WIDTH (f
);
5268 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
5271 /* Now make the frame display the given font. */
5272 if (FRAME_MAC_WINDOW (f
) != 0)
5274 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->normal_gc
,
5276 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->reverse_gc
,
5278 XSetFont (FRAME_MAC_DISPLAY (f
), f
->output_data
.mac
->cursor_gc
,
5281 /* Don't change the size of a tip frame; there's no point in
5282 doing it because it's done in Fx_show_tip, and it leads to
5283 problems because the tip frame has no widget. */
5284 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
5285 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
5288 return build_string (fontp
->full_name
);
5291 /* Give frame F the fontset named FONTSETNAME as its default font, and
5292 return the full name of that fontset. FONTSETNAME may be a wildcard
5293 pattern; in that case, we choose some fontset that fits the pattern.
5294 The return value shows which fontset we chose. */
5297 x_new_fontset (f
, fontsetname
)
5299 Lisp_Object fontsetname
;
5301 int fontset
= fs_query_fontset (fontsetname
, 0);
5304 if (fontset
> 0 && FRAME_FONTSET(f
) == fontset
)
5305 /* This fontset is already set in frame F. There's nothing more
5307 return fontset_name (fontset
);
5308 else if (fontset
== 0)
5309 /* The default fontset can't be the default font. */
5313 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
5315 result
= x_new_font (f
, SDATA (fontsetname
));
5317 if (!STRINGP (result
))
5318 /* Can't load ASCII font. */
5322 fontset
= new_fontset_from_font_name (result
);
5324 /* Since x_new_font doesn't update any fontset information, do it now. */
5325 FRAME_FONTSET (f
) = fontset
;
5327 return fontset_name (fontset
);
5331 /***********************************************************************
5332 TODO: W32 Input Methods
5333 ***********************************************************************/
5334 /* Listing missing functions from xterm.c helps diff stay in step.
5336 xim_destroy_callback (xim, client_data, call_data)
5337 xim_open_dpy (dpyinfo, resource_name)
5339 xim_instantiate_callback (display, client_data, call_data)
5340 xim_initialize (dpyinfo, resource_name)
5341 xim_close_dpy (dpyinfo)
5347 mac_get_window_bounds (f
, inner
, outer
)
5349 Rect
*inner
, *outer
;
5351 #if TARGET_API_MAC_CARBON
5352 GetWindowBounds (FRAME_MAC_WINDOW (f
), kWindowContentRgn
, inner
);
5353 GetWindowBounds (FRAME_MAC_WINDOW (f
), kWindowStructureRgn
, outer
);
5354 #else /* not TARGET_API_MAC_CARBON */
5355 RgnHandle region
= NewRgn ();
5357 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowContentRgn
, region
);
5358 *inner
= (*region
)->rgnBBox
;
5359 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowStructureRgn
, region
);
5360 *outer
= (*region
)->rgnBBox
;
5361 DisposeRgn (region
);
5362 #endif /* not TARGET_API_MAC_CARBON */
5367 /* Calculate the absolute position in frame F
5368 from its current recorded position values and gravity. */
5371 x_calc_absolute_position (f
)
5374 int width_diff
= 0, height_diff
= 0;
5375 int flags
= f
->size_hint_flags
;
5378 /* We have nothing to do if the current position
5379 is already for the top-left corner. */
5380 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
5383 /* Find the offsets of the outside upper-left corner of
5384 the inner window, with respect to the outer window. */
5385 mac_get_window_bounds (f
, &inner
, &outer
);
5387 width_diff
= (outer
.right
- outer
.left
) - (inner
.right
- inner
.left
);
5388 height_diff
= (outer
.bottom
- outer
.top
) - (inner
.bottom
- inner
.top
);
5390 /* Treat negative positions as relative to the leftmost bottommost
5391 position that fits on the screen. */
5392 if (flags
& XNegative
)
5393 f
->left_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->width
5395 - FRAME_PIXEL_WIDTH (f
)
5398 if (flags
& YNegative
)
5399 f
->top_pos
= (FRAME_MAC_DISPLAY_INFO (f
)->height
5401 - FRAME_PIXEL_HEIGHT (f
)
5404 /* The left_pos and top_pos
5405 are now relative to the top and left screen edges,
5406 so the flags should correspond. */
5407 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5410 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
5411 to really change the position, and 0 when calling from
5412 x_make_frame_visible (in that case, XOFF and YOFF are the current
5413 position values). It is -1 when calling from x_set_frame_parameters,
5414 which means, do adjust for borders but don't change the gravity. */
5417 x_set_offset (f
, xoff
, yoff
, change_gravity
)
5419 register int xoff
, yoff
;
5422 if (change_gravity
> 0)
5426 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5428 f
->size_hint_flags
|= XNegative
;
5430 f
->size_hint_flags
|= YNegative
;
5431 f
->win_gravity
= NorthWestGravity
;
5433 x_calc_absolute_position (f
);
5436 x_wm_set_size_hint (f
, (long) 0, 0);
5438 #if TARGET_API_MAC_CARBON
5439 MoveWindowStructure (FRAME_MAC_WINDOW (f
), f
->left_pos
, f
->top_pos
);
5440 /* If the title bar is completely outside the screen, adjust the
5442 ConstrainWindowToScreen (FRAME_MAC_WINDOW (f
), kWindowTitleBarRgn
,
5443 kWindowConstrainMoveRegardlessOfFit
5444 | kWindowConstrainAllowPartial
, NULL
, NULL
);
5445 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
5448 Rect inner
, outer
, screen_rect
, dummy
;
5449 RgnHandle region
= NewRgn ();
5451 mac_get_window_bounds (f
, &inner
, &outer
);
5452 f
->x_pixels_diff
= inner
.left
- outer
.left
;
5453 f
->y_pixels_diff
= inner
.top
- outer
.top
;
5454 MoveWindow (FRAME_MAC_WINDOW (f
), f
->left_pos
+ f
->x_pixels_diff
,
5455 f
->top_pos
+ f
->y_pixels_diff
, false);
5457 /* If the title bar is completely outside the screen, adjust the
5458 position. The variable `outer' holds the title bar rectangle.
5459 The variable `inner' holds slightly smaller one than `outer',
5460 so that the calculation of overlapping may not become too
5462 GetWindowRegion (FRAME_MAC_WINDOW (f
), kWindowTitleBarRgn
, region
);
5463 outer
= (*region
)->rgnBBox
;
5464 DisposeRgn (region
);
5466 InsetRect (&inner
, 8, 8);
5467 screen_rect
= qd
.screenBits
.bounds
;
5468 screen_rect
.top
+= GetMBarHeight ();
5470 if (!SectRect (&inner
, &screen_rect
, &dummy
))
5472 if (inner
.right
<= screen_rect
.left
)
5473 f
->left_pos
= screen_rect
.left
;
5474 else if (inner
.left
>= screen_rect
.right
)
5475 f
->left_pos
= screen_rect
.right
- (outer
.right
- outer
.left
);
5477 if (inner
.bottom
<= screen_rect
.top
)
5478 f
->top_pos
= screen_rect
.top
;
5479 else if (inner
.top
>= screen_rect
.bottom
)
5480 f
->top_pos
= screen_rect
.bottom
- (outer
.bottom
- outer
.top
);
5482 MoveWindow (FRAME_MAC_WINDOW (f
), f
->left_pos
+ f
->x_pixels_diff
,
5483 f
->top_pos
+ f
->y_pixels_diff
, false);
5491 /* Call this to change the size of frame F's x-window.
5492 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
5493 for this size change and subsequent size changes.
5494 Otherwise we leave the window gravity unchanged. */
5497 x_set_window_size (f
, change_gravity
, cols
, rows
)
5502 int pixelwidth
, pixelheight
;
5506 check_frame_size (f
, &rows
, &cols
);
5507 f
->scroll_bar_actual_width
5508 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
5510 compute_fringe_widths (f
, 0);
5512 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
5513 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
5515 f
->win_gravity
= NorthWestGravity
;
5516 x_wm_set_size_hint (f
, (long) 0, 0);
5518 SizeWindow (FRAME_MAC_WINDOW (f
), pixelwidth
, pixelheight
, 0);
5519 #if TARGET_API_MAC_CARBON
5520 if (f
->output_data
.mac
->hourglass_control
)
5521 MoveControl (f
->output_data
.mac
->hourglass_control
,
5522 pixelwidth
- HOURGLASS_WIDTH
, 0);
5525 /* Now, strictly speaking, we can't be sure that this is accurate,
5526 but the window manager will get around to dealing with the size
5527 change request eventually, and we'll hear how it went when the
5528 ConfigureNotify event gets here.
5530 We could just not bother storing any of this information here,
5531 and let the ConfigureNotify event set everything up, but that
5532 might be kind of confusing to the Lisp code, since size changes
5533 wouldn't be reported in the frame parameters until some random
5534 point in the future when the ConfigureNotify event arrives.
5536 We pass 1 for DELAY since we can't run Lisp code inside of
5538 change_frame_size (f
, rows
, cols
, 0, 1, 0);
5539 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
5540 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
5542 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
5543 receive in the ConfigureNotify event; if we get what we asked
5544 for, then the event won't cause the screen to become garbaged, so
5545 we have to make sure to do it here. */
5546 SET_FRAME_GARBAGED (f
);
5548 XFlush (FRAME_X_DISPLAY (f
));
5550 /* If cursor was outside the new size, mark it as off. */
5551 mark_window_cursors_off (XWINDOW (f
->root_window
));
5553 /* Clear out any recollection of where the mouse highlighting was,
5554 since it might be in a place that's outside the new frame size.
5555 Actually checking whether it is outside is a pain in the neck,
5556 so don't try--just let the highlighting be done afresh with new size. */
5557 cancel_mouse_face (f
);
5562 /* Mouse warping. */
5564 void x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
);
5567 x_set_mouse_position (f
, x
, y
)
5573 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
5574 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
5576 if (pix_x
< 0) pix_x
= 0;
5577 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
5579 if (pix_y
< 0) pix_y
= 0;
5580 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
5582 x_set_mouse_pixel_position (f
, pix_x
, pix_y
);
5586 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
5590 #if 0 /* MAC_TODO: CursorDeviceMoveTo is non-Carbon */
5593 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
5594 0, 0, 0, 0, pix_x
, pix_y
);
5599 /* focus shifting, raising and lowering. */
5602 x_focus_on_frame (f
)
5605 #if 0 /* This proves to be unpleasant. */
5609 /* I don't think that the ICCCM allows programs to do things like this
5610 without the interaction of the window manager. Whatever you end up
5611 doing with this code, do it to x_unfocus_frame too. */
5612 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5613 RevertToPointerRoot
, CurrentTime
);
5623 /* Raise frame F. */
5629 if (f
->async_visible
)
5632 SelectWindow (FRAME_MAC_WINDOW (f
));
5637 /* Lower frame F. */
5643 if (f
->async_visible
)
5646 SendBehind (FRAME_MAC_WINDOW (f
), nil
);
5652 XTframe_raise_lower (f
, raise_flag
)
5662 /* Change of visibility. */
5664 /* This tries to wait until the frame is really visible.
5665 However, if the window manager asks the user where to position
5666 the frame, this will return before the user finishes doing that.
5667 The frame will not actually be visible at that time,
5668 but it will become visible later when the window manager
5669 finishes with it. */
5672 x_make_frame_visible (f
)
5676 int original_top
, original_left
;
5680 if (! FRAME_VISIBLE_P (f
))
5682 /* We test FRAME_GARBAGED_P here to make sure we don't
5683 call x_set_offset a second time
5684 if we get to x_make_frame_visible a second time
5685 before the window gets really visible. */
5686 if (! FRAME_ICONIFIED_P (f
)
5687 && ! f
->output_data
.mac
->asked_for_visible
)
5688 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
5690 f
->output_data
.mac
->asked_for_visible
= 1;
5692 #if TARGET_API_MAC_CARBON
5693 if (!(FRAME_SIZE_HINTS (f
)->flags
& (USPosition
| PPosition
)))
5695 struct frame
*sf
= SELECTED_FRAME ();
5696 if (!FRAME_MAC_P (sf
))
5697 RepositionWindow (FRAME_MAC_WINDOW (f
), NULL
,
5698 kWindowCenterOnMainScreen
);
5700 RepositionWindow (FRAME_MAC_WINDOW (f
),
5701 FRAME_MAC_WINDOW (sf
),
5702 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
5703 kWindowCascadeStartAtParentWindowScreen
5705 kWindowCascadeOnParentWindowScreen
5708 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
5711 ShowWindow (FRAME_MAC_WINDOW (f
));
5714 XFlush (FRAME_MAC_DISPLAY (f
));
5716 /* Synchronize to ensure Emacs knows the frame is visible
5717 before we do anything else. We do this loop with input not blocked
5718 so that incoming events are handled. */
5723 /* This must come after we set COUNT. */
5726 XSETFRAME (frame
, f
);
5728 /* Wait until the frame is visible. Process X events until a
5729 MapNotify event has been seen, or until we think we won't get a
5730 MapNotify at all.. */
5731 for (count
= input_signal_count
+ 10;
5732 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
5734 /* Force processing of queued events. */
5737 /* Machines that do polling rather than SIGIO have been
5738 observed to go into a busy-wait here. So we'll fake an
5739 alarm signal to let the handler know that there's something
5740 to be read. We used to raise a real alarm, but it seems
5741 that the handler isn't always enabled here. This is
5743 if (input_polling_used ())
5745 /* It could be confusing if a real alarm arrives while
5746 processing the fake one. Turn it off and let the
5747 handler reset it. */
5748 extern void poll_for_input_1
P_ ((void));
5749 int old_poll_suppress_count
= poll_suppress_count
;
5750 poll_suppress_count
= 1;
5751 poll_for_input_1 ();
5752 poll_suppress_count
= old_poll_suppress_count
;
5755 /* See if a MapNotify event has been processed. */
5756 FRAME_SAMPLE_VISIBILITY (f
);
5761 /* Change from mapped state to withdrawn state. */
5763 /* Make the frame visible (mapped and not iconified). */
5766 x_make_frame_invisible (f
)
5769 /* Don't keep the highlight on an invisible frame. */
5770 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5771 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5775 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
5776 that the current position of the window is user-specified, rather than
5777 program-specified, so that when the window is mapped again, it will be
5778 placed at the same location, without forcing the user to position it
5779 by hand again (they have already done that once for this window.) */
5780 x_wm_set_size_hint (f
, (long) 0, 1);
5782 HideWindow (FRAME_MAC_WINDOW (f
));
5784 /* We can't distinguish this from iconification
5785 just by the event that we get from the server.
5786 So we can't win using the usual strategy of letting
5787 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
5788 and synchronize with the server to make sure we agree. */
5790 FRAME_ICONIFIED_P (f
) = 0;
5791 f
->async_visible
= 0;
5792 f
->async_iconified
= 0;
5797 /* Change window state from mapped to iconified. */
5803 /* Don't keep the highlight on an invisible frame. */
5804 if (FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5805 FRAME_MAC_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5808 /* Review: Since window is still visible in dock, still allow updates? */
5809 if (f
->async_iconified
)
5815 CollapseWindow (FRAME_MAC_WINDOW (f
), true);
5821 /* Free X resources of frame F. */
5824 x_free_frame_resources (f
)
5827 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
5828 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
5832 if (wp
!= tip_window
)
5833 remove_window_handler (wp
);
5836 if (wp
== tip_window
)
5837 /* Neither WaitNextEvent nor ReceiveNextEvent receives `window
5838 closed' event. So we reset tip_window here. */
5841 free_frame_menubar (f
);
5843 if (FRAME_FACE_CACHE (f
))
5844 free_frame_faces (f
);
5848 if (FRAME_SIZE_HINTS (f
))
5849 xfree (FRAME_SIZE_HINTS (f
));
5851 xfree (f
->output_data
.mac
);
5852 f
->output_data
.mac
= NULL
;
5854 if (f
== dpyinfo
->x_focus_frame
)
5855 dpyinfo
->x_focus_frame
= 0;
5856 if (f
== dpyinfo
->x_focus_event_frame
)
5857 dpyinfo
->x_focus_event_frame
= 0;
5858 if (f
== dpyinfo
->x_highlight_frame
)
5859 dpyinfo
->x_highlight_frame
= 0;
5861 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5863 dpyinfo
->mouse_face_beg_row
5864 = dpyinfo
->mouse_face_beg_col
= -1;
5865 dpyinfo
->mouse_face_end_row
5866 = dpyinfo
->mouse_face_end_col
= -1;
5867 dpyinfo
->mouse_face_window
= Qnil
;
5868 dpyinfo
->mouse_face_deferred_gc
= 0;
5869 dpyinfo
->mouse_face_mouse_frame
= 0;
5876 /* Destroy the X window of frame F. */
5879 x_destroy_window (f
)
5882 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
5884 x_free_frame_resources (f
);
5886 dpyinfo
->reference_count
--;
5890 /* Setting window manager hints. */
5892 /* Set the normal size hints for the window manager, for frame F.
5893 FLAGS is the flags word to use--or 0 meaning preserve the flags
5894 that the window now has.
5895 If USER_POSITION is nonzero, we set the USPosition
5896 flag (this is useful when FLAGS is 0). */
5898 x_wm_set_size_hint (f
, flags
, user_position
)
5903 int base_width
, base_height
, width_inc
, height_inc
;
5904 int min_rows
= 0, min_cols
= 0;
5905 XSizeHints
*size_hints
;
5907 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
5908 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
5909 width_inc
= FRAME_COLUMN_WIDTH (f
);
5910 height_inc
= FRAME_LINE_HEIGHT (f
);
5912 check_frame_size (f
, &min_rows
, &min_cols
);
5914 size_hints
= FRAME_SIZE_HINTS (f
);
5915 if (size_hints
== NULL
)
5917 size_hints
= FRAME_SIZE_HINTS (f
) = xmalloc (sizeof (XSizeHints
));
5918 bzero (size_hints
, sizeof (XSizeHints
));
5921 size_hints
->flags
|= PResizeInc
| PMinSize
| PBaseSize
;
5922 size_hints
->width_inc
= width_inc
;
5923 size_hints
->height_inc
= height_inc
;
5924 size_hints
->min_width
= base_width
+ min_cols
* width_inc
;
5925 size_hints
->min_height
= base_height
+ min_rows
* height_inc
;
5926 size_hints
->base_width
= base_width
;
5927 size_hints
->base_height
= base_height
;
5930 size_hints
->flags
= flags
;
5931 else if (user_position
)
5933 size_hints
->flags
&= ~ PPosition
;
5934 size_hints
->flags
|= USPosition
;
5938 #if 0 /* MAC_TODO: hide application instead of iconify? */
5939 /* Used for IconicState or NormalState */
5942 x_wm_set_window_state (f
, state
)
5946 #ifdef USE_X_TOOLKIT
5949 XtSetArg (al
[0], XtNinitialState
, state
);
5950 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
5951 #else /* not USE_X_TOOLKIT */
5952 Window window
= FRAME_X_WINDOW (f
);
5954 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
5955 f
->output_data
.x
->wm_hints
.initial_state
= state
;
5957 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
5958 #endif /* not USE_X_TOOLKIT */
5962 x_wm_set_icon_pixmap (f
, pixmap_id
)
5968 #ifndef USE_X_TOOLKIT
5969 Window window
= FRAME_X_WINDOW (f
);
5974 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
5975 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
5979 /* It seems there is no way to turn off use of an icon pixmap.
5980 The following line does it, only if no icon has yet been created,
5981 for some window managers. But with mwm it crashes.
5982 Some people say it should clear the IconPixmapHint bit in this case,
5983 but that doesn't work, and the X consortium said it isn't the
5984 right thing at all. Since there is no way to win,
5985 best to explicitly give up. */
5987 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
5993 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
5997 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
5998 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6001 #else /* not USE_X_TOOLKIT */
6003 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
6004 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6006 #endif /* not USE_X_TOOLKIT */
6009 #endif /* MAC_TODO */
6012 x_wm_set_icon_position (f
, icon_x
, icon_y
)
6016 #if 0 /* MAC_TODO: no icons on Mac */
6017 #ifdef USE_X_TOOLKIT
6018 Window window
= XtWindow (f
->output_data
.x
->widget
);
6020 Window window
= FRAME_X_WINDOW (f
);
6023 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
6024 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
6025 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
6027 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6028 #endif /* MAC_TODO */
6032 /***********************************************************************
6034 ***********************************************************************/
6036 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6039 x_get_font_info (f
, font_idx
)
6043 return (FRAME_MAC_FONT_TABLE (f
) + font_idx
);
6046 /* the global font name table */
6047 static char **font_name_table
= NULL
;
6048 static int font_name_table_size
= 0;
6049 static int font_name_count
= 0;
6051 /* Alist linking character set strings to Mac text encoding and Emacs
6053 static Lisp_Object Vmac_charset_info_alist
;
6056 create_text_encoding_info_alist ()
6058 Lisp_Object result
= Qnil
, rest
;
6060 for (rest
= Vmac_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
6062 Lisp_Object charset_info
= XCAR (rest
);
6063 Lisp_Object charset
, coding_system
, text_encoding
;
6064 Lisp_Object existing_info
;
6066 if (!(CONSP (charset_info
)
6067 && STRINGP (charset
= XCAR (charset_info
))
6068 && CONSP (XCDR (charset_info
))
6069 && INTEGERP (text_encoding
= XCAR (XCDR (charset_info
)))
6070 && CONSP (XCDR (XCDR (charset_info
)))
6071 && SYMBOLP (coding_system
= XCAR (XCDR (XCDR (charset_info
))))))
6074 existing_info
= assq_no_quit (text_encoding
, result
);
6075 if (NILP (existing_info
))
6076 result
= Fcons (list3 (text_encoding
, coding_system
, charset
),
6079 if (NILP (Fmember (charset
, XCDR (XCDR (existing_info
)))))
6080 XSETCDR (XCDR (existing_info
),
6081 Fcons (charset
, XCDR (XCDR (existing_info
))));
6089 decode_mac_font_name (name
, size
, coding_system
)
6092 Lisp_Object coding_system
;
6094 struct coding_system coding
;
6097 for (p
= name
; *p
; p
++)
6098 if (!isascii (*p
) || iscntrl (*p
))
6102 || NILP (coding_system
) || NILP (Fcoding_system_p (coding_system
)))
6106 /* MAC_TODO: Fix encoding system... */
6107 setup_coding_system (coding_system
, &coding
);
6108 coding
.src_multibyte
= 0;
6109 coding
.dst_multibyte
= 1;
6110 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6111 coding
.dst_bytes
= MAX_MULTsize
;
6112 coding
.destination
= (char *) alloca (size
);
6113 coding_decode_c_string(&coding
, name
, strlen(name
), qNil
);
6115 decode_coding (&coding
, name
, buf
, strlen (name
), size
- 1);
6116 bcopy (buf
, name
, coding
.produced
);
6117 name
[coding
.produced
] = '\0';
6123 mac_to_x_fontname (name
, size
, style
, charset
)
6131 char xf
[256], *result
, *p
;
6133 if (sscanf (name
, "%31[^-]-%255[^-]-%31s", foundry
, family
, cs
) == 3)
6137 strcpy(foundry
, "Apple");
6138 strcpy(family
, name
);
6141 sprintf (xf
, "%s-%c-normal--%d-%d-%d-%d-m-%d-%s",
6142 style
& bold
? "bold" : "medium", style
& italic
? 'i' : 'r',
6143 size
, size
* 10, size
? 75 : 0, size
? 75 : 0, size
* 10, charset
);
6145 result
= xmalloc (strlen (foundry
) + strlen (family
) + strlen (xf
) + 3 + 1);
6146 sprintf (result
, "-%s-%s-%s", foundry
, family
, xf
);
6147 for (p
= result
; *p
; p
++)
6153 /* Convert an X font spec to the corresponding mac font name, which
6154 can then be passed to GetFNum after conversion to a Pascal string.
6155 For ordinary Mac fonts, this should just be their names, like
6156 "monaco", "Taipei", etc. Fonts converted from the GNU intlfonts
6157 collection contain their charset designation in their names, like
6158 "ETL-Fixed-iso8859-1", "ETL-Fixed-koi8-r", etc. Both types of font
6159 names are handled accordingly. */
6161 x_font_name_to_mac_font_name (xf
, mf
, mf_decoded
, style
, cs
)
6162 char *xf
, *mf
, *mf_decoded
;
6168 char weight
[20], slant
[2], *p
;
6169 Lisp_Object charset_info
, coding_system
= Qnil
;
6170 struct coding_system coding
;
6174 if (sscanf (xf
, "-%31[^-]-%255[^-]-%19[^-]-%1[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%31s",
6175 foundry
, family
, weight
, slant
, cs
) != 5 &&
6176 sscanf (xf
, "-%31[^-]-%255[^-]-%19[^-]-%1[^-]-%*[^-]--%*[^-]-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]-%31s",
6177 foundry
, family
, weight
, slant
, cs
) != 5)
6181 if (strcmp (weight
, "bold") == 0)
6186 charset_info
= Fassoc (build_string (cs
), Vmac_charset_info_alist
);
6187 if (!NILP (charset_info
))
6189 strcpy (mf_decoded
, family
);
6190 coding_system
= Fcar (Fcdr (Fcdr (charset_info
)));
6193 sprintf (mf_decoded
, "%s-%s-%s", foundry
, family
, cs
);
6195 for (p
= mf_decoded
; *p
; p
++)
6196 if (!isascii (*p
) || iscntrl (*p
))
6200 || NILP (coding_system
) || NILP (Fcoding_system_p (coding_system
)))
6201 strcpy (mf
, mf_decoded
);
6203 /* MAC_TODO: Fix coding system to use objects */
6206 setup_coding_system (coding_system
, &coding
);
6207 coding
.src_multibyte
= 1;
6208 coding
.dst_multibyte
= 1;
6209 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6210 encode_coding (&coding
, mf_decoded
, mf
,
6211 strlen (mf_decoded
), sizeof (Str255
) - 1);
6212 mf
[coding
.produced
] = '\0';
6219 add_font_name_table_entry (char *font_name
)
6221 if (font_name_table_size
== 0)
6223 font_name_table_size
= 16;
6224 font_name_table
= (char **)
6225 xmalloc (font_name_table_size
* sizeof (char *));
6227 else if (font_name_count
+ 1 >= font_name_table_size
)
6229 font_name_table_size
+= 16;
6230 font_name_table
= (char **)
6231 xrealloc (font_name_table
,
6232 font_name_table_size
* sizeof (char *));
6235 font_name_table
[font_name_count
++] = font_name
;
6238 /* Sets up the table font_name_table to contain the list of all fonts
6239 in the system the first time the table is used so that the Resource
6240 Manager need not be accessed every time this information is
6244 init_font_name_table ()
6246 #if TARGET_API_MAC_CARBON
6247 FMFontFamilyIterator ffi
;
6248 FMFontFamilyInstanceIterator ffii
;
6250 Lisp_Object text_encoding_info_alist
;
6251 struct gcpro gcpro1
;
6253 /* Create a dummy instance iterator here to avoid creating and
6254 destroying it in the loop. */
6255 if (FMCreateFontFamilyInstanceIterator (0, &ffii
) != noErr
)
6257 /* Create an iterator to enumerate the font families. */
6258 if (FMCreateFontFamilyIterator (NULL
, NULL
, kFMDefaultOptions
, &ffi
)
6261 FMDisposeFontFamilyInstanceIterator (&ffii
);
6265 text_encoding_info_alist
= create_text_encoding_info_alist ();
6267 GCPRO1 (text_encoding_info_alist
);
6269 while (FMGetNextFontFamily (&ffi
, &ff
) == noErr
)
6275 TextEncoding encoding
;
6276 TextEncodingBase sc
;
6277 Lisp_Object text_encoding_info
;
6279 if (FMGetFontFamilyName (ff
, name
) != noErr
)
6285 if (FMGetFontFamilyTextEncoding (ff
, &encoding
) != noErr
)
6287 sc
= GetTextEncodingBase (encoding
);
6288 text_encoding_info
= assq_no_quit (make_number (sc
),
6289 text_encoding_info_alist
);
6290 if (!NILP (text_encoding_info
))
6291 decode_mac_font_name (name
, sizeof (name
),
6292 XCAR (XCDR (text_encoding_info
)));
6294 text_encoding_info
= assq_no_quit (make_number (kTextEncodingMacRoman
),
6295 text_encoding_info_alist
);
6297 /* Point the instance iterator at the current font family. */
6298 if (FMResetFontFamilyInstanceIterator (ff
, &ffii
) != noErr
)
6301 while (FMGetNextFontFamilyInstance (&ffii
, &font
, &style
, &size
)
6304 Lisp_Object rest
= XCDR (XCDR (text_encoding_info
));
6306 for (; !NILP (rest
); rest
= XCDR (rest
))
6308 char *cs
= SDATA (XCAR (rest
));
6312 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
6314 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
6316 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
6318 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
6324 add_font_name_table_entry (mac_to_x_fontname (name
, size
,
6333 /* Dispose of the iterators. */
6334 FMDisposeFontFamilyIterator (&ffi
);
6335 FMDisposeFontFamilyInstanceIterator (&ffii
);
6336 #else /* !TARGET_API_MAC_CARBON */
6338 SInt16 fontnum
, old_fontnum
;
6339 int num_mac_fonts
= CountResources('FOND');
6341 Handle font_handle
, font_handle_2
;
6342 short id
, scriptcode
;
6345 struct FontAssoc
*fat
;
6346 struct AsscEntry
*assc_entry
;
6347 Lisp_Object text_encoding_info_alist
, text_encoding_info
;
6348 struct gcpro gcpro1
;
6350 GetPort (&port
); /* save the current font number used */
6351 old_fontnum
= port
->txFont
;
6353 text_encoding_info_alist
= create_text_encoding_info_alist ();
6355 GCPRO1 (text_encoding_info_alist
);
6357 for (i
= 1; i
<= num_mac_fonts
; i
++) /* get all available fonts */
6359 font_handle
= GetIndResource ('FOND', i
);
6363 GetResInfo (font_handle
, &id
, &type
, name
);
6364 GetFNum (name
, &fontnum
);
6370 scriptcode
= FontToScript (fontnum
);
6371 text_encoding_info
= assq_no_quit (make_number (scriptcode
),
6372 text_encoding_info_alist
);
6373 if (!NILP (text_encoding_info
))
6374 decode_mac_font_name (name
, sizeof (name
),
6375 XCAR (XCDR (text_encoding_info
)));
6377 text_encoding_info
= assq_no_quit (make_number (smRoman
),
6378 text_encoding_info_alist
);
6381 HLock (font_handle
);
6383 if (GetResourceSizeOnDisk (font_handle
)
6384 >= sizeof (struct FamRec
))
6386 fat
= (struct FontAssoc
*) (*font_handle
6387 + sizeof (struct FamRec
));
6389 = (struct AsscEntry
*) (*font_handle
6390 + sizeof (struct FamRec
)
6391 + sizeof (struct FontAssoc
));
6393 for (j
= 0; j
<= fat
->numAssoc
; j
++, assc_entry
++)
6395 Lisp_Object rest
= XCDR (XCDR (text_encoding_info
));
6397 for (; !NILP (rest
); rest
= XCDR (rest
))
6399 char *cs
= SDATA (XCAR (rest
));
6401 add_font_name_table_entry (mac_to_x_fontname (name
,
6402 assc_entry
->fontSize
,
6403 assc_entry
->fontStyle
,
6409 HUnlock (font_handle
);
6410 font_handle_2
= GetNextFOND (font_handle
);
6411 ReleaseResource (font_handle
);
6412 font_handle
= font_handle_2
;
6414 while (ResError () == noErr
&& font_handle
);
6419 TextFont (old_fontnum
);
6420 #endif /* !TARGET_API_MAC_CARBON */
6425 mac_clear_font_name_table ()
6429 for (i
= 0; i
< font_name_count
; i
++)
6430 xfree (font_name_table
[i
]);
6431 xfree (font_name_table
);
6432 font_name_table
= NULL
;
6433 font_name_table_size
= font_name_count
= 0;
6437 enum xlfd_scalable_field_index
6439 XLFD_SCL_PIXEL_SIZE
,
6440 XLFD_SCL_POINT_SIZE
,
6445 static int xlfd_scalable_fields
[] =
6454 mac_c_string_match (regexp
, string
, nonspecial
, exact
)
6456 const char *string
, *nonspecial
;
6461 if (strcmp (string
, nonspecial
) == 0)
6462 return build_string (string
);
6464 else if (strstr (string
, nonspecial
))
6466 Lisp_Object str
= build_string (string
);
6468 if (fast_string_match (regexp
, str
) >= 0)
6476 mac_do_list_fonts (pattern
, maxnames
)
6481 Lisp_Object font_list
= Qnil
, pattern_regex
, fontname
;
6482 char *regex
= (char *) alloca (strlen (pattern
) * 2 + 3);
6484 int scl_val
[XLFD_SCL_LAST
], *field
, *val
;
6485 char *longest_start
, *cur_start
, *nonspecial
;
6486 int longest_len
, exact
;
6488 if (font_name_table
== NULL
) /* Initialize when first used. */
6489 init_font_name_table ();
6491 for (i
= 0; i
< XLFD_SCL_LAST
; i
++)
6494 /* If the pattern contains 14 dashes and one of PIXEL_SIZE,
6495 POINT_SIZE, and AVGWIDTH fields is explicitly specified, scalable
6496 fonts are scaled according to the specified size. */
6499 field
= xlfd_scalable_fields
;
6507 if ('0' <= *ptr
&& *ptr
<= '9')
6509 *val
= *ptr
++ - '0';
6510 while ('0' <= *ptr
&& *ptr
<= '9' && *val
< 10000)
6511 *val
= *val
* 10 + *ptr
++ - '0';
6518 ptr
= strchr (ptr
, '-');
6521 while (ptr
&& i
< 14);
6523 if (i
== 14 && ptr
== NULL
)
6525 if (scl_val
[XLFD_SCL_PIXEL_SIZE
] < 0)
6526 scl_val
[XLFD_SCL_PIXEL_SIZE
] =
6527 (scl_val
[XLFD_SCL_POINT_SIZE
] > 0 ? scl_val
[XLFD_SCL_POINT_SIZE
] / 10
6528 : (scl_val
[XLFD_SCL_AVGWIDTH
] > 0 ? scl_val
[XLFD_SCL_AVGWIDTH
] / 10
6530 if (scl_val
[XLFD_SCL_POINT_SIZE
] < 0)
6531 scl_val
[XLFD_SCL_POINT_SIZE
] =
6532 (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0 ? scl_val
[XLFD_SCL_PIXEL_SIZE
] * 10
6533 : (scl_val
[XLFD_SCL_AVGWIDTH
] > 0 ? scl_val
[XLFD_SCL_AVGWIDTH
]
6535 if (scl_val
[XLFD_SCL_AVGWIDTH
] < 0)
6536 scl_val
[XLFD_SCL_AVGWIDTH
] =
6537 (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0 ? scl_val
[XLFD_SCL_PIXEL_SIZE
] * 10
6538 : (scl_val
[XLFD_SCL_POINT_SIZE
] > 0 ? scl_val
[XLFD_SCL_POINT_SIZE
]
6542 scl_val
[XLFD_SCL_PIXEL_SIZE
] = -1;
6547 longest_start
= cur_start
= ptr
;
6551 /* Turn pattern into a regexp and do a regexp match. Also find the
6552 longest substring containing no special characters. */
6553 for (; *pattern
; pattern
++)
6555 if (*pattern
== '?' || *pattern
== '*')
6557 if (ptr
- cur_start
> longest_len
)
6559 longest_start
= cur_start
;
6560 longest_len
= ptr
- cur_start
;
6564 if (*pattern
== '?')
6566 else /* if (*pattern == '*') */
6574 *ptr
++ = tolower (*pattern
);
6577 if (ptr
- cur_start
> longest_len
)
6579 longest_start
= cur_start
;
6580 longest_len
= ptr
- cur_start
;
6586 nonspecial
= xmalloc (longest_len
+ 1);
6587 strncpy (nonspecial
, longest_start
, longest_len
);
6588 nonspecial
[longest_len
] = '\0';
6590 pattern_regex
= build_string (regex
);
6592 for (i
= 0; i
< font_name_count
; i
++)
6594 fontname
= mac_c_string_match (pattern_regex
, font_name_table
[i
],
6596 if (!NILP (fontname
))
6598 font_list
= Fcons (fontname
, font_list
);
6599 if (exact
|| maxnames
> 0 && ++n_fonts
>= maxnames
)
6602 else if (scl_val
[XLFD_SCL_PIXEL_SIZE
] > 0
6603 && (ptr
= strstr (font_name_table
[i
], "-0-0-0-0-m-0-")))
6605 int former_len
= ptr
- font_name_table
[i
];
6607 scaled
= xmalloc (strlen (font_name_table
[i
]) + 20 + 1);
6608 memcpy (scaled
, font_name_table
[i
], former_len
);
6609 sprintf (scaled
+ former_len
,
6610 "-%d-%d-75-75-m-%d-%s",
6611 scl_val
[XLFD_SCL_PIXEL_SIZE
],
6612 scl_val
[XLFD_SCL_POINT_SIZE
],
6613 scl_val
[XLFD_SCL_AVGWIDTH
],
6614 ptr
+ sizeof ("-0-0-0-0-m-0-") - 1);
6615 fontname
= mac_c_string_match (pattern_regex
, scaled
,
6618 if (!NILP (fontname
))
6620 font_list
= Fcons (fontname
, font_list
);
6621 if (exact
|| maxnames
> 0 && ++n_fonts
>= maxnames
)
6632 /* Return a list of names of available fonts matching PATTERN on frame F.
6634 Frame F null means we have not yet created any frame on Mac, and
6635 consult the first display in x_display_list. MAXNAMES sets a limit
6636 on how many fonts to match. */
6639 x_list_fonts (f
, pattern
, size
, maxnames
)
6641 Lisp_Object pattern
;
6644 Lisp_Object list
= Qnil
, patterns
, tem
, key
;
6645 struct mac_display_info
*dpyinfo
6646 = f
? FRAME_MAC_DISPLAY_INFO (f
) : x_display_list
;
6648 xassert (size
<= 0);
6650 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6651 if (NILP (patterns
))
6652 patterns
= Fcons (pattern
, Qnil
);
6654 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
6656 pattern
= XCAR (patterns
);
6658 if (!STRINGP (pattern
))
6661 tem
= XCAR (XCDR (dpyinfo
->name_list_element
));
6662 key
= Fcons (pattern
, make_number (maxnames
));
6664 list
= Fassoc (key
, tem
);
6667 list
= Fcdr_safe (list
);
6668 /* We have a cashed list. Don't have to get the list again. */
6673 list
= mac_do_list_fonts (SDATA (pattern
), maxnames
);
6676 /* MAC_TODO: add code for matching outline fonts here */
6678 /* Now store the result in the cache. */
6679 XSETCAR (XCDR (dpyinfo
->name_list_element
),
6680 Fcons (Fcons (key
, list
),
6681 XCAR (XCDR (dpyinfo
->name_list_element
))));
6684 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6693 /* Check that FONT is valid on frame F. It is if it can be found in F's
6697 x_check_font (f
, font
)
6702 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6704 xassert (font
!= NULL
);
6706 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6707 if (dpyinfo
->font_table
[i
].name
6708 && font
== dpyinfo
->font_table
[i
].font
)
6711 xassert (i
< dpyinfo
->n_fonts
);
6714 #endif /* GLYPH_DEBUG != 0 */
6716 /* Set *W to the minimum width, *H to the minimum font height of FONT.
6717 Note: There are (broken) X fonts out there with invalid XFontStruct
6718 min_bounds contents. For example, handa@etl.go.jp reports that
6719 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
6720 have font->min_bounds.width == 0. */
6723 x_font_min_bounds (font
, w
, h
)
6724 MacFontStruct
*font
;
6727 *h
= FONT_HEIGHT (font
);
6728 *w
= font
->min_bounds
.width
;
6732 /* Compute the smallest character width and smallest font height over
6733 all fonts available on frame F. Set the members smallest_char_width
6734 and smallest_font_height in F's x_display_info structure to
6735 the values computed. Value is non-zero if smallest_font_height or
6736 smallest_char_width become smaller than they were before. */
6739 x_compute_min_glyph_bounds (f
)
6743 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
6744 MacFontStruct
*font
;
6745 int old_width
= dpyinfo
->smallest_char_width
;
6746 int old_height
= dpyinfo
->smallest_font_height
;
6748 dpyinfo
->smallest_font_height
= 100000;
6749 dpyinfo
->smallest_char_width
= 100000;
6751 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
6752 if (dpyinfo
->font_table
[i
].name
)
6754 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
6757 font
= (MacFontStruct
*) fontp
->font
;
6758 xassert (font
!= (MacFontStruct
*) ~0);
6759 x_font_min_bounds (font
, &w
, &h
);
6761 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
6762 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
6765 xassert (dpyinfo
->smallest_char_width
> 0
6766 && dpyinfo
->smallest_font_height
> 0);
6768 return (dpyinfo
->n_fonts
== 1
6769 || dpyinfo
->smallest_char_width
< old_width
6770 || dpyinfo
->smallest_font_height
< old_height
);
6774 /* Determine whether given string is a fully-specified XLFD: all 14
6775 fields are present, none is '*'. */
6778 is_fully_specified_xlfd (char *p
)
6786 for (i
= 0; i
< 13; i
++)
6788 q
= strchr (p
+ 1, '-');
6791 if (q
- p
== 2 && *(p
+ 1) == '*')
6796 if (strchr (p
+ 1, '-') != NULL
)
6799 if (*(p
+ 1) == '*' && *(p
+ 2) == '\0')
6806 const int kDefaultFontSize
= 12;
6809 /* XLoadQueryFont creates and returns an internal representation for a
6810 font in a MacFontStruct struct. There is really no concept
6811 corresponding to "loading" a font on the Mac. But we check its
6812 existence and find the font number and all other information for it
6813 and store them in the returned MacFontStruct. */
6815 static MacFontStruct
*
6816 XLoadQueryFont (Display
*dpy
, char *fontname
)
6818 int i
, size
, point_size
, avgwidth
, is_two_byte_font
, char_width
;
6821 SInt16 old_fontnum
, old_fontsize
;
6823 Str255 mfontname
, mfontname_decoded
;
6827 #if TARGET_API_MAC_CARBON
6828 TextEncoding encoding
;
6833 MacFontStruct
*font
;
6834 FontInfo the_fontinfo
;
6836 UInt32 old_flags
, new_flags
;
6839 if (is_fully_specified_xlfd (fontname
))
6843 Lisp_Object matched_fonts
;
6845 matched_fonts
= mac_do_list_fonts (fontname
, 1);
6846 if (NILP (matched_fonts
))
6848 name
= SDATA (XCAR (matched_fonts
));
6851 GetPort (&port
); /* save the current font number used */
6852 #if TARGET_API_MAC_CARBON
6853 old_fontnum
= GetPortTextFont (port
);
6854 old_fontsize
= GetPortTextSize (port
);
6855 old_fontface
= GetPortTextFace (port
);
6857 old_fontnum
= port
->txFont
;
6858 old_fontsize
= port
->txSize
;
6859 old_fontface
= port
->txFace
;
6862 if (sscanf (name
, "-%*[^-]-%*[^-]-%*[^-]-%*c-%*[^-]--%d-%d-%*[^-]-%*[^-]-%*c-%d-%*s", &size
, &point_size
, &avgwidth
) != 3)
6868 size
= point_size
/ 10;
6869 else if (avgwidth
> 0)
6870 size
= avgwidth
/ 10;
6873 size
= kDefaultFontSize
;
6875 x_font_name_to_mac_font_name (name
, mfontname
, mfontname_decoded
,
6876 &fontface
, charset
);
6878 #if TARGET_API_MAC_CARBON
6879 fontnum
= FMGetFontFamilyFromName (mfontname
);
6880 if (fontnum
== kInvalidFontFamily
6881 || FMGetFontFamilyTextEncoding (fontnum
, &encoding
) != noErr
)
6883 scriptcode
= GetTextEncodingBase (encoding
);
6885 GetFNum (mfontname
, &fontnum
);
6888 scriptcode
= FontToScript (fontnum
);
6891 font
= (MacFontStruct
*) xmalloc (sizeof (struct MacFontStruct
));
6893 font
->mac_fontnum
= fontnum
;
6894 font
->mac_fontsize
= size
;
6895 font
->mac_fontface
= fontface
;
6896 font
->mac_scriptcode
= scriptcode
;
6898 /* Apple Japanese (SJIS) font is listed as both
6899 "*-jisx0208.1983-sjis" (Japanese script) and "*-jisx0201.1976-0"
6900 (Roman script) in init_font_name_table (). The latter should be
6901 treated as a one-byte font. */
6902 if (scriptcode
== smJapanese
&& strcmp (charset
, "jisx0201.1976-0") == 0)
6903 font
->mac_scriptcode
= smRoman
;
6905 font
->full_name
= mac_to_x_fontname (mfontname_decoded
, size
, fontface
, charset
);
6907 is_two_byte_font
= font
->mac_scriptcode
== smJapanese
||
6908 font
->mac_scriptcode
== smTradChinese
||
6909 font
->mac_scriptcode
== smSimpChinese
||
6910 font
->mac_scriptcode
== smKorean
;
6914 TextFace (fontface
);
6916 GetFontInfo (&the_fontinfo
);
6918 font
->ascent
= the_fontinfo
.ascent
;
6919 font
->descent
= the_fontinfo
.descent
;
6921 font
->min_byte1
= 0;
6922 if (is_two_byte_font
)
6923 font
->max_byte1
= 1;
6925 font
->max_byte1
= 0;
6926 font
->min_char_or_byte2
= 0x20;
6927 font
->max_char_or_byte2
= 0xff;
6929 if (is_two_byte_font
)
6931 /* Use the width of an "ideographic space" of that font because
6932 the_fontinfo.widMax returns the wrong width for some fonts. */
6933 switch (font
->mac_scriptcode
)
6936 char_width
= StringWidth("\p\x81\x40");
6939 char_width
= StringWidth("\p\xa1\x40");
6942 char_width
= StringWidth("\p\xa1\xa1");
6945 char_width
= StringWidth("\p\xa1\xa1");
6950 /* Do this instead of use the_fontinfo.widMax, which incorrectly
6951 returns 15 for 12-point Monaco! */
6952 char_width
= CharWidth ('m');
6954 if (is_two_byte_font
)
6956 font
->per_char
= NULL
;
6958 if (fontface
& italic
)
6959 font
->max_bounds
.rbearing
= char_width
+ 1;
6961 font
->max_bounds
.rbearing
= char_width
;
6962 font
->max_bounds
.lbearing
= 0;
6963 font
->max_bounds
.width
= char_width
;
6964 font
->max_bounds
.ascent
= the_fontinfo
.ascent
;
6965 font
->max_bounds
.descent
= the_fontinfo
.descent
;
6967 font
->min_bounds
= font
->max_bounds
;
6971 font
->per_char
= (XCharStruct
*)
6972 xmalloc (sizeof (XCharStruct
) * (0xff - 0x20 + 1));
6974 int c
, min_width
, max_width
;
6975 Rect char_bounds
, min_bounds
, max_bounds
;
6978 min_width
= max_width
= char_width
;
6979 SetRect (&min_bounds
, -32767, -32767, 32767, 32767);
6980 SetRect (&max_bounds
, 0, 0, 0, 0);
6981 for (c
= 0x20; c
<= 0xff; c
++)
6984 char_width
= CharWidth (ch
);
6985 QDTextBounds (1, &ch
, &char_bounds
);
6986 STORE_XCHARSTRUCT (font
->per_char
[c
- 0x20],
6987 char_width
, char_bounds
);
6988 /* Some Japanese fonts (in SJIS encoding) return 0 as the
6989 character width of 0x7f. */
6992 min_width
= min (min_width
, char_width
);
6993 max_width
= max (max_width
, char_width
);
6995 if (!EmptyRect (&char_bounds
))
6997 SetRect (&min_bounds
,
6998 max (min_bounds
.left
, char_bounds
.left
),
6999 max (min_bounds
.top
, char_bounds
.top
),
7000 min (min_bounds
.right
, char_bounds
.right
),
7001 min (min_bounds
.bottom
, char_bounds
.bottom
));
7002 UnionRect (&max_bounds
, &char_bounds
, &max_bounds
);
7005 STORE_XCHARSTRUCT (font
->min_bounds
, min_width
, min_bounds
);
7006 STORE_XCHARSTRUCT (font
->max_bounds
, max_width
, max_bounds
);
7007 if (min_width
== max_width
7008 && max_bounds
.left
>= 0 && max_bounds
.right
<= max_width
)
7010 /* Fixed width and no overhangs. */
7011 xfree (font
->per_char
);
7012 font
->per_char
= NULL
;
7017 TextFont (old_fontnum
); /* restore previous font number, size and face */
7018 TextSize (old_fontsize
);
7019 TextFace (old_fontface
);
7026 mac_unload_font (dpyinfo
, font
)
7027 struct mac_display_info
*dpyinfo
;
7030 xfree (font
->full_name
);
7032 xfree (font
->per_char
);
7037 /* Load font named FONTNAME of the size SIZE for frame F, and return a
7038 pointer to the structure font_info while allocating it dynamically.
7039 If SIZE is 0, load any size of font.
7040 If loading is failed, return NULL. */
7043 x_load_font (f
, fontname
, size
)
7045 register char *fontname
;
7048 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7049 Lisp_Object font_names
;
7051 /* Get a list of all the fonts that match this name. Once we
7052 have a list of matching fonts, we compare them against the fonts
7053 we already have by comparing names. */
7054 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
7056 if (!NILP (font_names
))
7061 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7062 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
7063 if (dpyinfo
->font_table
[i
].name
7064 && (!strcmp (dpyinfo
->font_table
[i
].name
,
7065 SDATA (XCAR (tail
)))
7066 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
7067 SDATA (XCAR (tail
)))))
7068 return (dpyinfo
->font_table
+ i
);
7073 /* Load the font and add it to the table. */
7076 struct MacFontStruct
*font
;
7077 struct font_info
*fontp
;
7078 unsigned long value
;
7081 fontname
= (char *) SDATA (XCAR (font_names
));
7084 font
= (MacFontStruct
*) XLoadQueryFont (FRAME_MAC_DISPLAY (f
), fontname
);
7089 /* Find a free slot in the font table. */
7090 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
7091 if (dpyinfo
->font_table
[i
].name
== NULL
)
7094 /* If no free slot found, maybe enlarge the font table. */
7095 if (i
== dpyinfo
->n_fonts
7096 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
7099 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
7100 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
7102 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
7105 fontp
= dpyinfo
->font_table
+ i
;
7106 if (i
== dpyinfo
->n_fonts
)
7109 /* Now fill in the slots of *FONTP. */
7111 bzero (fontp
, sizeof (*fontp
));
7113 fontp
->font_idx
= i
;
7114 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
7115 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
7117 if (font
->min_bounds
.width
== font
->max_bounds
.width
)
7119 /* Fixed width font. */
7120 fontp
->average_width
= fontp
->space_width
= font
->min_bounds
.width
;
7127 char2b
.byte1
= 0x00, char2b
.byte2
= 0x20;
7128 pcm
= mac_per_char_metric (font
, &char2b
, 0);
7130 fontp
->space_width
= pcm
->width
;
7132 fontp
->space_width
= FONT_WIDTH (font
);
7136 int width
= pcm
->width
;
7137 for (char2b
.byte2
= 33; char2b
.byte2
<= 126; char2b
.byte2
++)
7138 if ((pcm
= mac_per_char_metric (font
, &char2b
, 0)) != NULL
)
7139 width
+= pcm
->width
;
7140 fontp
->average_width
= width
/ 95;
7143 fontp
->average_width
= FONT_WIDTH (font
);
7146 fontp
->full_name
= (char *) xmalloc (strlen (font
->full_name
) + 1);
7147 bcopy (font
->full_name
, fontp
->full_name
, strlen (font
->full_name
) + 1);
7149 fontp
->size
= font
->max_bounds
.width
;
7150 fontp
->height
= FONT_HEIGHT (font
);
7152 /* For some font, ascent and descent in max_bounds field is
7153 larger than the above value. */
7154 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
7155 if (max_height
> fontp
->height
)
7156 fontp
->height
= max_height
;
7159 #if 0 /* MAC_TODO: fill these out with more reasonably values */
7161 /* MAC_TODO: The script encoding is irrelevant in unicode? */
7162 /* The slot `encoding' specifies how to map a character
7163 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
7164 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
7165 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
7166 2:0xA020..0xFF7F). For the moment, we don't know which charset
7167 uses this font. So, we set information in fontp->encoding[1]
7168 which is never used by any charset. If mapping can't be
7169 decided, set FONT_ENCODING_NOT_DECIDED. */
7170 if (font
->mac_scriptcode
== smJapanese
)
7171 fontp
->encoding
[1] = 4;
7175 = (font
->max_byte1
== 0
7177 ? (font
->min_char_or_byte2
< 0x80
7178 ? (font
->max_char_or_byte2
< 0x80
7179 ? 0 /* 0x20..0x7F */
7180 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
7181 : 1) /* 0xA0..0xFF */
7183 : (font
->min_byte1
< 0x80
7184 ? (font
->max_byte1
< 0x80
7185 ? (font
->min_char_or_byte2
< 0x80
7186 ? (font
->max_char_or_byte2
< 0x80
7187 ? 0 /* 0x2020..0x7F7F */
7188 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
7189 : 3) /* 0x20A0..0x7FFF */
7190 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
7191 : (font
->min_char_or_byte2
< 0x80
7192 ? (font
->max_char_or_byte2
< 0x80
7193 ? 2 /* 0xA020..0xFF7F */
7194 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
7195 : 1))); /* 0xA0A0..0xFFFF */
7198 fontp
->baseline_offset
7199 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
7200 ? (long) value
: 0);
7201 fontp
->relative_compose
7202 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
7203 ? (long) value
: 0);
7204 fontp
->default_ascent
7205 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
7206 ? (long) value
: 0);
7208 fontp
->baseline_offset
= 0;
7209 fontp
->relative_compose
= 0;
7210 fontp
->default_ascent
= 0;
7213 /* Set global flag fonts_changed_p to non-zero if the font loaded
7214 has a character with a smaller width than any other character
7215 before, or if the font loaded has a smalle>r height than any
7216 other font loaded before. If this happens, it will make a
7217 glyph matrix reallocation necessary. */
7218 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
7225 /* Return a pointer to struct font_info of a font named FONTNAME for
7226 frame F. If no such font is loaded, return NULL. */
7229 x_query_font (f
, fontname
)
7231 register char *fontname
;
7233 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7236 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7237 if (dpyinfo
->font_table
[i
].name
7238 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
7239 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
7240 return (dpyinfo
->font_table
+ i
);
7245 /* Find a CCL program for a font specified by FONTP, and set the member
7246 `encoder' of the structure. */
7249 x_find_ccl_program (fontp
)
7250 struct font_info
*fontp
;
7252 Lisp_Object list
, elt
;
7254 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
7258 && STRINGP (XCAR (elt
))
7259 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
7265 struct ccl_program
*ccl
7266 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
7268 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
7271 fontp
->font_encoder
= ccl
;
7277 /* The Mac Event loop code */
7279 #if !TARGET_API_MAC_CARBON
7281 #include <Quickdraw.h>
7282 #include <Balloons.h>
7283 #include <Devices.h>
7285 #include <Gestalt.h>
7287 #include <Processes.h>
7289 #include <ToolUtils.h>
7290 #include <TextUtils.h>
7291 #include <Dialogs.h>
7294 #include <Resources.h>
7299 #endif /* ! TARGET_API_MAC_CARBON */
7304 #define WINDOW_RESOURCE 128
7305 #define TERM_WINDOW_RESOURCE 129
7307 #define DEFAULT_NUM_COLS 80
7309 #define MIN_DOC_SIZE 64
7310 #define MAX_DOC_SIZE 32767
7312 #define EXTRA_STACK_ALLOC (256 * 1024)
7314 #define ARGV_STRING_LIST_ID 129
7315 #define ABOUT_ALERT_ID 128
7316 #define RAM_TOO_LARGE_ALERT_ID 129
7318 /* Contains the string "reverse", which is a constant for mouse button emu.*/
7319 Lisp_Object Qreverse
;
7321 /* True if using command key as meta key. */
7322 Lisp_Object Vmac_command_key_is_meta
;
7324 /* Modifier associated with the option key, or nil for normal behavior. */
7325 Lisp_Object Vmac_option_modifier
;
7327 /* True if the ctrl and meta keys should be reversed. */
7328 Lisp_Object Vmac_reverse_ctrl_meta
;
7330 /* True if the option and command modifiers should be used to emulate
7331 a three button mouse */
7332 Lisp_Object Vmac_emulate_three_button_mouse
;
7334 #if USE_CARBON_EVENTS
7335 /* True if the mouse wheel button (i.e. button 4) should map to
7336 mouse-2, instead of mouse-3. */
7337 Lisp_Object Vmac_wheel_button_is_mouse_2
;
7339 /* If Non-nil, the Mac "Command" key is passed on to the Mac Toolbox
7340 for processing before Emacs sees it. */
7341 Lisp_Object Vmac_pass_command_to_system
;
7343 /* If Non-nil, the Mac "Control" key is passed on to the Mac Toolbox
7344 for processing before Emacs sees it. */
7345 Lisp_Object Vmac_pass_control_to_system
;
7347 /* Points to the variable `inev' in the function XTread_socket. It is
7348 used for passing an input event to the function back from
7349 Carbon/Apple event handlers. */
7350 static struct input_event
*read_socket_inev
= NULL
;
7353 /* Set in term/mac-win.el to indicate that event loop can now generate
7354 drag and drop events. */
7355 Lisp_Object Qmac_ready_for_drag_n_drop
;
7357 Point saved_menu_event_location
;
7360 static void init_required_apple_events (void);
7362 do_ae_open_application (const AppleEvent
*, AppleEvent
*, long);
7364 do_ae_print_documents (const AppleEvent
*, AppleEvent
*, long);
7365 static pascal OSErr
do_ae_open_documents (AppleEvent
*, AppleEvent
*, long);
7366 static pascal OSErr
do_ae_quit_application (AppleEvent
*, AppleEvent
*, long);
7368 #if TARGET_API_MAC_CARBON
7370 static pascal OSErr
mac_do_track_drag (DragTrackingMessage
, WindowPtr
, void*, DragReference
);
7371 static pascal OSErr
mac_do_receive_drag (WindowPtr
, void*, DragReference
);
7372 static DragTrackingHandlerUPP mac_do_track_dragUPP
= NULL
;
7373 static DragReceiveHandlerUPP mac_do_receive_dragUPP
= NULL
;
7376 static Lisp_Object Qapplication
, Qabout
;
7377 #if USE_CARBON_EVENTS
7379 extern void init_service_handler ();
7380 static Lisp_Object Qpreferences
, Qservices
, Qpaste
, Qperform
;
7382 /* Window Event Handler */
7383 static pascal OSStatus
mac_handle_window_event (EventHandlerCallRef
,
7386 OSErr
install_window_handler (WindowPtr
);
7388 extern void init_emacs_passwd_dir ();
7389 extern int emacs_main (int, char **, char **);
7391 extern void initialize_applescript();
7392 extern void terminate_applescript();
7395 #if USE_CARBON_EVENTS
7396 mac_to_emacs_modifiers (UInt32 mods
)
7398 mac_to_emacs_modifiers (EventModifiers mods
)
7401 unsigned int result
= 0;
7402 if (mods
& macShiftKey
)
7403 result
|= shift_modifier
;
7404 if (mods
& macCtrlKey
)
7405 result
|= ctrl_modifier
;
7406 if (mods
& macMetaKey
)
7407 result
|= meta_modifier
;
7408 if (NILP (Vmac_command_key_is_meta
) && (mods
& macAltKey
))
7409 result
|= alt_modifier
;
7410 if (!NILP (Vmac_option_modifier
) && (mods
& optionKey
)) {
7411 Lisp_Object val
= Fget(Vmac_option_modifier
, Qmodifier_value
);
7413 result
|= XUINT(val
);
7420 mac_get_emulated_btn ( UInt32 modifiers
)
7423 if (!NILP (Vmac_emulate_three_button_mouse
)) {
7424 int cmdIs3
= !EQ (Vmac_emulate_three_button_mouse
, Qreverse
);
7425 if (modifiers
& cmdKey
)
7426 result
= cmdIs3
? 2 : 1;
7427 else if (modifiers
& optionKey
)
7428 result
= cmdIs3
? 1 : 2;
7433 #if USE_CARBON_EVENTS
7434 /* Obtains the event modifiers from the event ref and then calls
7435 mac_to_emacs_modifiers. */
7437 mac_event_to_emacs_modifiers (EventRef eventRef
)
7440 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
7441 sizeof (UInt32
), NULL
, &mods
);
7442 if (!NILP (Vmac_emulate_three_button_mouse
) &&
7443 GetEventClass(eventRef
) == kEventClassMouse
)
7445 mods
&= ~(optionKey
| cmdKey
);
7447 return mac_to_emacs_modifiers (mods
);
7450 /* Given an event ref, return the code to use for the mouse button
7451 code in the emacs input_event. */
7453 mac_get_mouse_btn (EventRef ref
)
7455 EventMouseButton result
= kEventMouseButtonPrimary
;
7456 GetEventParameter (ref
, kEventParamMouseButton
, typeMouseButton
, NULL
,
7457 sizeof (EventMouseButton
), NULL
, &result
);
7460 case kEventMouseButtonPrimary
:
7461 if (NILP (Vmac_emulate_three_button_mouse
))
7465 GetEventParameter (ref
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
7466 sizeof (UInt32
), NULL
, &mods
);
7467 return mac_get_emulated_btn(mods
);
7469 case kEventMouseButtonSecondary
:
7470 return NILP (Vmac_wheel_button_is_mouse_2
) ? 1 : 2;
7471 case kEventMouseButtonTertiary
:
7472 case 4: /* 4 is the number for the mouse wheel button */
7473 return NILP (Vmac_wheel_button_is_mouse_2
) ? 2 : 1;
7479 /* Normally, ConvertEventRefToEventRecord will correctly handle all
7480 events. However the click of the mouse wheel is not converted to a
7481 mouseDown or mouseUp event. Likewise for dead key down events.
7482 This calls ConvertEventRef, but then checks to see if it is a mouse
7483 up/down, or a dead key down carbon event that has not been
7484 converted, and if so, converts it by hand (to be picked up in the
7485 XTread_socket loop). */
7486 static Boolean
mac_convert_event_ref (EventRef eventRef
, EventRecord
*eventRec
)
7488 Boolean result
= ConvertEventRefToEventRecord (eventRef
, eventRec
);
7493 switch (GetEventClass (eventRef
))
7495 case kEventClassMouse
:
7496 switch (GetEventKind (eventRef
))
7498 case kEventMouseDown
:
7499 eventRec
->what
= mouseDown
;
7504 eventRec
->what
= mouseUp
;
7513 case kEventClassKeyboard
:
7514 switch (GetEventKind (eventRef
))
7516 case kEventRawKeyDown
:
7518 unsigned char char_codes
;
7521 eventRec
->what
= keyDown
;
7522 GetEventParameter (eventRef
, kEventParamKeyMacCharCodes
, typeChar
,
7523 NULL
, sizeof (char), NULL
, &char_codes
);
7524 GetEventParameter (eventRef
, kEventParamKeyCode
, typeUInt32
,
7525 NULL
, sizeof (UInt32
), NULL
, &key_code
);
7526 eventRec
->message
= char_codes
| ((key_code
& 0xff) << 8);
7542 /* Need where and when. */
7545 GetEventParameter (eventRef
, kEventParamMouseLocation
, typeQDPoint
,
7546 NULL
, sizeof (Point
), NULL
, &eventRec
->where
);
7547 /* Use two step process because new event modifiers are 32-bit
7548 and old are 16-bit. Currently, only loss is NumLock & Fn. */
7549 GetEventParameter (eventRef
, kEventParamKeyModifiers
, typeUInt32
,
7550 NULL
, sizeof (UInt32
), NULL
, &mods
);
7551 eventRec
->modifiers
= mods
;
7553 eventRec
->when
= EventTimeToTicks (GetEventTime (eventRef
));
7564 Handle menubar_handle
;
7565 MenuHandle menu_handle
;
7567 menubar_handle
= GetNewMBar (128);
7568 if(menubar_handle
== NULL
)
7570 SetMenuBar (menubar_handle
);
7573 #if !TARGET_API_MAC_CARBON
7574 menu_handle
= GetMenuHandle (M_APPLE
);
7575 if(menu_handle
!= NULL
)
7576 AppendResMenu (menu_handle
,'DRVR');
7584 do_init_managers (void)
7586 #if !TARGET_API_MAC_CARBON
7587 InitGraf (&qd
.thePort
);
7589 FlushEvents (everyEvent
, 0);
7594 #endif /* !TARGET_API_MAC_CARBON */
7597 #if !TARGET_API_MAC_CARBON
7598 /* set up some extra stack space for use by emacs */
7599 SetApplLimit ((Ptr
) ((long) GetApplLimit () - EXTRA_STACK_ALLOC
));
7601 /* MaxApplZone must be called for AppleScript to execute more
7602 complicated scripts */
7605 #endif /* !TARGET_API_MAC_CARBON */
7609 do_check_ram_size (void)
7611 SInt32 physical_ram_size
, logical_ram_size
;
7613 if (Gestalt (gestaltPhysicalRAMSize
, &physical_ram_size
) != noErr
7614 || Gestalt (gestaltLogicalRAMSize
, &logical_ram_size
) != noErr
7615 || physical_ram_size
> (1 << VALBITS
)
7616 || logical_ram_size
> (1 << VALBITS
))
7618 StopAlert (RAM_TOO_LARGE_ALERT_ID
, NULL
);
7624 do_window_update (WindowPtr win
)
7626 struct frame
*f
= mac_window_to_frame (win
);
7630 /* The tooltip has been drawn already. Avoid the SET_FRAME_GARBAGED
7632 if (win
!= tip_window
)
7634 if (f
->async_visible
== 0)
7636 f
->async_visible
= 1;
7637 f
->async_iconified
= 0;
7638 SET_FRAME_GARBAGED (f
);
7640 /* An update event is equivalent to MapNotify on X, so report
7641 visibility changes properly. */
7642 if (! NILP(Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
7643 /* Force a redisplay sooner or later to update the
7644 frame titles in case this is the second frame. */
7645 record_asynch_buffer_change ();
7651 #if TARGET_API_MAC_CARBON
7653 RgnHandle region
= NewRgn ();
7655 GetPortVisibleRegion (GetWindowPort (win
), region
);
7656 GetRegionBounds (region
, &r
);
7657 expose_frame (f
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
);
7658 UpdateControls (win
, region
);
7659 DisposeRgn (region
);
7662 r
= (*win
->visRgn
)->rgnBBox
;
7663 expose_frame (f
, r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
);
7664 UpdateControls (win
, win
->visRgn
);
7673 is_emacs_window (WindowPtr win
)
7675 Lisp_Object tail
, frame
;
7680 FOR_EACH_FRAME (tail
, frame
)
7681 if (FRAME_MAC_P (XFRAME (frame
)))
7682 if (FRAME_MAC_WINDOW (XFRAME (frame
)) == win
)
7691 /* Window-activate events will do the job. */
7697 /* Window-deactivate events will do the job. */
7702 do_apple_menu (SInt16 menu_item
)
7704 #if !TARGET_API_MAC_CARBON
7706 SInt16 da_driver_refnum
;
7708 if (menu_item
== I_ABOUT
)
7709 NoteAlert (ABOUT_ALERT_ID
, NULL
);
7712 GetMenuItemText (GetMenuHandle (M_APPLE
), menu_item
, item_name
);
7713 da_driver_refnum
= OpenDeskAcc (item_name
);
7715 #endif /* !TARGET_API_MAC_CARBON */
7719 do_menu_choice (SInt32 menu_choice
)
7721 SInt16 menu_id
, menu_item
;
7723 menu_id
= HiWord (menu_choice
);
7724 menu_item
= LoWord (menu_choice
);
7732 do_apple_menu (menu_item
);
7737 struct frame
*f
= mac_focus_frame (&one_mac_display_info
);
7738 MenuHandle menu
= GetMenuHandle (menu_id
);
7743 GetMenuItemRefCon (menu
, menu_item
, &refcon
);
7744 menubar_selection_callback (f
, refcon
);
7753 /* Handle drags in size box. Based on code contributed by Ben
7754 Mesander and IM - Window Manager A. */
7757 do_grow_window (WindowPtr w
, EventRecord
*e
)
7760 int rows
, columns
, width
, height
;
7761 struct frame
*f
= mac_window_to_frame (w
);
7762 XSizeHints
*size_hints
= FRAME_SIZE_HINTS (f
);
7763 int min_width
= MIN_DOC_SIZE
, min_height
= MIN_DOC_SIZE
;
7764 #if TARGET_API_MAC_CARBON
7770 if (size_hints
->flags
& PMinSize
)
7772 min_width
= size_hints
->min_width
;
7773 min_height
= size_hints
->min_height
;
7775 SetRect (&limit_rect
, min_width
, min_height
, MAX_DOC_SIZE
, MAX_DOC_SIZE
);
7777 #if TARGET_API_MAC_CARBON
7778 if (!ResizeWindow (w
, e
->where
, &limit_rect
, &new_rect
))
7780 height
= new_rect
.bottom
- new_rect
.top
;
7781 width
= new_rect
.right
- new_rect
.left
;
7783 grow_size
= GrowWindow (w
, e
->where
, &limit_rect
);
7784 /* see if it really changed size */
7787 height
= HiWord (grow_size
);
7788 width
= LoWord (grow_size
);
7791 if (width
!= FRAME_PIXEL_WIDTH (f
)
7792 || height
!= FRAME_PIXEL_HEIGHT (f
))
7794 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, height
);
7795 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, width
);
7797 x_set_window_size (f
, 0, columns
, rows
);
7802 /* Handle clicks in zoom box. Calculation of "standard state" based
7803 on code in IM - Window Manager A and code contributed by Ben
7804 Mesander. The standard state of an Emacs window is 80-characters
7805 wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */
7808 do_zoom_window (WindowPtr w
, int zoom_in_or_out
)
7811 Rect zoom_rect
, port_rect
;
7813 int w_title_height
, columns
, rows
, width
, height
;
7814 struct frame
*f
= mac_window_to_frame (w
);
7815 struct mac_display_info
*dpyinfo
= FRAME_MAC_DISPLAY_INFO (f
);
7817 #if TARGET_API_MAC_CARBON
7819 Point standard_size
;
7821 standard_size
.h
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
7822 standard_size
.v
= dpyinfo
->height
;
7824 if (IsWindowInStandardState (w
, &standard_size
, &zoom_rect
))
7825 zoom_in_or_out
= inZoomIn
;
7828 /* Adjust the standard size according to character boundaries. */
7830 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, zoom_rect
.right
- zoom_rect
.left
);
7831 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, zoom_rect
.bottom
- zoom_rect
.top
);
7832 standard_size
.h
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, columns
);
7833 standard_size
.v
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
7834 GetWindowBounds (w
, kWindowContentRgn
, &port_rect
);
7835 if (IsWindowInStandardState (w
, &standard_size
, &zoom_rect
)
7836 && port_rect
.left
== zoom_rect
.left
7837 && port_rect
.top
== zoom_rect
.top
)
7838 zoom_in_or_out
= inZoomIn
;
7840 zoom_in_or_out
= inZoomOut
;
7843 ZoomWindowIdeal (w
, zoom_in_or_out
, &standard_size
);
7845 #else /* not TARGET_API_MAC_CARBON */
7846 GetPort (&save_port
);
7848 SetPortWindowPort (w
);
7850 /* Clear window to avoid flicker. */
7851 EraseRect (&(w
->portRect
));
7852 if (zoom_in_or_out
== inZoomOut
)
7854 SetPt (&top_left
, w
->portRect
.left
, w
->portRect
.top
);
7855 LocalToGlobal (&top_left
);
7857 /* calculate height of window's title bar */
7858 w_title_height
= top_left
.v
- 1
7859 - (**((WindowPeek
) w
)->strucRgn
).rgnBBox
.top
+ GetMBarHeight ();
7861 /* get maximum height of window into zoom_rect.bottom - zoom_rect.top */
7862 zoom_rect
= qd
.screenBits
.bounds
;
7863 zoom_rect
.top
+= w_title_height
;
7864 InsetRect (&zoom_rect
, 8, 4); /* not too tight */
7866 zoom_rect
.right
= zoom_rect
.left
7867 + FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, DEFAULT_NUM_COLS
);
7869 /* Adjust the standard size according to character boundaries. */
7870 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, zoom_rect
.bottom
- zoom_rect
.top
);
7872 zoom_rect
.top
+ FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
7874 (**((WStateDataHandle
) ((WindowPeek
) w
)->dataHandle
)).stdState
7878 ZoomWindow (w
, zoom_in_or_out
, f
== mac_focus_frame (dpyinfo
));
7880 SetPort (save_port
);
7881 #endif /* not TARGET_API_MAC_CARBON */
7883 /* retrieve window size and update application values */
7884 #if TARGET_API_MAC_CARBON
7885 GetWindowPortBounds (w
, &port_rect
);
7887 port_rect
= w
->portRect
;
7889 height
= port_rect
.bottom
- port_rect
.top
;
7890 width
= port_rect
.right
- port_rect
.left
;
7892 if (width
!= FRAME_PIXEL_WIDTH (f
)
7893 || height
!= FRAME_PIXEL_HEIGHT (f
))
7895 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, height
);
7896 columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, width
);
7898 change_frame_size (f
, rows
, columns
, 0, 1, 0);
7899 SET_FRAME_GARBAGED (f
);
7900 cancel_mouse_face (f
);
7902 FRAME_PIXEL_WIDTH (f
) = width
;
7903 FRAME_PIXEL_HEIGHT (f
) = height
;
7905 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
7908 /* Intialize AppleEvent dispatcher table for the required events. */
7910 init_required_apple_events ()
7915 /* Make sure we have apple events before starting. */
7916 err
= Gestalt (gestaltAppleEventsAttr
, &result
);
7920 if (!(result
& (1 << gestaltAppleEventsPresent
)))
7923 #if TARGET_API_MAC_CARBON
7924 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenApplication
,
7925 NewAEEventHandlerUPP
7926 ((AEEventHandlerProcPtr
) do_ae_open_application
),
7929 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenApplication
,
7930 NewAEEventHandlerProc
7931 ((AEEventHandlerProcPtr
) do_ae_open_application
),
7937 #if TARGET_API_MAC_CARBON
7938 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenDocuments
,
7939 NewAEEventHandlerUPP
7940 ((AEEventHandlerProcPtr
) do_ae_open_documents
),
7943 err
= AEInstallEventHandler(kCoreEventClass
, kAEOpenDocuments
,
7944 NewAEEventHandlerProc
7945 ((AEEventHandlerProcPtr
) do_ae_open_documents
),
7951 #if TARGET_API_MAC_CARBON
7952 err
= AEInstallEventHandler(kCoreEventClass
, kAEPrintDocuments
,
7953 NewAEEventHandlerUPP
7954 ((AEEventHandlerProcPtr
) do_ae_print_documents
),
7957 err
= AEInstallEventHandler(kCoreEventClass
, kAEPrintDocuments
,
7958 NewAEEventHandlerProc
7959 ((AEEventHandlerProcPtr
) do_ae_print_documents
),
7965 #if TARGET_API_MAC_CARBON
7966 err
= AEInstallEventHandler(kCoreEventClass
, kAEQuitApplication
,
7967 NewAEEventHandlerUPP
7968 ((AEEventHandlerProcPtr
) do_ae_quit_application
),
7971 err
= AEInstallEventHandler(kCoreEventClass
, kAEQuitApplication
,
7972 NewAEEventHandlerProc
7973 ((AEEventHandlerProcPtr
) do_ae_quit_application
),
7981 mac_store_application_menu_event (event
)
7982 #if USE_CARBON_EVENTS
7988 struct input_event buf
;
7989 Lisp_Object frame
, entry
;
7993 XSETFRAME (frame
, mac_focus_frame (&one_mac_display_info
));
7994 buf
.kind
= MENU_BAR_EVENT
;
7995 buf
.frame_or_window
= frame
;
7997 kbd_buffer_store_event (&buf
);
7999 buf
.arg
= Qapplication
;
8000 kbd_buffer_store_event (&buf
);
8002 #if USE_CARBON_EVENTS
8003 switch (GetEventClass (event
))
8006 case kEventClassService
:
8007 buf
.arg
= Qservices
;
8008 kbd_buffer_store_event (&buf
);
8009 switch (GetEventKind (event
))
8011 case kEventServicePaste
:
8015 case kEventServicePerform
:
8018 CFStringRef message
;
8020 err
= GetEventParameter (event
, kEventParamServiceMessageName
,
8021 typeCFStringRef
, NULL
,
8022 sizeof (CFStringRef
), NULL
, &message
);
8024 kbd_buffer_store_event (&buf
);
8025 if (err
== noErr
&& message
)
8026 entry
= intern (SDATA (cfstring_to_lisp (message
)));
8036 #endif /* MAC_OSX */
8037 case kEventClassCommand
:
8041 GetEventParameter(event
, kEventParamDirectObject
, typeHICommand
,
8042 NULL
, sizeof (HICommand
), NULL
, &command
);
8043 switch (command
.commandID
)
8045 case kHICommandAbout
:
8049 case kHICommandPreferences
:
8050 entry
= Qpreferences
;
8052 #endif /* MAC_OSX */
8053 case kHICommandQuit
:
8065 #else /* USE_CARBON_EVENTS */
8068 case kHICommandAbout
:
8071 case kHICommandQuit
:
8080 kbd_buffer_store_event (&buf
);
8083 #if USE_CARBON_EVENTS
8084 static pascal OSStatus
8085 mac_handle_command_event (next_handler
, event
, data
)
8086 EventHandlerCallRef next_handler
;
8093 GetEventParameter(event
, kEventParamDirectObject
, typeHICommand
, NULL
,
8094 sizeof (HICommand
), NULL
, &command
);
8096 switch (command
.commandID
)
8098 case kHICommandAbout
:
8100 case kHICommandPreferences
:
8101 #endif /* MAC_OSX */
8102 result
= CallNextEventHandler (next_handler
, event
);
8103 if (result
!= eventNotHandledErr
)
8106 mac_store_application_menu_event (event
);
8113 return eventNotHandledErr
;
8117 init_command_handler ()
8120 EventTypeSpec specs
[] = {{kEventClassCommand
, kEventCommandProcess
}};
8121 static EventHandlerUPP handle_command_eventUPP
= NULL
;
8123 if (handle_command_eventUPP
== NULL
)
8124 handle_command_eventUPP
= NewEventHandlerUPP (mac_handle_command_event
);
8125 return InstallApplicationEventHandler (handle_command_eventUPP
,
8126 GetEventTypeCount (specs
), specs
,
8130 static pascal OSStatus
8131 mac_handle_window_event (next_handler
, event
, data
)
8132 EventHandlerCallRef next_handler
;
8139 XSizeHints
*size_hints
;
8141 GetEventParameter (event
, kEventParamDirectObject
, typeWindowRef
,
8142 NULL
, sizeof (WindowPtr
), NULL
, &wp
);
8144 switch (GetEventKind (event
))
8146 case kEventWindowUpdate
:
8147 result
= CallNextEventHandler (next_handler
, event
);
8148 if (result
!= eventNotHandledErr
)
8151 do_window_update (wp
);
8154 case kEventWindowBoundsChanging
:
8155 result
= CallNextEventHandler (next_handler
, event
);
8156 if (result
!= eventNotHandledErr
)
8159 GetEventParameter (event
, kEventParamAttributes
, typeUInt32
,
8160 NULL
, sizeof (UInt32
), NULL
, &attributes
);
8161 size_hints
= FRAME_SIZE_HINTS (mac_window_to_frame (wp
));
8162 if ((attributes
& kWindowBoundsChangeUserResize
)
8163 && ((size_hints
->flags
& (PResizeInc
| PBaseSize
| PMinSize
))
8164 == (PResizeInc
| PBaseSize
| PMinSize
)))
8169 GetEventParameter (event
, kEventParamCurrentBounds
,
8171 NULL
, sizeof (Rect
), NULL
, &bounds
);
8172 width
= bounds
.right
- bounds
.left
;
8173 height
= bounds
.bottom
- bounds
.top
;
8175 if (width
< size_hints
->min_width
)
8176 width
= size_hints
->min_width
;
8178 width
= size_hints
->base_width
8179 + (int) ((width
- size_hints
->base_width
)
8180 / (float) size_hints
->width_inc
+ .5)
8181 * size_hints
->width_inc
;
8183 if (height
< size_hints
->min_height
)
8184 height
= size_hints
->min_height
;
8186 height
= size_hints
->base_height
8187 + (int) ((height
- size_hints
->base_height
)
8188 / (float) size_hints
->height_inc
+ .5)
8189 * size_hints
->height_inc
;
8191 bounds
.right
= bounds
.left
+ width
;
8192 bounds
.bottom
= bounds
.top
+ height
;
8193 SetEventParameter (event
, kEventParamCurrentBounds
,
8194 typeQDRectangle
, sizeof (Rect
), &bounds
);
8200 return eventNotHandledErr
;
8203 static pascal OSStatus
8204 mac_handle_mouse_event (next_handler
, event
, data
)
8205 EventHandlerCallRef next_handler
;
8211 switch (GetEventKind (event
))
8213 case kEventMouseWheelMoved
:
8217 EventMouseWheelAxis axis
;
8221 result
= CallNextEventHandler (next_handler
, event
);
8222 if (result
!= eventNotHandledErr
|| read_socket_inev
== NULL
)
8225 GetEventParameter (event
, kEventParamWindowRef
, typeWindowRef
,
8226 NULL
, sizeof (WindowRef
), NULL
, &wp
);
8227 f
= mac_window_to_frame (wp
);
8228 if (f
!= mac_focus_frame (&one_mac_display_info
))
8231 GetEventParameter (event
, kEventParamMouseWheelAxis
,
8232 typeMouseWheelAxis
, NULL
,
8233 sizeof (EventMouseWheelAxis
), NULL
, &axis
);
8234 if (axis
!= kEventMouseWheelAxisY
)
8237 GetEventParameter (event
, kEventParamMouseWheelDelta
, typeSInt32
,
8238 NULL
, sizeof (SInt32
), NULL
, &delta
);
8239 GetEventParameter (event
, kEventParamMouseLocation
, typeQDPoint
,
8240 NULL
, sizeof (Point
), NULL
, &point
);
8241 read_socket_inev
->kind
= WHEEL_EVENT
;
8242 read_socket_inev
->code
= 0;
8243 read_socket_inev
->modifiers
=
8244 (mac_event_to_emacs_modifiers (event
)
8245 | ((delta
< 0) ? down_modifier
: up_modifier
));
8246 SetPortWindowPort (wp
);
8247 GlobalToLocal (&point
);
8248 XSETINT (read_socket_inev
->x
, point
.h
);
8249 XSETINT (read_socket_inev
->y
, point
.v
);
8250 XSETFRAME (read_socket_inev
->frame_or_window
, f
);
8260 return eventNotHandledErr
;
8262 #endif /* USE_CARBON_EVENTS */
8266 install_window_handler (window
)
8270 #if USE_CARBON_EVENTS
8271 EventTypeSpec specs_window
[] =
8272 {{kEventClassWindow
, kEventWindowUpdate
},
8273 {kEventClassWindow
, kEventWindowBoundsChanging
}};
8274 EventTypeSpec specs_mouse
[] = {{kEventClassMouse
, kEventMouseWheelMoved
}};
8275 static EventHandlerUPP handle_window_eventUPP
= NULL
;
8276 static EventHandlerUPP handle_mouse_eventUPP
= NULL
;
8278 if (handle_window_eventUPP
== NULL
)
8279 handle_window_eventUPP
= NewEventHandlerUPP (mac_handle_window_event
);
8280 if (handle_mouse_eventUPP
== NULL
)
8281 handle_mouse_eventUPP
= NewEventHandlerUPP (mac_handle_mouse_event
);
8282 err
= InstallWindowEventHandler (window
, handle_window_eventUPP
,
8283 GetEventTypeCount (specs_window
),
8284 specs_window
, NULL
, NULL
);
8286 err
= InstallWindowEventHandler (window
, handle_mouse_eventUPP
,
8287 GetEventTypeCount (specs_mouse
),
8288 specs_mouse
, NULL
, NULL
);
8290 #if TARGET_API_MAC_CARBON
8291 if (mac_do_track_dragUPP
== NULL
)
8292 mac_do_track_dragUPP
= NewDragTrackingHandlerUPP (mac_do_track_drag
);
8293 if (mac_do_receive_dragUPP
== NULL
)
8294 mac_do_receive_dragUPP
= NewDragReceiveHandlerUPP (mac_do_receive_drag
);
8297 err
= InstallTrackingHandler (mac_do_track_dragUPP
, window
, NULL
);
8299 err
= InstallReceiveHandler (mac_do_receive_dragUPP
, window
, NULL
);
8305 remove_window_handler (window
)
8308 #if TARGET_API_MAC_CARBON
8309 if (mac_do_track_dragUPP
)
8310 RemoveTrackingHandler (mac_do_track_dragUPP
, window
);
8311 if (mac_do_receive_dragUPP
)
8312 RemoveReceiveHandler (mac_do_receive_dragUPP
, window
);
8316 /* Open Application Apple Event */
8318 do_ae_open_application(const AppleEvent
*pae
, AppleEvent
*preply
, long prefcon
)
8324 /* Called when we receive an AppleEvent with an ID of
8325 "kAEOpenDocuments". This routine gets the direct parameter,
8326 extracts the FSSpecs in it, and puts their names on a list. */
8327 #pragma options align=mac68k
8328 typedef struct SelectionRange
{
8329 short unused1
; // 0 (not used)
8330 short lineNum
; // line to select (<0 to specify range)
8331 long startRange
; // start of selection range (if line < 0)
8332 long endRange
; // end of selection range (if line < 0)
8333 long unused2
; // 0 (not used)
8334 long theDate
; // modification date/time
8336 #pragma options align=reset
8339 do_ae_open_documents(AppleEvent
*message
, AppleEvent
*reply
, long refcon
)
8344 DescType actual_type
;
8346 SelectionRange position
;
8347 Lisp_Object file_list
= Qnil
;
8349 xassert (read_socket_inev
);
8351 err
= AEGetParamDesc (message
, keyDirectObject
, typeAEList
, &the_desc
);
8353 goto descriptor_error_exit
;
8355 err
= AEGetParamPtr (message
, keyAEPosition
, typeChar
, &actual_type
, &position
, sizeof(SelectionRange
), &actual_size
);
8357 file_list
= Fcons (list3 (make_number (position
.lineNum
+ 1),
8358 make_number (position
.startRange
+ 1),
8359 make_number (position
.endRange
+ 1)),
8362 /* Check to see that we got all of the required parameters from the
8363 event descriptor. For an 'odoc' event this should just be the
8365 err
= AEGetAttributePtr(message
, keyMissedKeywordAttr
, typeWildCard
,
8366 &actual_type
, (Ptr
) &keyword
,
8367 sizeof (keyword
), &actual_size
);
8368 /* No error means that we found some unused parameters.
8369 errAEDescNotFound means that there are no more parameters. If we
8370 get an error code other than that, flag it. */
8371 if ((err
== noErr
) || (err
!= errAEDescNotFound
))
8373 err
= errAEEventNotHandled
;
8378 /* Got all the parameters we need. Now, go through the direct
8379 object list and parse it up. */
8381 long num_files_to_open
;
8383 err
= AECountItems (&the_desc
, &num_files_to_open
);
8388 /* AE file list is one based so just use that for indexing here. */
8389 for (i
= 1; i
<= num_files_to_open
; i
++)
8391 char unix_path_name
[MAXPATHLEN
];
8395 err
= AEGetNthPtr (&the_desc
, i
, typeFSRef
, &keyword
,
8396 &actual_type
, &fref
, sizeof (FSRef
),
8398 if (err
!= noErr
|| actual_type
!= typeFSRef
)
8401 if (FSRefMakePath (&fref
, unix_path_name
, sizeof (unix_path_name
))
8406 err
= AEGetNthPtr(&the_desc
, i
, typeFSS
, &keyword
, &actual_type
,
8407 (Ptr
) &fs
, sizeof (fs
), &actual_size
);
8408 if (err
!= noErr
) continue;
8410 if (fsspec_to_posix_pathname (&fs
, unix_path_name
,
8411 sizeof (unix_path_name
) - 1) == noErr
)
8413 /* x-dnd functions expect undecoded filenames. */
8414 file_list
= Fcons (make_unibyte_string (unix_path_name
,
8415 strlen (unix_path_name
)),
8420 /* Build a DRAG_N_DROP_EVENT type event as is done in
8421 constuct_drag_n_drop in w32term.c. */
8422 if (!NILP (file_list
))
8424 struct frame
*f
= mac_focus_frame (&one_mac_display_info
);
8428 read_socket_inev
->kind
= DRAG_N_DROP_EVENT
;
8429 read_socket_inev
->code
= 0;
8430 read_socket_inev
->modifiers
= 0;
8432 XSETINT (read_socket_inev
->x
, 0);
8433 XSETINT (read_socket_inev
->y
, 0);
8435 XSETFRAME (frame
, f
);
8436 read_socket_inev
->frame_or_window
= Fcons (frame
, file_list
);
8439 /* Regardless of whether Emacs was suspended or in the
8440 foreground, ask it to redraw its entire screen. Otherwise
8441 parts of the screen can be left in an inconsistent
8443 wp
= FRAME_MAC_WINDOW (f
);
8445 #if TARGET_API_MAC_CARBON
8449 GetWindowPortBounds (wp
, &r
);
8450 InvalWindowRect (wp
, &r
);
8452 #else /* not TARGET_API_MAC_CARBON */
8453 InvalRect (&(wp
->portRect
));
8454 #endif /* not TARGET_API_MAC_CARBON */
8460 /* Nuke the coerced file list in any case */
8461 err2
= AEDisposeDesc(&the_desc
);
8463 descriptor_error_exit
:
8464 /* InvalRect(&(gFrontMacWindowP->mWP->portRect)); */
8469 #if TARGET_API_MAC_CARBON
8471 mac_do_track_drag (DragTrackingMessage message
, WindowPtr window
,
8472 void *handlerRefCon
, DragReference theDrag
)
8474 static int can_accept
;
8477 ItemReference theItem
;
8478 FlavorFlags theFlags
;
8481 if (GetFrontWindowOfClass (kMovableModalWindowClass
, false))
8482 return dragNotAcceptedErr
;
8486 case kDragTrackingEnterHandler
:
8487 CountDragItems (theDrag
, &items
);
8489 for (index
= 1; index
<= items
; index
++)
8491 GetDragItemReferenceNumber (theDrag
, index
, &theItem
);
8492 result
= GetFlavorFlags (theDrag
, theItem
, flavorTypeHFS
, &theFlags
);
8493 if (result
== noErr
)
8501 case kDragTrackingEnterWindow
:
8504 RgnHandle hilite_rgn
= NewRgn ();
8506 struct frame
*f
= mac_window_to_frame (window
);
8508 GetWindowPortBounds (window
, &r
);
8509 OffsetRect (&r
, -r
.left
, -r
.top
);
8510 RectRgn (hilite_rgn
, &r
);
8511 ShowDragHilite (theDrag
, hilite_rgn
, true);
8512 DisposeRgn (hilite_rgn
);
8513 SetThemeCursor (kThemeCopyArrowCursor
);
8517 case kDragTrackingInWindow
:
8520 case kDragTrackingLeaveWindow
:
8523 struct frame
*f
= mac_window_to_frame (window
);
8525 HideDragHilite (theDrag
);
8526 SetThemeCursor (kThemeArrowCursor
);
8530 case kDragTrackingLeaveHandler
:
8538 mac_do_receive_drag (WindowPtr window
, void *handlerRefCon
,
8539 DragReference theDrag
)
8543 FlavorFlags theFlags
;
8546 ItemReference theItem
;
8548 Size size
= sizeof (HFSFlavor
);
8549 Lisp_Object file_list
;
8551 if (GetFrontWindowOfClass (kMovableModalWindowClass
, false))
8552 return dragNotAcceptedErr
;
8555 GetDragMouse (theDrag
, &mouse
, 0L);
8556 CountDragItems (theDrag
, &items
);
8557 for (index
= 1; index
<= items
; index
++)
8559 /* Only handle file references. */
8560 GetDragItemReferenceNumber (theDrag
, index
, &theItem
);
8561 result
= GetFlavorFlags (theDrag
, theItem
, flavorTypeHFS
, &theFlags
);
8562 if (result
== noErr
)
8567 char unix_path_name
[MAXPATHLEN
];
8569 GetFlavorData (theDrag
, theItem
, flavorTypeHFS
, &data
, &size
, 0L);
8571 /* Use Carbon routines, otherwise it converts the file name
8572 to /Macintosh HD/..., which is not correct. */
8573 FSpMakeFSRef (&data
.fileSpec
, &fref
);
8574 if (! FSRefMakePath (&fref
, unix_path_name
, sizeof (unix_path_name
)));
8576 if (fsspec_to_posix_pathname (&data
.fileSpec
, unix_path_name
,
8577 sizeof (unix_path_name
) - 1) == noErr
)
8579 /* x-dnd functions expect undecoded filenames. */
8580 file_list
= Fcons (make_unibyte_string (unix_path_name
,
8581 strlen (unix_path_name
)),
8585 /* If there are items in the list, construct an event and post it to
8586 the queue like an interrupt using kbd_buffer_store_event. */
8587 if (!NILP (file_list
))
8589 struct input_event event
;
8591 struct frame
*f
= mac_window_to_frame (window
);
8594 GlobalToLocal (&mouse
);
8595 GetDragModifiers (theDrag
, NULL
, NULL
, &modifiers
);
8597 event
.kind
= DRAG_N_DROP_EVENT
;
8599 event
.modifiers
= mac_to_emacs_modifiers (modifiers
);
8600 event
.timestamp
= TickCount () * (1000 / 60);
8601 XSETINT (event
.x
, mouse
.h
);
8602 XSETINT (event
.y
, mouse
.v
);
8603 XSETFRAME (frame
, f
);
8604 event
.frame_or_window
= Fcons (frame
, file_list
);
8606 /* Post to the interrupt queue */
8607 kbd_buffer_store_event (&event
);
8608 /* MAC_TODO: Mimic behavior of windows by switching contexts to Emacs */
8610 ProcessSerialNumber psn
;
8611 GetCurrentProcess (&psn
);
8612 SetFrontProcess (&psn
);
8618 return dragNotAcceptedErr
;
8623 /* Print Document Apple Event */
8625 do_ae_print_documents (const AppleEvent
*pAE
, AppleEvent
*reply
, long refcon
)
8627 return errAEEventNotHandled
;
8632 do_ae_quit_application (AppleEvent
* message
, AppleEvent
*reply
, long refcon
)
8634 #if USE_CARBON_EVENTS
8636 EventRef event
= NULL
;
8637 static const HICommand quit_command
= {kEventAttributeNone
, kHICommandQuit
};
8639 err
= CreateEvent (NULL
, kEventClassCommand
, kEventCommandProcess
, 0,
8640 kEventAttributeUserEvent
, &event
);
8642 err
= SetEventParameter (event
, kEventParamDirectObject
, typeHICommand
,
8643 sizeof (HICommand
), &quit_command
);
8645 mac_store_application_menu_event (event
);
8647 ReleaseEvent (event
);
8652 return errAEEventNotHandled
;
8654 mac_store_application_menu_event (kHICommandQuit
);
8663 profiler_exit_proc ()
8665 ProfilerDump ("\pEmacs.prof");
8670 /* These few functions implement Emacs as a normal Mac application
8671 (almost): set up the heap and the Toolbox, handle necessary system
8672 events plus a few simple menu events. They also set up Emacs's
8673 access to functions defined in the rest of this file. Emacs uses
8674 function hooks to perform all its terminal I/O. A complete list of
8675 these functions appear in termhooks.h. For what they do, read the
8676 comments there and see also w32term.c and xterm.c. What's
8677 noticeably missing here is the event loop, which is normally
8678 present in most Mac application. After performing the necessary
8679 Mac initializations, main passes off control to emacs_main
8680 (corresponding to main in emacs.c). Emacs_main calls XTread_socket
8681 (defined further below) to read input. This is where
8682 WaitNextEvent/ReceiveNextEvent is called to process Mac events. */
8689 #if __profile__ /* is the profiler on? */
8690 if (ProfilerInit(collectDetailed
, bestTimeBase
, 5000, 200))
8695 /* set creator and type for files created by MSL */
8700 do_init_managers ();
8705 do_check_ram_size ();
8708 init_emacs_passwd_dir ();
8712 initialize_applescript ();
8714 init_required_apple_events ();
8720 /* set up argv array from STR# resource */
8721 get_string_list (&argv
, ARGV_STRING_LIST_ID
);
8725 /* free up AppleScript resources on exit */
8726 atexit (terminate_applescript
);
8728 #if __profile__ /* is the profiler on? */
8729 atexit (profiler_exit_proc
);
8732 /* 3rd param "envp" never used in emacs_main */
8733 (void) emacs_main (argc
, argv
, 0);
8736 /* Never reached - real exit in Fkill_emacs */
8741 /* Table for translating Mac keycode to X keysym values. Contributed
8743 Mapping for special keys is now identical to that in Apple X11
8744 except `clear' (-> <clear>) on the KeyPad, `enter' (-> <kp-enter>)
8745 on the right of the Cmd key on laptops, and fn + `enter' (->
8747 static unsigned char keycode_to_xkeysym_table
[] = {
8748 /*0x00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8749 /*0x10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8750 /*0x20*/ 0, 0, 0, 0, 0x0d /*return*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8752 /*0x30*/ 0x09 /*tab*/, 0 /*0x0020 space*/, 0, 0x08 /*backspace*/,
8753 /*0x34*/ 0x8d /*enter on laptops*/, 0x1b /*escape*/, 0, 0,
8754 /*0x38*/ 0, 0, 0, 0,
8755 /*0x3C*/ 0, 0, 0, 0,
8757 /*0x40*/ 0, 0xae /*kp-.*/, 0, 0xaa /*kp-**/,
8758 /*0x44*/ 0, 0xab /*kp-+*/, 0, 0x0b /*clear*/,
8759 /*0x48*/ 0, 0, 0, 0xaf /*kp-/*/,
8760 /*0x4C*/ 0x8d /*kp-enter*/, 0, 0xad /*kp--*/, 0,
8762 /*0x50*/ 0, 0xbd /*kp-=*/, 0xb0 /*kp-0*/, 0xb1 /*kp-1*/,
8763 /*0x54*/ 0xb2 /*kp-2*/, 0xb3 /*kp-3*/, 0xb4 /*kp-4*/, 0xb5 /*kp-5*/,
8764 /*0x58*/ 0xb6 /*kp-6*/, 0xb7 /*kp-7*/, 0, 0xb8 /*kp-8*/,
8765 /*0x5C*/ 0xb9 /*kp-9*/, 0, 0, 0,
8767 /*0x60*/ 0xc2 /*f5*/, 0xc3 /*f6*/, 0xc4 /*f7*/, 0xc0 /*f3*/,
8768 /*0x64*/ 0xc5 /*f8*/, 0xc6 /*f9*/, 0, 0xc8 /*f11*/,
8769 /*0x68*/ 0, 0xca /*f13*/, 0, 0xcb /*f14*/,
8770 /*0x6C*/ 0, 0xc7 /*f10*/, 0x0a /*fn+enter on laptops*/, 0xc9 /*f12*/,
8772 /*0x70*/ 0, 0xcc /*f15*/, 0x6a /*help*/, 0x50 /*home*/,
8773 /*0x74*/ 0x55 /*pgup*/, 0xff /*delete*/, 0xc1 /*f4*/, 0x57 /*end*/,
8774 /*0x78*/ 0xbf /*f2*/, 0x56 /*pgdown*/, 0xbe /*f1*/, 0x51 /*left*/,
8775 /*0x7C*/ 0x53 /*right*/, 0x54 /*down*/, 0x52 /*up*/, 0
8779 keycode_to_xkeysym (int keyCode
, int *xKeySym
)
8781 *xKeySym
= keycode_to_xkeysym_table
[keyCode
& 0x7f];
8782 return *xKeySym
!= 0;
8785 #if !USE_CARBON_EVENTS
8786 static RgnHandle mouse_region
= NULL
;
8789 mac_wait_next_event (er
, sleep_time
, dequeue
)
8794 static EventRecord er_buf
= {nullEvent
};
8795 UInt32 target_tick
, current_tick
;
8796 EventMask event_mask
;
8798 if (mouse_region
== NULL
)
8799 mouse_region
= NewRgn ();
8801 event_mask
= everyEvent
;
8802 if (NILP (Fboundp (Qmac_ready_for_drag_n_drop
)))
8803 event_mask
-= highLevelEventMask
;
8805 current_tick
= TickCount ();
8806 target_tick
= current_tick
+ sleep_time
;
8808 if (er_buf
.what
== nullEvent
)
8809 while (!WaitNextEvent (event_mask
, &er_buf
,
8810 target_tick
- current_tick
, mouse_region
))
8812 current_tick
= TickCount ();
8813 if (target_tick
<= current_tick
)
8819 er_buf
.what
= nullEvent
;
8822 #endif /* not USE_CARBON_EVENTS */
8824 /* Emacs calls this whenever it wants to read an input event from the
8827 XTread_socket (sd
, expected
, hold_quit
)
8829 struct input_event
*hold_quit
;
8831 struct input_event inev
;
8833 #if USE_CARBON_EVENTS
8835 EventTargetRef toolbox_dispatcher
;
8838 struct mac_display_info
*dpyinfo
= &one_mac_display_info
;
8840 if (interrupt_input_blocked
)
8842 interrupt_input_pending
= 1;
8846 interrupt_input_pending
= 0;
8849 /* So people can tell when we have read the available input. */
8850 input_signal_count
++;
8852 #if USE_CARBON_EVENTS
8853 toolbox_dispatcher
= GetEventDispatcherTarget ();
8855 while (!ReceiveNextEvent (0, NULL
, kEventDurationNoWait
,
8856 kEventRemoveFromQueue
, &eventRef
))
8857 #else /* !USE_CARBON_EVENTS */
8858 while (mac_wait_next_event (&er
, 0, true))
8859 #endif /* !USE_CARBON_EVENTS */
8863 unsigned long timestamp
;
8865 /* It is necessary to set this (additional) argument slot of an
8866 event to nil because keyboard.c protects incompletely
8867 processed event from being garbage collected by placing them
8868 in the kbd_buffer_gcpro vector. */
8870 inev
.kind
= NO_EVENT
;
8873 #if USE_CARBON_EVENTS
8874 timestamp
= GetEventTime (eventRef
) / kEventDurationMillisecond
;
8876 timestamp
= er
.when
* (1000 / 60); /* ticks to milliseconds */
8879 #if USE_CARBON_EVENTS
8880 /* Handle new events */
8881 if (!mac_convert_event_ref (eventRef
, &er
))
8883 /* There used to be a handler for the kEventMouseWheelMoved
8884 event here. But as of Mac OS X 10.4, this kind of event
8885 is not directly posted to the main event queue by
8886 two-finger scrolling on the trackpad. Instead, some
8887 private event is posted and it is converted to a wheel
8888 event by the default handler for the application target.
8889 The converted one can be received by a Carbon event
8890 handler installed on a window target. */
8891 read_socket_inev
= &inev
;
8892 SendEventToEventTarget (eventRef
, toolbox_dispatcher
);
8893 read_socket_inev
= NULL
;
8896 #endif /* USE_CARBON_EVENTS */
8902 WindowPtr window_ptr
;
8903 ControlPartCode part_code
;
8906 #if USE_CARBON_EVENTS
8907 /* This is needed to send mouse events like aqua window
8908 buttons to the correct handler. */
8909 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
8910 != eventNotHandledErr
)
8914 if (dpyinfo
->grabbed
&& last_mouse_frame
8915 && FRAME_LIVE_P (last_mouse_frame
))
8917 window_ptr
= FRAME_MAC_WINDOW (last_mouse_frame
);
8918 part_code
= inContent
;
8922 part_code
= FindWindow (er
.where
, &window_ptr
);
8923 if (tip_window
&& window_ptr
== tip_window
)
8925 HideWindow (tip_window
);
8926 part_code
= FindWindow (er
.where
, &window_ptr
);
8930 if (er
.what
!= mouseDown
&& part_code
!= inContent
)
8936 f
= mac_focus_frame (dpyinfo
);
8937 saved_menu_event_location
= er
.where
;
8938 inev
.kind
= MENU_BAR_ACTIVATE_EVENT
;
8939 XSETFRAME (inev
.frame_or_window
, f
);
8943 if (window_ptr
!= FRAME_MAC_WINDOW (mac_focus_frame (dpyinfo
)))
8944 SelectWindow (window_ptr
);
8947 ControlPartCode control_part_code
;
8949 Point mouse_loc
= er
.where
;
8951 ControlKind control_kind
;
8954 f
= mac_window_to_frame (window_ptr
);
8955 /* convert to local coordinates of new window */
8956 SetPortWindowPort (window_ptr
);
8958 GlobalToLocal (&mouse_loc
);
8959 #if TARGET_API_MAC_CARBON
8960 ch
= FindControlUnderMouse (mouse_loc
, window_ptr
,
8961 &control_part_code
);
8964 GetControlKind (ch
, &control_kind
);
8967 control_part_code
= FindControl (mouse_loc
, window_ptr
,
8971 #if USE_CARBON_EVENTS
8972 inev
.code
= mac_get_mouse_btn (eventRef
);
8973 inev
.modifiers
= mac_event_to_emacs_modifiers (eventRef
);
8975 inev
.code
= mac_get_emulated_btn (er
.modifiers
);
8976 inev
.modifiers
= mac_to_emacs_modifiers (er
.modifiers
);
8978 XSETINT (inev
.x
, mouse_loc
.h
);
8979 XSETINT (inev
.y
, mouse_loc
.v
);
8981 if (dpyinfo
->grabbed
&& tracked_scroll_bar
8983 #ifndef USE_TOOLKIT_SCROLL_BARS
8984 /* control_part_code becomes kControlNoPart if
8985 a progress indicator is clicked. */
8986 && control_part_code
!= kControlNoPart
8987 #else /* USE_TOOLKIT_SCROLL_BARS */
8989 && control_kind
.kind
== kControlKindScrollBar
8990 #endif /* MAC_OSX */
8991 #endif /* USE_TOOLKIT_SCROLL_BARS */
8994 struct scroll_bar
*bar
;
8996 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
8998 bar
= tracked_scroll_bar
;
8999 #ifndef USE_TOOLKIT_SCROLL_BARS
9000 control_part_code
= kControlIndicatorPart
;
9004 bar
= (struct scroll_bar
*) GetControlReference (ch
);
9005 #ifdef USE_TOOLKIT_SCROLL_BARS
9006 /* Make the "Ctrl-Mouse-2 splits window" work
9007 for toolkit scroll bars. */
9008 if (er
.modifiers
& controlKey
)
9009 x_scroll_bar_handle_click (bar
, control_part_code
,
9011 else if (er
.what
== mouseDown
)
9012 x_scroll_bar_handle_press (bar
, control_part_code
,
9015 x_scroll_bar_handle_release (bar
, &inev
);
9016 #else /* not USE_TOOLKIT_SCROLL_BARS */
9017 x_scroll_bar_handle_click (bar
, control_part_code
,
9019 if (er
.what
== mouseDown
9020 && control_part_code
== kControlIndicatorPart
)
9021 tracked_scroll_bar
= bar
;
9023 tracked_scroll_bar
= NULL
;
9024 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9029 int x
= mouse_loc
.h
;
9030 int y
= mouse_loc
.v
;
9032 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
9033 if (EQ (window
, f
->tool_bar_window
))
9035 if (er
.what
== mouseDown
)
9036 handle_tool_bar_click (f
, x
, y
, 1, 0);
9038 handle_tool_bar_click (f
, x
, y
, 0,
9044 XSETFRAME (inev
.frame_or_window
, f
);
9045 inev
.kind
= MOUSE_CLICK_EVENT
;
9049 if (er
.what
== mouseDown
)
9051 dpyinfo
->grabbed
|= (1 << inev
.code
);
9052 last_mouse_frame
= f
;
9053 /* Ignore any mouse motion that happened
9054 before this event; any subsequent
9055 mouse-movement Emacs events should reflect
9056 only motion after the ButtonPress. */
9061 last_tool_bar_item
= -1;
9065 if ((dpyinfo
->grabbed
& (1 << inev
.code
)) == 0)
9066 /* If a button is released though it was not
9067 previously pressed, that would be because
9068 of multi-button emulation. */
9069 dpyinfo
->grabbed
= 0;
9071 dpyinfo
->grabbed
&= ~(1 << inev
.code
);
9074 #ifdef USE_TOOLKIT_SCROLL_BARS
9075 if (inev
.kind
== MOUSE_CLICK_EVENT
)
9080 inev
.modifiers
|= down_modifier
;
9083 inev
.modifiers
|= up_modifier
;
9090 #if TARGET_API_MAC_CARBON
9091 DragWindow (window_ptr
, er
.where
, NULL
);
9092 #else /* not TARGET_API_MAC_CARBON */
9093 DragWindow (window_ptr
, er
.where
, &qd
.screenBits
.bounds
);
9094 #endif /* not TARGET_API_MAC_CARBON */
9095 /* Update the frame parameters. */
9097 struct frame
*f
= mac_window_to_frame (window_ptr
);
9099 if (f
&& !f
->async_iconified
)
9100 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
9105 if (TrackGoAway (window_ptr
, er
.where
))
9107 inev
.kind
= DELETE_WINDOW_EVENT
;
9108 XSETFRAME (inev
.frame_or_window
,
9109 mac_window_to_frame (window_ptr
));
9113 /* window resize handling added --ben */
9115 do_grow_window (window_ptr
, &er
);
9118 /* window zoom handling added --ben */
9121 if (TrackBox (window_ptr
, er
.where
, part_code
))
9122 do_zoom_window (window_ptr
, part_code
);
9132 #if USE_CARBON_EVENTS
9133 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
9134 != eventNotHandledErr
)
9137 do_window_update ((WindowPtr
) er
.message
);
9142 #if USE_CARBON_EVENTS
9143 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
9144 != eventNotHandledErr
)
9147 switch ((er
.message
>> 24) & 0x000000FF)
9149 case suspendResumeMessage
:
9150 if ((er
.message
& resumeFlag
) == 1)
9156 case mouseMovedMessage
:
9157 #if !USE_CARBON_EVENTS
9158 SetRectRgn (mouse_region
, er
.where
.h
, er
.where
.v
,
9159 er
.where
.h
+ 1, er
.where
.v
+ 1);
9161 previous_help_echo_string
= help_echo_string
;
9162 help_echo_string
= help_echo_object
= help_echo_window
= Qnil
;
9165 if (dpyinfo
->grabbed
&& last_mouse_frame
9166 && FRAME_LIVE_P (last_mouse_frame
))
9167 f
= last_mouse_frame
;
9169 f
= dpyinfo
->x_focus_frame
;
9171 if (dpyinfo
->mouse_face_hidden
)
9173 dpyinfo
->mouse_face_hidden
= 0;
9174 clear_mouse_face (dpyinfo
);
9179 WindowPtr wp
= FRAME_MAC_WINDOW (f
);
9180 Point mouse_pos
= er
.where
;
9182 SetPortWindowPort (wp
);
9184 GlobalToLocal (&mouse_pos
);
9186 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
9187 #ifdef USE_TOOLKIT_SCROLL_BARS
9188 x_scroll_bar_handle_drag (wp
, tracked_scroll_bar
,
9190 #else /* not USE_TOOLKIT_SCROLL_BARS */
9191 x_scroll_bar_note_movement (tracked_scroll_bar
,
9193 - XINT (tracked_scroll_bar
->top
),
9194 er
.when
* (1000 / 60));
9195 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9198 /* Generate SELECT_WINDOW_EVENTs when needed. */
9199 if (mouse_autoselect_window
)
9203 window
= window_from_coordinates (f
,
9208 /* Window will be selected only when it is
9209 not selected now and last mouse movement
9210 event was not in it. Minibuffer window
9211 will be selected iff it is active. */
9212 if (WINDOWP (window
)
9213 && !EQ (window
, last_window
)
9214 && !EQ (window
, selected_window
))
9216 inev
.kind
= SELECT_WINDOW_EVENT
;
9217 inev
.frame_or_window
= window
;
9222 note_mouse_movement (f
, &mouse_pos
);
9226 /* If the contents of the global variable
9227 help_echo_string has changed, generate a
9229 if (!NILP (help_echo_string
) || !NILP (previous_help_echo_string
))
9237 WindowPtr window_ptr
= (WindowPtr
) er
.message
;
9239 #if USE_CARBON_EVENTS
9240 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
9241 != eventNotHandledErr
)
9244 if (window_ptr
== tip_window
)
9246 HideWindow (tip_window
);
9250 if (!is_emacs_window (window_ptr
))
9253 if ((er
.modifiers
& activeFlag
) != 0)
9255 /* A window has been activated */
9256 Point mouse_loc
= er
.where
;
9258 x_detect_focus_change (dpyinfo
, &er
, &inev
);
9260 SetPortWindowPort (window_ptr
);
9261 GlobalToLocal (&mouse_loc
);
9262 /* Window-activated event counts as mouse movement,
9263 so update things that depend on mouse position. */
9264 note_mouse_movement (mac_window_to_frame (window_ptr
),
9269 /* A window has been deactivated */
9270 #if USE_TOOLKIT_SCROLL_BARS
9271 if (dpyinfo
->grabbed
&& tracked_scroll_bar
)
9273 struct input_event event
;
9276 event
.kind
= NO_EVENT
;
9277 x_scroll_bar_handle_release (tracked_scroll_bar
, &event
);
9278 if (event
.kind
!= NO_EVENT
)
9280 event
.timestamp
= timestamp
;
9281 kbd_buffer_store_event_hold (&event
, hold_quit
);
9286 dpyinfo
->grabbed
= 0;
9288 x_detect_focus_change (dpyinfo
, &er
, &inev
);
9290 f
= mac_window_to_frame (window_ptr
);
9291 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9293 /* If we move outside the frame, then we're
9294 certainly no longer on any text in the
9296 clear_mouse_face (dpyinfo
);
9297 dpyinfo
->mouse_face_mouse_frame
= 0;
9300 /* Generate a nil HELP_EVENT to cancel a help-echo.
9301 Do it only if there's something to cancel.
9302 Otherwise, the startup message is cleared when the
9303 mouse leaves the frame. */
9304 if (any_help_event_p
)
9313 int keycode
= (er
.message
& keyCodeMask
) >> 8;
9316 #if USE_CARBON_EVENTS && defined (MAC_OSX)
9317 /* When using Carbon Events, we need to pass raw keyboard
9318 events to the TSM ourselves. If TSM handles it, it
9319 will pass back noErr, otherwise it will pass back
9320 "eventNotHandledErr" and we can process it
9322 if ((!NILP (Vmac_pass_command_to_system
)
9323 || !(er
.modifiers
& cmdKey
))
9324 && (!NILP (Vmac_pass_control_to_system
)
9325 || !(er
.modifiers
& controlKey
))
9326 && (!NILP (Vmac_command_key_is_meta
)
9327 && NILP (Vmac_option_modifier
)
9328 || !(er
.modifiers
& optionKey
)))
9329 if (SendEventToEventTarget (eventRef
, toolbox_dispatcher
)
9330 != eventNotHandledErr
)
9335 if (dpyinfo
->x_focus_frame
== NULL
)
9337 /* Beep if keyboard input occurs when all the frames
9345 static SInt16 last_key_script
= -1;
9346 SInt16 current_key_script
= GetScriptManagerVariable (smKeyScript
);
9348 if (last_key_script
!= current_key_script
)
9350 struct input_event event
;
9353 event
.kind
= LANGUAGE_CHANGE_EVENT
;
9355 event
.code
= current_key_script
;
9356 event
.timestamp
= timestamp
;
9357 kbd_buffer_store_event (&event
);
9360 last_key_script
= current_key_script
;
9365 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
9367 clear_mouse_face (dpyinfo
);
9368 dpyinfo
->mouse_face_hidden
= 1;
9371 if (keycode_to_xkeysym (keycode
, &xkeysym
))
9373 inev
.code
= 0xff00 | xkeysym
;
9374 inev
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
9378 if (er
.modifiers
& (controlKey
|
9379 (NILP (Vmac_command_key_is_meta
) ? optionKey
9382 /* This code comes from Keyboard Resource,
9383 Appendix C of IM - Text. This is necessary
9384 since shift is ignored in KCHR table
9385 translation when option or command is pressed.
9386 It also does not translate correctly
9387 control-shift chars like C-% so mask off shift
9389 int new_modifiers
= er
.modifiers
& 0xe600;
9390 /* mask off option and command */
9391 int new_keycode
= keycode
| new_modifiers
;
9392 Ptr kchr_ptr
= (Ptr
) GetScriptManagerVariable (smKCHRCache
);
9393 unsigned long some_state
= 0;
9394 inev
.code
= KeyTranslate (kchr_ptr
, new_keycode
,
9395 &some_state
) & 0xff;
9397 else if (!NILP (Vmac_option_modifier
)
9398 && (er
.modifiers
& optionKey
))
9400 /* When using the option key as an emacs modifier,
9401 convert the pressed key code back to one
9402 without the Mac option modifier applied. */
9403 int new_modifiers
= er
.modifiers
& ~optionKey
;
9404 int new_keycode
= keycode
| new_modifiers
;
9405 Ptr kchr_ptr
= (Ptr
) GetScriptManagerVariable (smKCHRCache
);
9406 unsigned long some_state
= 0;
9407 inev
.code
= KeyTranslate (kchr_ptr
, new_keycode
,
9408 &some_state
) & 0xff;
9411 inev
.code
= er
.message
& charCodeMask
;
9412 inev
.kind
= ASCII_KEYSTROKE_EVENT
;
9416 #if USE_CARBON_EVENTS
9417 inev
.modifiers
= mac_event_to_emacs_modifiers (eventRef
);
9419 inev
.modifiers
= mac_to_emacs_modifiers (er
.modifiers
);
9421 inev
.modifiers
|= (extra_keyboard_modifiers
9422 & (meta_modifier
| alt_modifier
9423 | hyper_modifier
| super_modifier
));
9424 XSETFRAME (inev
.frame_or_window
, mac_focus_frame (dpyinfo
));
9427 case kHighLevelEvent
:
9428 read_socket_inev
= &inev
;
9429 AEProcessAppleEvent (&er
);
9430 read_socket_inev
= NULL
;
9436 #if USE_CARBON_EVENTS
9437 ReleaseEvent (eventRef
);
9440 if (inev
.kind
!= NO_EVENT
)
9442 inev
.timestamp
= timestamp
;
9443 kbd_buffer_store_event_hold (&inev
, hold_quit
);
9448 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
9453 XSETFRAME (frame
, f
);
9459 any_help_event_p
= 1;
9460 gen_help_event (help_echo_string
, frame
, help_echo_window
,
9461 help_echo_object
, help_echo_pos
);
9465 help_echo_string
= Qnil
;
9466 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
9473 /* If the focus was just given to an autoraising frame,
9475 /* ??? This ought to be able to handle more than one such frame. */
9476 if (pending_autoraise_frame
)
9478 x_raise_frame (pending_autoraise_frame
);
9479 pending_autoraise_frame
= 0;
9487 /* Need to override CodeWarrior's input function so no conversion is
9488 done on newlines Otherwise compiled functions in .elc files will be
9489 read incorrectly. Defined in ...:MSL C:MSL
9490 Common:Source:buffer_io.c. */
9493 __convert_to_newlines (unsigned char * p
, size_t * n
)
9499 __convert_from_newlines (unsigned char * p
, size_t * n
)
9507 make_mac_terminal_frame (struct frame
*f
)
9512 XSETFRAME (frame
, f
);
9514 f
->output_method
= output_mac
;
9515 f
->output_data
.mac
= (struct mac_output
*)
9516 xmalloc (sizeof (struct mac_output
));
9517 bzero (f
->output_data
.mac
, sizeof (struct mac_output
));
9519 XSETFRAME (FRAME_KBOARD (f
)->Vdefault_minibuffer_frame
, f
);
9521 FRAME_COLS (f
) = 96;
9522 FRAME_LINES (f
) = 4;
9524 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
9525 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_right
;
9527 FRAME_DESIRED_CURSOR (f
) = FILLED_BOX_CURSOR
;
9529 f
->output_data
.mac
->cursor_pixel
= 0;
9530 f
->output_data
.mac
->border_pixel
= 0x00ff00;
9531 f
->output_data
.mac
->mouse_pixel
= 0xff00ff;
9532 f
->output_data
.mac
->cursor_foreground_pixel
= 0x0000ff;
9534 f
->output_data
.mac
->text_cursor
= kThemeIBeamCursor
;
9535 f
->output_data
.mac
->nontext_cursor
= kThemeArrowCursor
;
9536 f
->output_data
.mac
->modeline_cursor
= kThemeArrowCursor
;
9537 f
->output_data
.mac
->hand_cursor
= kThemePointingHandCursor
;
9538 f
->output_data
.mac
->hourglass_cursor
= kThemeWatchCursor
;
9539 f
->output_data
.mac
->horizontal_drag_cursor
= kThemeResizeLeftRightCursor
;
9541 FRAME_FONTSET (f
) = -1;
9542 f
->output_data
.mac
->explicit_parent
= 0;
9545 f
->border_width
= 0;
9547 f
->internal_border_width
= 0;
9552 f
->new_text_cols
= 0;
9553 f
->new_text_lines
= 0;
9555 SetRect (&r
, f
->left_pos
, f
->top_pos
,
9556 f
->left_pos
+ FRAME_PIXEL_WIDTH (f
),
9557 f
->top_pos
+ FRAME_PIXEL_HEIGHT (f
));
9561 if (!(FRAME_MAC_WINDOW (f
) =
9562 NewCWindow (NULL
, &r
, "\p", true, dBoxProc
,
9563 (WindowPtr
) -1, 1, (long) f
->output_data
.mac
)))
9565 /* so that update events can find this mac_output struct */
9566 f
->output_data
.mac
->mFP
= f
; /* point back to emacs frame */
9572 /* Need to be initialized for unshow_buffer in window.c. */
9573 selected_window
= f
->selected_window
;
9575 Fmodify_frame_parameters (frame
,
9576 Fcons (Fcons (Qfont
,
9577 build_string ("-*-monaco-medium-r-*--*-90-*-*-*-*-mac-roman")), Qnil
));
9578 Fmodify_frame_parameters (frame
,
9579 Fcons (Fcons (Qforeground_color
,
9580 build_string ("black")), Qnil
));
9581 Fmodify_frame_parameters (frame
,
9582 Fcons (Fcons (Qbackground_color
,
9583 build_string ("white")), Qnil
));
9588 /***********************************************************************
9590 ***********************************************************************/
9592 int mac_initialized
= 0;
9595 mac_initialize_display_info ()
9597 struct mac_display_info
*dpyinfo
= &one_mac_display_info
;
9598 GDHandle main_device_handle
;
9600 bzero (dpyinfo
, sizeof (*dpyinfo
));
9603 dpyinfo
->mac_id_name
9604 = (char *) xmalloc (SCHARS (Vinvocation_name
)
9605 + SCHARS (Vsystem_name
)
9607 sprintf (dpyinfo
->mac_id_name
, "%s@%s",
9608 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
9610 dpyinfo
->mac_id_name
= (char *) xmalloc (strlen ("Mac Display") + 1);
9611 strcpy (dpyinfo
->mac_id_name
, "Mac Display");
9614 main_device_handle
= LMGetMainDevice();
9616 dpyinfo
->reference_count
= 0;
9617 dpyinfo
->resx
= 75.0;
9618 dpyinfo
->resy
= 75.0;
9619 dpyinfo
->color_p
= TestDeviceAttribute (main_device_handle
, gdDevType
);
9621 /* HasDepth returns true if it is possible to have a 32 bit display,
9622 but this may not be what is actually used. Mac OSX can do better.
9623 CGMainDisplayID is only available on OSX 10.2 and higher, but the
9624 header for CGGetActiveDisplayList says that the first display returned
9625 is the active one, so we use that. */
9627 CGDirectDisplayID disp_id
[1];
9628 CGDisplayCount disp_count
;
9629 CGDisplayErr error_code
;
9631 error_code
= CGGetActiveDisplayList (1, disp_id
, &disp_count
);
9632 if (error_code
!= 0)
9633 error ("No display found, CGGetActiveDisplayList error %d", error_code
);
9635 dpyinfo
->n_planes
= CGDisplayBitsPerPixel (disp_id
[0]);
9638 for (dpyinfo
->n_planes
= 32; dpyinfo
->n_planes
> 0; dpyinfo
->n_planes
>>= 1)
9639 if (HasDepth (main_device_handle
, dpyinfo
->n_planes
,
9640 gdDevType
, dpyinfo
->color_p
))
9643 dpyinfo
->height
= (**main_device_handle
).gdRect
.bottom
;
9644 dpyinfo
->width
= (**main_device_handle
).gdRect
.right
;
9645 dpyinfo
->grabbed
= 0;
9646 dpyinfo
->root_window
= NULL
;
9647 dpyinfo
->image_cache
= make_image_cache ();
9649 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
9650 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
9651 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
9652 dpyinfo
->mouse_face_window
= Qnil
;
9653 dpyinfo
->mouse_face_overlay
= Qnil
;
9654 dpyinfo
->mouse_face_hidden
= 0;
9659 mac_make_rdb (xrm_option
)
9662 XrmDatabase database
;
9664 database
= xrm_get_preference_database (NULL
);
9666 xrm_merge_string_database (database
, xrm_option
);
9671 struct mac_display_info
*
9672 mac_term_init (display_name
, xrm_option
, resource_name
)
9673 Lisp_Object display_name
;
9675 char *resource_name
;
9677 struct mac_display_info
*dpyinfo
;
9681 if (!mac_initialized
)
9684 mac_initialized
= 1;
9688 error ("Sorry, this version can only handle one display");
9690 mac_initialize_display_info ();
9692 dpyinfo
= &one_mac_display_info
;
9694 dpyinfo
->xrdb
= mac_make_rdb (xrm_option
);
9696 /* Put this display on the chain. */
9697 dpyinfo
->next
= x_display_list
;
9698 x_display_list
= dpyinfo
;
9700 /* Put it on x_display_name_list. */
9701 x_display_name_list
= Fcons (Fcons (display_name
,
9702 Fcons (Qnil
, dpyinfo
->xrdb
)),
9703 x_display_name_list
);
9704 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
9710 /* Get rid of display DPYINFO, assuming all frames are already gone. */
9713 x_delete_display (dpyinfo
)
9714 struct mac_display_info
*dpyinfo
;
9718 /* Discard this display from x_display_name_list and x_display_list.
9719 We can't use Fdelq because that can quit. */
9720 if (! NILP (x_display_name_list
)
9721 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
9722 x_display_name_list
= XCDR (x_display_name_list
);
9727 tail
= x_display_name_list
;
9728 while (CONSP (tail
) && CONSP (XCDR (tail
)))
9730 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
9732 XSETCDR (tail
, XCDR (XCDR (tail
)));
9739 if (x_display_list
== dpyinfo
)
9740 x_display_list
= dpyinfo
->next
;
9743 struct x_display_info
*tail
;
9745 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
9746 if (tail
->next
== dpyinfo
)
9747 tail
->next
= tail
->next
->next
;
9750 /* Free the font names in the font table. */
9751 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
9752 if (dpyinfo
->font_table
[i
].name
)
9754 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
9755 xfree (dpyinfo
->font_table
[i
].full_name
);
9756 xfree (dpyinfo
->font_table
[i
].name
);
9759 if (dpyinfo
->font_table
->font_encoder
)
9760 xfree (dpyinfo
->font_table
->font_encoder
);
9762 xfree (dpyinfo
->font_table
);
9763 xfree (dpyinfo
->mac_id_name
);
9765 if (x_display_list
== 0)
9767 mac_clear_font_name_table ();
9768 bzero (dpyinfo
, sizeof (*dpyinfo
));
9777 extern int inhibit_window_system
;
9778 extern int noninteractive
;
9779 CFBundleRef appsBundle
;
9782 /* No need to test if already -nw*/
9783 if (inhibit_window_system
|| noninteractive
)
9786 appsBundle
= CFBundleGetMainBundle();
9787 if (appsBundle
!= NULL
)
9789 CFStringRef cfBI
= CFSTR("CFBundleIdentifier");
9790 CFTypeRef res
= CFBundleGetValueForInfoDictionaryKey(appsBundle
, cfBI
);
9791 /* We found the bundle identifier, now we know we are valid. */
9798 /* MAC_TODO: Have this start the bundled executable */
9800 /* For now, prevent the fatal error by bringing it up in the terminal */
9801 inhibit_window_system
= 1;
9805 MakeMeTheFrontProcess ()
9807 ProcessSerialNumber psn
;
9810 err
= GetCurrentProcess (&psn
);
9812 (void) SetFrontProcess (&psn
);
9815 /***** Code to handle C-g testing *****/
9817 /* Contains the Mac modifier formed from quit_char */
9818 int mac_quit_char_modifiers
= 0;
9819 int mac_quit_char_keycode
;
9820 extern int quit_char
;
9823 mac_determine_quit_char_modifiers()
9825 /* Todo: Determine modifiers from quit_char. */
9826 UInt32 qc_modifiers
= ctrl_modifier
;
9829 mac_quit_char_modifiers
= 0;
9830 if (qc_modifiers
& ctrl_modifier
) mac_quit_char_modifiers
|= macCtrlKey
;
9831 if (qc_modifiers
& shift_modifier
) mac_quit_char_modifiers
|= macShiftKey
;
9832 if (qc_modifiers
& meta_modifier
) mac_quit_char_modifiers
|= macMetaKey
;
9833 if (qc_modifiers
& alt_modifier
) mac_quit_char_modifiers
|= macAltKey
;
9837 init_quit_char_handler ()
9839 /* TODO: Let this support keys other the 'g' */
9840 mac_quit_char_keycode
= 5;
9841 /* Look at <architecture/adb_kb_map.h> for details */
9842 /* http://gemma.apple.com/techpubs/mac/Toolbox/Toolbox-40.html#MARKER-9-184*/
9844 mac_determine_quit_char_modifiers();
9848 quit_char_comp (EventRef inEvent
, void *inCompData
)
9850 if (GetEventClass(inEvent
) != kEventClassKeyboard
)
9852 if (GetEventKind(inEvent
) != kEventRawKeyDown
)
9856 UInt32 keyModifiers
;
9857 GetEventParameter(inEvent
, kEventParamKeyCode
,
9858 typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
9859 if (keyCode
!= mac_quit_char_keycode
)
9861 GetEventParameter(inEvent
, kEventParamKeyModifiers
,
9862 typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyModifiers
);
9863 if (keyModifiers
!= mac_quit_char_modifiers
)
9870 mac_check_for_quit_char ()
9873 static EMACS_TIME last_check_time
= { 0, 0 };
9874 static EMACS_TIME one_second
= { 1, 0 };
9877 /* If windows are not initialized, return immediately (keep it bouncin'). */
9878 if (!mac_quit_char_modifiers
)
9881 /* Don't check if last check is less than a second ago. */
9882 EMACS_GET_TIME (now
);
9883 EMACS_SUB_TIME (t
, now
, last_check_time
);
9884 if (EMACS_TIME_LT (t
, one_second
))
9886 last_check_time
= now
;
9888 /* Redetermine modifiers because they are based on lisp variables */
9889 mac_determine_quit_char_modifiers ();
9891 /* Fill the queue with events */
9893 ReceiveNextEvent (0, NULL
, kEventDurationNoWait
, false, &event
);
9894 event
= FindSpecificEventInQueue (GetMainEventQueue (), quit_char_comp
,
9899 struct input_event e
;
9901 /* Use an input_event to emulate what the interrupt handler does. */
9903 e
.kind
= ASCII_KEYSTROKE_EVENT
;
9907 e
.timestamp
= EventTimeToTicks (GetEventTime (event
)) * (1000/60);
9908 XSETFRAME (e
.frame_or_window
, mac_focus_frame (&one_mac_display_info
));
9909 /* Remove event from queue to prevent looping. */
9910 RemoveEventFromQueue (GetMainEventQueue (), event
);
9911 ReleaseEvent (event
);
9912 kbd_buffer_store_event (&e
);
9915 #endif /* MAC_OSX */
9923 MenuItemIndex menu_index
;
9925 err
= GetIndMenuItemWithCommandID (NULL
, kHICommandQuit
, 1,
9926 &menu
, &menu_index
);
9928 SetMenuItemCommandKey (menu
, menu_index
, false, 0);
9929 #if USE_CARBON_EVENTS
9930 EnableMenuCommand (NULL
, kHICommandPreferences
);
9931 err
= GetIndMenuItemWithCommandID (NULL
, kHICommandPreferences
, 1,
9932 &menu
, &menu_index
);
9935 SetMenuItemCommandKey (menu
, menu_index
, false, 0);
9936 InsertMenuItemTextWithCFString (menu
, NULL
,
9937 0, kMenuItemAttrSeparator
, 0);
9938 InsertMenuItemTextWithCFString (menu
, CFSTR ("About Emacs"),
9939 0, 0, kHICommandAbout
);
9941 #endif /* USE_CARBON_EVENTS */
9942 #else /* !MAC_OSX */
9943 #if USE_CARBON_EVENTS
9944 SetMenuItemCommandID (GetMenuHandle (M_APPLE
), I_ABOUT
, kHICommandAbout
);
9950 /* Set up use of X before we make the first connection. */
9952 extern frame_parm_handler mac_frame_parm_handlers
[];
9954 static struct redisplay_interface x_redisplay_interface
=
9956 mac_frame_parm_handlers
,
9960 x_clear_end_of_line
,
9962 x_after_update_window_line
,
9963 x_update_window_begin
,
9964 x_update_window_end
,
9967 0, /* flush_display_optional */
9968 x_clear_window_mouse_face
,
9969 x_get_glyph_overhangs
,
9970 x_fix_overlapping_area
,
9971 x_draw_fringe_bitmap
,
9972 0, /* define_fringe_bitmap */
9973 0, /* destroy_fringe_bitmap */
9974 mac_per_char_metric
,
9976 mac_compute_glyph_string_overhangs
,
9977 x_draw_glyph_string
,
9978 mac_define_frame_cursor
,
9979 mac_clear_frame_area
,
9980 mac_draw_window_cursor
,
9981 mac_draw_vertical_window_border
,
9982 mac_shift_glyphs_for_insert
9988 rif
= &x_redisplay_interface
;
9990 clear_frame_hook
= x_clear_frame
;
9991 ins_del_lines_hook
= x_ins_del_lines
;
9992 delete_glyphs_hook
= x_delete_glyphs
;
9993 ring_bell_hook
= XTring_bell
;
9994 reset_terminal_modes_hook
= XTreset_terminal_modes
;
9995 set_terminal_modes_hook
= XTset_terminal_modes
;
9996 update_begin_hook
= x_update_begin
;
9997 update_end_hook
= x_update_end
;
9998 set_terminal_window_hook
= XTset_terminal_window
;
9999 read_socket_hook
= XTread_socket
;
10000 frame_up_to_date_hook
= XTframe_up_to_date
;
10001 mouse_position_hook
= XTmouse_position
;
10002 frame_rehighlight_hook
= XTframe_rehighlight
;
10003 frame_raise_lower_hook
= XTframe_raise_lower
;
10005 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10006 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10007 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10008 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10010 scroll_region_ok
= 1; /* we'll scroll partial frames */
10011 char_ins_del_ok
= 1;
10012 line_ins_del_ok
= 1; /* we'll just blt 'em */
10013 fast_clear_end_of_line
= 1; /* X does this well */
10014 memory_below_frame
= 0; /* we don't remember what scrolls
10018 last_tool_bar_item
= -1;
10019 any_help_event_p
= 0;
10021 /* Try to use interrupt input; if we can't, then start polling. */
10022 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
10026 #if TARGET_API_MAC_CARBON
10027 init_required_apple_events ();
10029 #if USE_CARBON_EVENTS
10031 init_service_handler ();
10033 init_quit_char_handler ();
10034 #endif /* MAC_OSX */
10036 init_command_handler ();
10039 #endif /* USE_CARBON_EVENTS */
10042 if (!inhibit_window_system
)
10043 MakeMeTheFrontProcess ();
10054 staticpro (&x_error_message_string
);
10055 x_error_message_string
= Qnil
;
10058 Qmodifier_value
= intern ("modifier-value");
10059 Qalt
= intern ("alt");
10060 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10061 Qhyper
= intern ("hyper");
10062 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10063 Qsuper
= intern ("super");
10064 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10066 Qapplication
= intern ("application"); staticpro (&Qapplication
);
10067 Qabout
= intern ("about"); staticpro (&Qabout
);
10069 #if USE_CARBON_EVENTS && defined (MAC_OSX)
10070 Qpreferences
= intern ("preferences"); staticpro (&Qpreferences
);
10071 Qservices
= intern ("services"); staticpro (&Qservices
);
10072 Qpaste
= intern ("paste"); staticpro (&Qpaste
);
10073 Qperform
= intern ("perform"); staticpro (&Qperform
);
10077 Fprovide (intern ("mac-carbon"), Qnil
);
10080 staticpro (&Qreverse
);
10081 Qreverse
= intern ("reverse");
10083 staticpro (&x_display_name_list
);
10084 x_display_name_list
= Qnil
;
10086 staticpro (&last_mouse_scroll_bar
);
10087 last_mouse_scroll_bar
= Qnil
;
10089 Qmac_ready_for_drag_n_drop
= intern ("mac-ready-for-drag-n-drop");
10090 staticpro (&Qmac_ready_for_drag_n_drop
);
10092 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
10093 doc
: /* If not nil, Emacs uses toolkit scroll bars. */);
10094 #ifdef USE_TOOLKIT_SCROLL_BARS
10095 Vx_toolkit_scroll_bars
= Qt
;
10097 Vx_toolkit_scroll_bars
= Qnil
;
10100 staticpro (&last_mouse_motion_frame
);
10101 last_mouse_motion_frame
= Qnil
;
10103 DEFVAR_LISP ("mac-command-key-is-meta", &Vmac_command_key_is_meta
,
10104 doc
: /* Non-nil means that the command key is used as the Emacs meta key.
10105 Otherwise the option key is used. */);
10106 Vmac_command_key_is_meta
= Qt
;
10108 DEFVAR_LISP ("mac-option-modifier", &Vmac_option_modifier
,
10109 doc
: /* Modifier to use for the Mac alt/option key. The value can
10110 be alt, hyper, or super for the respective modifier. If the value is
10111 nil then the key will act as the normal Mac option modifier. */);
10112 Vmac_option_modifier
= Qnil
;
10114 DEFVAR_LISP ("mac-reverse-ctrl-meta", &Vmac_reverse_ctrl_meta
,
10115 doc
: /* Non-nil means that the control and meta keys are reversed. This is
10116 useful for non-standard keyboard layouts. */);
10117 Vmac_reverse_ctrl_meta
= Qnil
;
10119 DEFVAR_LISP ("mac-emulate-three-button-mouse",
10120 &Vmac_emulate_three_button_mouse
,
10121 doc
: /* t means that when the option-key is held down while pressing the
10122 mouse button, the click will register as mouse-2 and while the
10123 command-key is held down, the click will register as mouse-3.
10124 'reverse means that the option-key will register for mouse-3
10125 and the command-key will register for mouse-2. nil means that
10126 no emulation should be done and the modifiers should be placed
10127 on the mouse-1 event. */);
10128 Vmac_emulate_three_button_mouse
= Qnil
;
10130 #if USE_CARBON_EVENTS
10131 DEFVAR_LISP ("mac-wheel-button-is-mouse-2", &Vmac_wheel_button_is_mouse_2
,
10132 doc
: /* Non-nil means that the wheel button will be treated as mouse-2 and
10133 the right click will be mouse-3.
10134 Otherwise, the right click will be mouse-2 and the wheel button mouse-3.*/);
10135 Vmac_wheel_button_is_mouse_2
= Qt
;
10137 DEFVAR_LISP ("mac-pass-command-to-system", &Vmac_pass_command_to_system
,
10138 doc
: /* If non-nil, the Mac \"Command\" key is passed on to the Mac
10139 Toolbox for processing before Emacs sees it. */);
10140 Vmac_pass_command_to_system
= Qt
;
10142 DEFVAR_LISP ("mac-pass-control-to-system", &Vmac_pass_control_to_system
,
10143 doc
: /* If non-nil, the Mac \"Control\" key is passed on to the Mac
10144 Toolbox for processing before Emacs sees it. */);
10145 Vmac_pass_control_to_system
= Qt
;
10149 DEFVAR_LISP ("mac-allow-anti-aliasing", &Vmac_use_core_graphics
,
10150 doc
: /* If non-nil, allow anti-aliasing.
10151 The text will be rendered using Core Graphics text rendering which
10152 may anti-alias the text. */);
10153 Vmac_use_core_graphics
= Qnil
;
10155 /* Register an entry for `mac-roman' so that it can be used when
10156 creating the terminal frame on Mac OS 9 before loading
10157 term/mac-win.elc. */
10158 DEFVAR_LISP ("mac-charset-info-alist", &Vmac_charset_info_alist
,
10159 doc
: /* Alist linking Emacs character sets to Mac text encoding and Emacs coding system.
10160 Each entry should be of the form:
10162 (CHARSET-NAME TEXT-ENCODING CODING-SYSTEM)
10164 where CHARSET-NAME is a string used in font names to identify the
10165 charset, TEXT-ENCODING is a TextEncodingBase value, and CODING_SYSTEM
10166 is a coding system corresponding to TEXT-ENCODING. */);
10167 Vmac_charset_info_alist
=
10168 Fcons (list3 (build_string ("mac-roman"),
10169 make_number (smRoman
), Qnil
), Qnil
);
10172 /* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b
10173 (do not change this comment) */