aboutsummaryrefslogtreecommitdiffstats
path: root/src/macfns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/macfns.c')
-rw-r--r--src/macfns.c401
1 files changed, 261 insertions, 140 deletions
diff --git a/src/macfns.c b/src/macfns.c
index dbb8adb3fe1..ec014e772e3 100644
--- a/src/macfns.c
+++ b/src/macfns.c
@@ -1,5 +1,5 @@
1/* Graphical user interface functions for Mac OS. 1/* Graphical user interface functions for Mac OS.
2 Copyright (C) 2000, 2001 Free Software Foundation, Inc. 2 Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -42,7 +42,6 @@ Boston, MA 02111-1307, USA. */
42#include "epaths.h" 42#include "epaths.h"
43#include "termhooks.h" 43#include "termhooks.h"
44#include "coding.h" 44#include "coding.h"
45#include "ccl.h"
46#include "systime.h" 45#include "systime.h"
47 46
48/* #include "bitmaps/gray.xbm" */ 47/* #include "bitmaps/gray.xbm" */
@@ -59,17 +58,6 @@ static unsigned char gray_bits[] = {
59 58
60#include <stdlib.h> 59#include <stdlib.h>
61#include <string.h> 60#include <string.h>
62#ifndef MAC_OSX
63#include <alloca.h>
64#endif
65
66#ifdef MAC_OSX
67#include <QuickTime/QuickTime.h>
68#else /* not MAC_OSX */
69#include <Windows.h>
70#include <Gestalt.h>
71#include <TextUtils.h>
72#endif /* not MAC_OSX */
73 61
74/*extern void free_frame_menubar (); 62/*extern void free_frame_menubar ();
75extern double atof (); 63extern double atof ();
@@ -2580,8 +2568,6 @@ This function is an internal primitive--use `make-frame' instead. */)
2580 f->output_data.mac = (struct mac_output *) xmalloc (sizeof (struct mac_output)); 2568 f->output_data.mac = (struct mac_output *) xmalloc (sizeof (struct mac_output));
2581 bzero (f->output_data.mac, sizeof (struct mac_output)); 2569 bzero (f->output_data.mac, sizeof (struct mac_output));
2582 FRAME_FONTSET (f) = -1; 2570 FRAME_FONTSET (f) = -1;
2583 f->output_data.mac->scroll_bar_foreground_pixel = -1;
2584 f->output_data.mac->scroll_bar_background_pixel = -1;
2585 record_unwind_protect (unwind_create_frame, frame); 2571 record_unwind_protect (unwind_create_frame, frame);
2586 2572
2587 f->icon_name 2573 f->icon_name
@@ -2598,7 +2584,7 @@ This function is an internal primitive--use `make-frame' instead. */)
2598 2584
2599 if (!NILP (parent)) 2585 if (!NILP (parent))
2600 { 2586 {
2601 f->output_data.mac->parent_desc = (Window) parent; 2587 f->output_data.mac->parent_desc = (Window) XFASTINT (parent);
2602 f->output_data.mac->explicit_parent = 1; 2588 f->output_data.mac->explicit_parent = 1;
2603 } 2589 }
2604 else 2590 else
@@ -2708,7 +2694,7 @@ This function is an internal primitive--use `make-frame' instead. */)
2708 2694
2709 x_default_parameter (f, parms, Qmenu_bar_lines, make_number (1), 2695 x_default_parameter (f, parms, Qmenu_bar_lines, make_number (1),
2710 "menuBar", "MenuBar", RES_TYPE_NUMBER); 2696 "menuBar", "MenuBar", RES_TYPE_NUMBER);
2711 x_default_parameter (f, parms, Qtool_bar_lines, make_number (0), 2697 x_default_parameter (f, parms, Qtool_bar_lines, make_number (1),
2712 "toolBar", "ToolBar", RES_TYPE_NUMBER); 2698 "toolBar", "ToolBar", RES_TYPE_NUMBER);
2713 x_default_parameter (f, parms, Qbuffer_predicate, Qnil, 2699 x_default_parameter (f, parms, Qbuffer_predicate, Qnil,
2714 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL); 2700 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL);
@@ -2717,25 +2703,32 @@ This function is an internal primitive--use `make-frame' instead. */)
2717 2703
2718 f->output_data.mac->parent_desc = FRAME_MAC_DISPLAY_INFO (f)->root_window; 2704 f->output_data.mac->parent_desc = FRAME_MAC_DISPLAY_INFO (f)->root_window;
2719 2705
2720 /* MAC_TODO: specify 1 below when toolbars are implemented. */ 2706#if TARGET_API_MAC_CARBON
2721 window_prompting = x_figure_window_size (f, parms, 0); 2707 f->output_data.mac->text_cursor = kThemeIBeamCursor;
2708 f->output_data.mac->nontext_cursor = kThemeArrowCursor;
2709 f->output_data.mac->modeline_cursor = kThemeArrowCursor;
2710 f->output_data.mac->hand_cursor = kThemePointingHandCursor;
2711 f->output_data.mac->hourglass_cursor = kThemeWatchCursor;
2712 f->output_data.mac->horizontal_drag_cursor = kThemeResizeLeftRightCursor;
2713#else
2714 f->output_data.mac->text_cursor = GetCursor (iBeamCursor);
2715 f->output_data.mac->nontext_cursor = &arrow_cursor;
2716 f->output_data.mac->modeline_cursor = &arrow_cursor;
2717 f->output_data.mac->hand_cursor = &arrow_cursor;
2718 f->output_data.mac->hourglass_cursor = GetCursor (watchCursor);
2719 f->output_data.mac->horizontal_drag_cursor = &arrow_cursor;
2720#endif
2721
2722 /* Compute the size of the window. */
2723 window_prompting = x_figure_window_size (f, parms, 1);
2722 2724
2723 tem = mac_get_arg (parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); 2725 tem = mac_get_arg (parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
2724 f->no_split = minibuffer_only || EQ (tem, Qt); 2726 f->no_split = minibuffer_only || EQ (tem, Qt);
2725 2727
2726 /* Create the window. Add the tool-bar height to the initial frame
2727 height so that the user gets a text display area of the size he
2728 specified with -g or via the registry. Later changes of the
2729 tool-bar height don't change the frame size. This is done so that
2730 users can create tall Emacs frames without having to guess how
2731 tall the tool-bar will get. */
2732 FRAME_LINES (f) += FRAME_TOOL_BAR_LINES (f);
2733
2734 /* mac_window (f, window_prompting, minibuffer_only); */ 2728 /* mac_window (f, window_prompting, minibuffer_only); */
2735 make_mac_frame (f); 2729 make_mac_frame (f);
2736 2730
2737 x_icon (f, parms); 2731 x_icon (f, parms);
2738
2739 x_make_gc (f); 2732 x_make_gc (f);
2740 2733
2741 /* Now consider the frame official. */ 2734 /* Now consider the frame official. */
@@ -2754,7 +2747,8 @@ This function is an internal primitive--use `make-frame' instead. */)
2754 x_default_parameter (f, parms, Qcursor_type, Qbox, 2747 x_default_parameter (f, parms, Qcursor_type, Qbox,
2755 "cursorType", "CursorType", RES_TYPE_SYMBOL); 2748 "cursorType", "CursorType", RES_TYPE_SYMBOL);
2756 x_default_parameter (f, parms, Qscroll_bar_width, Qnil, 2749 x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
2757 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER); 2750 "scrollBarWidth", "ScrollBarWidth",
2751 RES_TYPE_NUMBER);
2758 2752
2759 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size. 2753 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
2760 Change will not be effected unless different from the current 2754 Change will not be effected unless different from the current
@@ -2762,13 +2756,10 @@ This function is an internal primitive--use `make-frame' instead. */)
2762 width = FRAME_COLS (f); 2756 width = FRAME_COLS (f);
2763 height = FRAME_LINES (f); 2757 height = FRAME_LINES (f);
2764 2758
2765 FRAME_LINES (f) = 0;
2766 SET_FRAME_COLS (f, 0); 2759 SET_FRAME_COLS (f, 0);
2760 FRAME_LINES (f) = 0;
2767 change_frame_size (f, height, width, 1, 0, 0); 2761 change_frame_size (f, height, width, 1, 0, 0);
2768 2762
2769 /* Set up faces after all frame parameters are known. */
2770 call1 (Qface_set_after_frame_default, frame);
2771
2772#if 0 /* MAC_TODO: when we have window manager hints */ 2763#if 0 /* MAC_TODO: when we have window manager hints */
2773 /* Tell the server what size and position, etc, we want, and how 2764 /* Tell the server what size and position, etc, we want, and how
2774 badly we want them. This should be done after we have the menu 2765 badly we want them. This should be done after we have the menu
@@ -2948,8 +2939,8 @@ If omitted or nil, that stands for the selected frame's display. */)
2948{ 2939{
2949 struct mac_display_info *dpyinfo = check_x_display_info (display); 2940 struct mac_display_info *dpyinfo = check_x_display_info (display);
2950 2941
2951 /* MAC_TODO: check whether this is right */ 2942 /* We force 24+ bit depths to 24-bit to prevent an overflow. */
2952 return make_number (dpyinfo->n_planes >= 8 ? 256 : 1 << dpyinfo->n_planes - 1); 2943 return make_number (1 << min (dpyinfo->n_planes, 24));
2953} 2944}
2954 2945
2955DEFUN ("x-server-max-request-size", Fx_server_max_request_size, 2946DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
@@ -3025,11 +3016,8 @@ If omitted or nil, that stands for the selected frame's display. */)
3025 /* MAC_TODO: this is an approximation, and only of the main display */ 3016 /* MAC_TODO: this is an approximation, and only of the main display */
3026 3017
3027 struct mac_display_info *dpyinfo = check_x_display_info (display); 3018 struct mac_display_info *dpyinfo = check_x_display_info (display);
3028 short h, v;
3029 3019
3030 ScreenRes (&h, &v); 3020 return make_number ((int) (dpyinfo->height * 25.4 / dpyinfo->resy));
3031
3032 return make_number ((int) (v / 72.0 * 25.4));
3033} 3021}
3034 3022
3035DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0, 3023DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
@@ -3043,11 +3031,8 @@ If omitted or nil, that stands for the selected frame's display. */)
3043 /* MAC_TODO: this is an approximation, and only of the main display */ 3031 /* MAC_TODO: this is an approximation, and only of the main display */
3044 3032
3045 struct mac_display_info *dpyinfo = check_x_display_info (display); 3033 struct mac_display_info *dpyinfo = check_x_display_info (display);
3046 short h, v;
3047
3048 ScreenRes (&h, &v);
3049 3034
3050 return make_number ((int) (h / 72.0 * 25.4)); 3035 return make_number ((int) (dpyinfo->width * 25.4 / dpyinfo->resx));
3051} 3036}
3052 3037
3053DEFUN ("x-display-backing-store", Fx_display_backing_store, 3038DEFUN ("x-display-backing-store", Fx_display_backing_store,
@@ -3595,9 +3580,11 @@ hide_hourglass ()
3595 ***********************************************************************/ 3580 ***********************************************************************/
3596 3581
3597static Lisp_Object x_create_tip_frame P_ ((struct mac_display_info *, 3582static Lisp_Object x_create_tip_frame P_ ((struct mac_display_info *,
3598 Lisp_Object)); 3583 Lisp_Object, Lisp_Object));
3584static void compute_tip_xy P_ ((struct frame *, Lisp_Object, Lisp_Object,
3585 Lisp_Object, int, int, int *, int *));
3599 3586
3600/* The frame of a currently visible tooltip, or null. */ 3587/* The frame of a currently visible tooltip. */
3601 3588
3602Lisp_Object tip_frame; 3589Lisp_Object tip_frame;
3603 3590
@@ -3612,15 +3599,42 @@ Window tip_window;
3612 3599
3613Lisp_Object last_show_tip_args; 3600Lisp_Object last_show_tip_args;
3614 3601
3602/* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
3603
3604Lisp_Object Vx_max_tooltip_size;
3605
3606
3607static Lisp_Object
3608unwind_create_tip_frame (frame)
3609 Lisp_Object frame;
3610{
3611 Lisp_Object deleted;
3612
3613 deleted = unwind_create_frame (frame);
3614 if (EQ (deleted, Qt))
3615 {
3616 tip_window = NULL;
3617 tip_frame = Qnil;
3618 }
3619
3620 return deleted;
3621}
3622
3623
3615/* Create a frame for a tooltip on the display described by DPYINFO. 3624/* Create a frame for a tooltip on the display described by DPYINFO.
3616 PARMS is a list of frame parameters. Value is the frame. */ 3625 PARMS is a list of frame parameters. TEXT is the string to
3626 display in the tip frame. Value is the frame.
3627
3628 Note that functions called here, esp. x_default_parameter can
3629 signal errors, for instance when a specified color name is
3630 undefined. We have to make sure that we're in a consistent state
3631 when this happens. */
3617 3632
3618static Lisp_Object 3633static Lisp_Object
3619x_create_tip_frame (dpyinfo, parms) 3634x_create_tip_frame (dpyinfo, parms, text)
3620 struct mac_display_info *dpyinfo; 3635 struct mac_display_info *dpyinfo;
3621 Lisp_Object parms; 3636 Lisp_Object parms, text;
3622{ 3637{
3623#if 0 /* MAC_TODO : Mac version */
3624 struct frame *f; 3638 struct frame *f;
3625 Lisp_Object frame, tem; 3639 Lisp_Object frame, tem;
3626 Lisp_Object name; 3640 Lisp_Object name;
@@ -3629,8 +3643,11 @@ x_create_tip_frame (dpyinfo, parms)
3629 int count = SPECPDL_INDEX (); 3643 int count = SPECPDL_INDEX ();
3630 struct gcpro gcpro1, gcpro2, gcpro3; 3644 struct gcpro gcpro1, gcpro2, gcpro3;
3631 struct kboard *kb; 3645 struct kboard *kb;
3646 int face_change_count_before = face_change_count;
3647 Lisp_Object buffer;
3648 struct buffer *old_buffer;
3632 3649
3633 check_x (); 3650 check_mac ();
3634 3651
3635 /* Use this general default value to start with until we know if 3652 /* Use this general default value to start with until we know if
3636 this frame has a specified name. */ 3653 this frame has a specified name. */
@@ -3643,7 +3660,7 @@ x_create_tip_frame (dpyinfo, parms)
3643#endif 3660#endif
3644 3661
3645 /* Get the name of the frame to use for resource lookup. */ 3662 /* Get the name of the frame to use for resource lookup. */
3646 name = w32_get_arg (parms, Qname, "name", "Name", RES_TYPE_STRING); 3663 name = mac_get_arg (parms, Qname, "name", "Name", RES_TYPE_STRING);
3647 if (!STRINGP (name) 3664 if (!STRINGP (name)
3648 && !EQ (name, Qunbound) 3665 && !EQ (name, Qunbound)
3649 && !NILP (name)) 3666 && !NILP (name))
@@ -3652,31 +3669,50 @@ x_create_tip_frame (dpyinfo, parms)
3652 3669
3653 frame = Qnil; 3670 frame = Qnil;
3654 GCPRO3 (parms, name, frame); 3671 GCPRO3 (parms, name, frame);
3655 tip_frame = f = make_frame (1); 3672 f = make_frame (1);
3656 XSETFRAME (frame, f); 3673 XSETFRAME (frame, f);
3674
3675 buffer = Fget_buffer_create (build_string (" *tip*"));
3676 Fset_window_buffer (FRAME_ROOT_WINDOW (f), buffer, Qnil);
3677 old_buffer = current_buffer;
3678 set_buffer_internal_1 (XBUFFER (buffer));
3679 current_buffer->truncate_lines = Qnil;
3680 specbind (Qinhibit_read_only, Qt);
3681 specbind (Qinhibit_modification_hooks, Qt);
3682 Ferase_buffer ();
3683 Finsert (1, &text);
3684 set_buffer_internal_1 (old_buffer);
3685
3657 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0; 3686 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
3687 record_unwind_protect (unwind_create_tip_frame, frame);
3658 3688
3659 f->output_method = output_w32; 3689 /* By setting the output method, we're essentially saying that
3660 f->output_data.w32 = 3690 the frame is live, as per FRAME_LIVE_P. If we get a signal
3661 (struct w32_output *) xmalloc (sizeof (struct w32_output)); 3691 from this point on, x_destroy_window might screw up reference
3662 bzero (f->output_data.w32, sizeof (struct w32_output)); 3692 counts etc. */
3663#if 0 3693 f->output_method = output_mac;
3664 f->output_data.w32->icon_bitmap = -1; 3694 f->output_data.mac =
3665#endif 3695 (struct mac_output *) xmalloc (sizeof (struct mac_output));
3666 FRAME_FONTSET (f) = -1; 3696 bzero (f->output_data.mac, sizeof (struct mac_output));
3697
3698 FRAME_FONTSET (f) = -1;
3667 f->icon_name = Qnil; 3699 f->icon_name = Qnil;
3668 3700
3701#if 0 /* GLYPH_DEBUG TODO: image support. */
3702 image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
3703 dpyinfo_refcount = dpyinfo->reference_count;
3704#endif /* GLYPH_DEBUG */
3669#ifdef MULTI_KBOARD 3705#ifdef MULTI_KBOARD
3670 FRAME_KBOARD (f) = kb; 3706 FRAME_KBOARD (f) = kb;
3671#endif 3707#endif
3672 f->output_data.w32->parent_desc = FRAME_W32_DISPLAY_INFO (f)->root_window; 3708 f->output_data.mac->parent_desc = FRAME_MAC_DISPLAY_INFO (f)->root_window;
3673 f->output_data.w32->explicit_parent = 0; 3709 f->output_data.mac->explicit_parent = 0;
3674 3710
3675 /* Set the name; the functions to which we pass f expect the name to 3711 /* Set the name; the functions to which we pass f expect the name to
3676 be set. */ 3712 be set. */
3677 if (EQ (name, Qunbound) || NILP (name)) 3713 if (EQ (name, Qunbound) || NILP (name))
3678 { 3714 {
3679 f->name = build_string (dpyinfo->x_id_name); 3715 f->name = build_string (dpyinfo->mac_id_name);
3680 f->explicit_name = 0; 3716 f->explicit_name = 0;
3681 } 3717 }
3682 else 3718 else
@@ -3687,12 +3723,12 @@ x_create_tip_frame (dpyinfo, parms)
3687 specbind (Qx_resource_name, name); 3723 specbind (Qx_resource_name, name);
3688 } 3724 }
3689 3725
3690 /* Extract the window parameters from the supplied values 3726 /* Extract the window parameters from the supplied values that are
3691 that are needed to determine window geometry. */ 3727 needed to determine window geometry. */
3692 { 3728 {
3693 Lisp_Object font; 3729 Lisp_Object font;
3694 3730
3695 font = w32_get_arg (parms, Qfont, "font", "Font", RES_TYPE_STRING); 3731 font = mac_get_arg (parms, Qfont, "font", "Font", RES_TYPE_STRING);
3696 3732
3697 BLOCK_INPUT; 3733 BLOCK_INPUT;
3698 /* First, try whatever font the caller has specified. */ 3734 /* First, try whatever font the caller has specified. */
@@ -3706,22 +3742,16 @@ x_create_tip_frame (dpyinfo, parms)
3706 } 3742 }
3707 3743
3708 /* Try out a font which we hope has bold and italic variations. */ 3744 /* Try out a font which we hope has bold and italic variations. */
3709 if (!STRINGP (font))
3710 font = x_new_font (f, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
3711 if (!STRINGP (font))
3712 font = x_new_font (f, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3713 if (! STRINGP (font))
3714 font = x_new_font (f, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3715 if (! STRINGP (font)) 3745 if (! STRINGP (font))
3716 /* This was formerly the first thing tried, but it finds too many fonts 3746 font = x_new_font (f, "-ETL-fixed-medium-r-*--*-160-*-*-*-*-iso8859-1");
3717 and takes too long. */
3718 font = x_new_font (f, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
3719 /* If those didn't work, look for something which will at least work. */ 3747 /* If those didn't work, look for something which will at least work. */
3720 if (! STRINGP (font)) 3748 if (! STRINGP (font))
3721 font = x_new_font (f, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1"); 3749 font = x_new_font (f, "-*-monaco-*-12-*-mac-roman");
3750 if (! STRINGP (font))
3751 font = x_new_font (f, "-*-courier-*-10-*-mac-roman");
3722 UNBLOCK_INPUT; 3752 UNBLOCK_INPUT;
3723 if (! STRINGP (font)) 3753 if (! STRINGP (font))
3724 font = build_string ("fixed"); 3754 error ("Cannot find any usable font");
3725 3755
3726 x_default_parameter (f, parms, Qfont, font, 3756 x_default_parameter (f, parms, Qfont, font,
3727 "font", "Font", RES_TYPE_STRING); 3757 "font", "Font", RES_TYPE_STRING);
@@ -3737,7 +3767,7 @@ x_create_tip_frame (dpyinfo, parms)
3737 { 3767 {
3738 Lisp_Object value; 3768 Lisp_Object value;
3739 3769
3740 value = w32_get_arg (parms, Qinternal_border_width, 3770 value = mac_get_arg (parms, Qinternal_border_width,
3741 "internalBorder", "internalBorder", RES_TYPE_NUMBER); 3771 "internalBorder", "internalBorder", RES_TYPE_NUMBER);
3742 if (! EQ (value, Qunbound)) 3772 if (! EQ (value, Qunbound))
3743 parms = Fcons (Fcons (Qinternal_border_width, value), 3773 parms = Fcons (Fcons (Qinternal_border_width, value),
@@ -3768,34 +3798,28 @@ x_create_tip_frame (dpyinfo, parms)
3768 happen. */ 3798 happen. */
3769 init_frame_faces (f); 3799 init_frame_faces (f);
3770 3800
3771 f->output_data.w32->parent_desc = FRAME_W32_DISPLAY_INFO (f)->root_window; 3801 f->output_data.mac->parent_desc = FRAME_MAC_DISPLAY_INFO (f)->root_window;
3772 3802
3773 window_prompting = x_figure_window_size (f, parms, 0); 3803 window_prompting = x_figure_window_size (f, parms, 0);
3774 3804
3775 { 3805 {
3776 XSetWindowAttributes attrs; 3806 Rect r;
3777 unsigned long mask;
3778 3807
3779 BLOCK_INPUT; 3808 BLOCK_INPUT;
3780 mask = CWBackPixel | CWOverrideRedirect | CWSaveUnder | CWEventMask; 3809 SetRect (&r, 0, 0, 1, 1);
3781 /* Window managers looks at the override-redirect flag to 3810 if (CreateNewWindow (kHelpWindowClass,
3782 determine whether or net to give windows a decoration (Xlib 3811#ifdef MAC_OS_X_VERSION_10_2
3783 3.2.8). */ 3812 kWindowIgnoreClicksAttribute |
3784 attrs.override_redirect = True; 3813#endif
3785 attrs.save_under = True; 3814 kWindowNoActivatesAttribute,
3786 attrs.background_pixel = FRAME_BACKGROUND_PIXEL (f); 3815 &r, &tip_window) == noErr)
3787 /* Arrange for getting MapNotify and UnmapNotify events. */ 3816 {
3788 attrs.event_mask = StructureNotifyMask; 3817 FRAME_MAC_WINDOW (f) = tip_window;
3789 tip_window 3818 SetWRefCon (tip_window, (long) f->output_data.mac);
3790 = FRAME_W32_WINDOW (f) 3819 /* so that update events can find this mac_output struct */
3791 = XCreateWindow (FRAME_W32_DISPLAY (f), 3820 f->output_data.mac->mFP = f;
3792 FRAME_W32_DISPLAY_INFO (f)->root_window, 3821 ShowWindow (tip_window);
3793 /* x, y, width, height */ 3822 }
3794 0, 0, 1, 1,
3795 /* Border. */
3796 1,
3797 CopyFromParent, InputOutput, CopyFromParent,
3798 mask, &attrs);
3799 UNBLOCK_INPUT; 3823 UNBLOCK_INPUT;
3800 } 3824 }
3801 3825
@@ -3813,8 +3837,8 @@ x_create_tip_frame (dpyinfo, parms)
3813 FRAME_LINES (f). */ 3837 FRAME_LINES (f). */
3814 width = FRAME_COLS (f); 3838 width = FRAME_COLS (f);
3815 height = FRAME_LINES (f); 3839 height = FRAME_LINES (f);
3816 FRAME_LINES (f) = 0;
3817 SET_FRAME_COLS (f, 0); 3840 SET_FRAME_COLS (f, 0);
3841 FRAME_LINES (f) = 0;
3818 change_frame_size (f, height, width, 1, 0, 0); 3842 change_frame_size (f, height, width, 1, 0, 0);
3819 3843
3820 /* Add `tooltip' frame parameter's default value. */ 3844 /* Add `tooltip' frame parameter's default value. */
@@ -3822,6 +3846,26 @@ x_create_tip_frame (dpyinfo, parms)
3822 Fmodify_frame_parameters (frame, Fcons (Fcons (intern ("tooltip"), Qt), 3846 Fmodify_frame_parameters (frame, Fcons (Fcons (intern ("tooltip"), Qt),
3823 Qnil)); 3847 Qnil));
3824 3848
3849 /* Set up faces after all frame parameters are known. This call
3850 also merges in face attributes specified for new frames.
3851
3852 Frame parameters may be changed if .Xdefaults contains
3853 specifications for the default font. For example, if there is an
3854 `Emacs.default.attributeBackground: pink', the `background-color'
3855 attribute of the frame get's set, which let's the internal border
3856 of the tooltip frame appear in pink. Prevent this. */
3857 {
3858 Lisp_Object bg = Fframe_parameter (frame, Qbackground_color);
3859
3860 /* Set tip_frame here, so that */
3861 tip_frame = frame;
3862 call1 (Qface_set_after_frame_default, frame);
3863
3864 if (!EQ (bg, Fframe_parameter (frame, Qbackground_color)))
3865 Fmodify_frame_parameters (frame, Fcons (Fcons (Qbackground_color, bg),
3866 Qnil));
3867 }
3868
3825 f->no_split = 1; 3869 f->no_split = 1;
3826 3870
3827 UNGCPRO; 3871 UNGCPRO;
@@ -3833,17 +3877,80 @@ x_create_tip_frame (dpyinfo, parms)
3833 3877
3834 /* Now that the frame is official, it counts as a reference to 3878 /* Now that the frame is official, it counts as a reference to
3835 its display. */ 3879 its display. */
3836 FRAME_W32_DISPLAY_INFO (f)->reference_count++; 3880 FRAME_MAC_DISPLAY_INFO (f)->reference_count++;
3837 3881
3882 /* Setting attributes of faces of the tooltip frame from resources
3883 and similar will increment face_change_count, which leads to the
3884 clearing of all current matrices. Since this isn't necessary
3885 here, avoid it by resetting face_change_count to the value it
3886 had before we created the tip frame. */
3887 face_change_count = face_change_count_before;
3888
3889 /* Discard the unwind_protect. */
3838 return unbind_to (count, frame); 3890 return unbind_to (count, frame);
3839#endif /* MAC_TODO */ 3891}
3840 return Qnil; 3892
3893
3894/* Compute where to display tip frame F. PARMS is the list of frame
3895 parameters for F. DX and DY are specified offsets from the current
3896 location of the mouse. WIDTH and HEIGHT are the width and height
3897 of the tooltip. Return coordinates relative to the root window of
3898 the display in *ROOT_X, and *ROOT_Y. */
3899
3900static void
3901compute_tip_xy (f, parms, dx, dy, width, height, root_x, root_y)
3902 struct frame *f;
3903 Lisp_Object parms, dx, dy;
3904 int width, height;
3905 int *root_x, *root_y;
3906{
3907 Lisp_Object left, top;
3908
3909 /* User-specified position? */
3910 left = Fcdr (Fassq (Qleft, parms));
3911 top = Fcdr (Fassq (Qtop, parms));
3912
3913 /* Move the tooltip window where the mouse pointer is. Resize and
3914 show it. */
3915 if (!INTEGERP (left) || !INTEGERP (top))
3916 {
3917 Point mouse_pos;
3918
3919 BLOCK_INPUT;
3920 GetMouse (&mouse_pos);
3921 LocalToGlobal (&mouse_pos);
3922 *root_x = mouse_pos.h;
3923 *root_y = mouse_pos.v;
3924 UNBLOCK_INPUT;
3925 }
3926
3927 if (INTEGERP (top))
3928 *root_y = XINT (top);
3929 else if (*root_y + XINT (dy) - height < 0)
3930 *root_y -= XINT (dy);
3931 else
3932 {
3933 *root_y -= height;
3934 *root_y += XINT (dy);
3935 }
3936
3937 if (INTEGERP (left))
3938 *root_x = XINT (left);
3939 else if (*root_x + XINT (dx) + width <= FRAME_MAC_DISPLAY_INFO (f)->width)
3940 /* It fits to the right of the pointer. */
3941 *root_x += XINT (dx);
3942 else if (width + XINT (dx) <= *root_x)
3943 /* It fits to the left of the pointer. */
3944 *root_x -= width + XINT (dx);
3945 else
3946 /* Put it left-justified on the screen -- it ought to fit that way. */
3947 *root_x = 0;
3841} 3948}
3842 3949
3843 3950
3844DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0, 3951DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
3845 doc : /* Show STRING in a "tooltip" window on frame FRAME. 3952 doc: /* Show STRING in a "tooltip" window on frame FRAME.
3846A tooltip window is a small window displaying a string. 3953A tooltip window is a small X window displaying a string.
3847 3954
3848FRAME nil or omitted means use the selected frame. 3955FRAME nil or omitted means use the selected frame.
3849 3956
@@ -3859,19 +3966,19 @@ displayed at the mouse position, with offset DX added (default is 5 if
3859DX isn't specified). Likewise for the y-position; if a `top' frame 3966DX isn't specified). Likewise for the y-position; if a `top' frame
3860parameter is specified, it determines the y-position of the tooltip 3967parameter is specified, it determines the y-position of the tooltip
3861window, otherwise it is displayed at the mouse position, with offset 3968window, otherwise it is displayed at the mouse position, with offset
3862DY added (default is 10). */) 3969DY added (default is -10).
3863 (string, frame, parms, timeout, dx, dy) 3970
3971A tooltip's maximum size is specified by `x-max-tooltip-size'.
3972Text larger than the specified size is clipped. */)
3973 (string, frame, parms, timeout, dx, dy)
3864 Lisp_Object string, frame, parms, timeout, dx, dy; 3974 Lisp_Object string, frame, parms, timeout, dx, dy;
3865{ 3975{
3866 struct frame *f; 3976 struct frame *f;
3867 struct window *w; 3977 struct window *w;
3868 Window root, child; 3978 int root_x, root_y;
3869 Lisp_Object buffer, top, left;
3870 struct buffer *old_buffer; 3979 struct buffer *old_buffer;
3871 struct text_pos pos; 3980 struct text_pos pos;
3872 int i, width, height; 3981 int i, width, height;
3873 int root_x, root_y, win_x, win_y;
3874 unsigned pmask;
3875 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 3982 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
3876 int old_windows_or_buffers_changed = windows_or_buffers_changed; 3983 int old_windows_or_buffers_changed = windows_or_buffers_changed;
3877 int count = SPECPDL_INDEX (); 3984 int count = SPECPDL_INDEX ();
@@ -3920,13 +4027,11 @@ DY added (default is 10). */)
3920 call1 (Qcancel_timer, timer); 4027 call1 (Qcancel_timer, timer);
3921 } 4028 }
3922 4029
3923#if 0 /* MAC_TODO : Mac specifics */
3924 BLOCK_INPUT; 4030 BLOCK_INPUT;
3925 compute_tip_xy (f, parms, dx, dy, &root_x, &root_y); 4031 compute_tip_xy (f, parms, dx, dy, FRAME_PIXEL_WIDTH (f),
3926 XMoveWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 4032 FRAME_PIXEL_HEIGHT (f), &root_x, &root_y);
3927 root_x, root_y - FRAME_PIXEL_HEIGHT (f)); 4033 MoveWindow (FRAME_MAC_WINDOW (f), root_x, root_y, false);
3928 UNBLOCK_INPUT; 4034 UNBLOCK_INPUT;
3929#endif /* MAC_TODO */
3930 goto start_timer; 4035 goto start_timer;
3931 } 4036 }
3932 } 4037 }
@@ -3953,26 +4058,36 @@ DY added (default is 10). */)
3953 4058
3954 /* Create a frame for the tooltip, and record it in the global 4059 /* Create a frame for the tooltip, and record it in the global
3955 variable tip_frame. */ 4060 variable tip_frame. */
3956 frame = x_create_tip_frame (FRAME_MAC_DISPLAY_INFO (f), parms); 4061 frame = x_create_tip_frame (FRAME_MAC_DISPLAY_INFO (f), parms, string);
3957 f = XFRAME (frame); 4062 f = XFRAME (frame);
3958 4063
3959 /* Set up the frame's root window. Currently we use a size of 80 4064 /* Set up the frame's root window. */
3960 columns x 40 lines. If someone wants to show a larger tip, he
3961 will loose. I don't think this is a realistic case. */
3962 w = XWINDOW (FRAME_ROOT_WINDOW (f)); 4065 w = XWINDOW (FRAME_ROOT_WINDOW (f));
3963 w->left_col = w->top_line = make_number (0); 4066 w->left_col = w->top_line = make_number (0);
3964 w->total_cols = make_number (80); 4067
3965 w->total_lines = make_number (40); 4068 if (CONSP (Vx_max_tooltip_size)
4069 && INTEGERP (XCAR (Vx_max_tooltip_size))
4070 && XINT (XCAR (Vx_max_tooltip_size)) > 0
4071 && INTEGERP (XCDR (Vx_max_tooltip_size))
4072 && XINT (XCDR (Vx_max_tooltip_size)) > 0)
4073 {
4074 w->total_cols = XCAR (Vx_max_tooltip_size);
4075 w->total_lines = XCDR (Vx_max_tooltip_size);
4076 }
4077 else
4078 {
4079 w->total_cols = make_number (80);
4080 w->total_lines = make_number (40);
4081 }
4082
4083 FRAME_TOTAL_COLS (f) = XINT (w->total_cols);
3966 adjust_glyphs (f); 4084 adjust_glyphs (f);
3967 w->pseudo_window_p = 1; 4085 w->pseudo_window_p = 1;
3968 4086
3969 /* Display the tooltip text in a temporary buffer. */ 4087 /* Display the tooltip text in a temporary buffer. */
3970 buffer = Fget_buffer_create (build_string (" *tip*"));
3971 Fset_window_buffer (FRAME_ROOT_WINDOW (f), buffer, Qnil);
3972 old_buffer = current_buffer; 4088 old_buffer = current_buffer;
3973 set_buffer_internal_1 (XBUFFER (buffer)); 4089 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f))->buffer));
3974 Ferase_buffer (); 4090 current_buffer->truncate_lines = Qnil;
3975 Finsert (1, &string);
3976 clear_glyph_matrix (w->desired_matrix); 4091 clear_glyph_matrix (w->desired_matrix);
3977 clear_glyph_matrix (w->current_matrix); 4092 clear_glyph_matrix (w->current_matrix);
3978 SET_TEXT_POS (pos, BEGV, BEGV_BYTE); 4093 SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
@@ -3993,7 +4108,7 @@ DY added (default is 10). */)
3993 /* Let the row go over the full width of the frame. */ 4108 /* Let the row go over the full width of the frame. */
3994 row->full_width_p = 1; 4109 row->full_width_p = 1;
3995 4110
3996 /* There's a glyph at the end of rows that is use to place 4111 /* There's a glyph at the end of rows that is used to place
3997 the cursor there. Don't include the width of this glyph. */ 4112 the cursor there. Don't include the width of this glyph. */
3998 if (row->used[TEXT_AREA]) 4113 if (row->used[TEXT_AREA])
3999 { 4114 {
@@ -4014,17 +4129,13 @@ DY added (default is 10). */)
4014 4129
4015 /* Move the tooltip window where the mouse pointer is. Resize and 4130 /* Move the tooltip window where the mouse pointer is. Resize and
4016 show it. */ 4131 show it. */
4017#if 0 /* TODO : Mac specifics */ 4132 compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
4018 compute_tip_xy (f, parms, dx, dy, &root_x, &root_y);
4019 4133
4020 BLOCK_INPUT; 4134 BLOCK_INPUT;
4021 XQueryPointer (FRAME_W32_DISPLAY (f), FRAME_W32_DISPLAY_INFO (f)->root_window, 4135 MoveWindow (FRAME_MAC_WINDOW (f), root_x, root_y, false);
4022 &root, &child, &root_x, &root_y, &win_x, &win_y, &pmask); 4136 SizeWindow (FRAME_MAC_WINDOW (f), width, height, true);
4023 XMoveResizeWindow (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), 4137 BringToFront (FRAME_MAC_WINDOW (f));
4024 root_x + 5, root_y - height - 5, width, height);
4025 XMapRaised (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f));
4026 UNBLOCK_INPUT; 4138 UNBLOCK_INPUT;
4027#endif /* MAC_TODO */
4028 4139
4029 /* Draw into the window. */ 4140 /* Draw into the window. */
4030 w->must_be_updated_p = 1; 4141 w->must_be_updated_p = 1;
@@ -4046,8 +4157,8 @@ DY added (default is 10). */)
4046 4157
4047DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0, 4158DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
4048 doc: /* Hide the current tooltip window, if there is any. 4159 doc: /* Hide the current tooltip window, if there is any.
4049Value is t is tooltip was open, nil otherwise. */) 4160Value is t if tooltip was open, nil otherwise. */)
4050 () 4161 ()
4051{ 4162{
4052 int count; 4163 int count;
4053 Lisp_Object deleted, frame, timer; 4164 Lisp_Object deleted, frame, timer;
@@ -4249,7 +4360,8 @@ syms_of_macfns ()
4249 staticpro (&Qsuppress_icon); 4360 staticpro (&Qsuppress_icon);
4250 Qundefined_color = intern ("undefined-color"); 4361 Qundefined_color = intern ("undefined-color");
4251 staticpro (&Qundefined_color); 4362 staticpro (&Qundefined_color);
4252 /* This is the end of symbol initialization. */ 4363 Qcancel_timer = intern ("cancel-timer");
4364 staticpro (&Qcancel_timer);
4253 4365
4254 Qhyper = intern ("hyper"); 4366 Qhyper = intern ("hyper");
4255 staticpro (&Qhyper); 4367 staticpro (&Qhyper);
@@ -4265,6 +4377,7 @@ syms_of_macfns ()
4265 staticpro (&Qcontrol); 4377 staticpro (&Qcontrol);
4266 Qshift = intern ("shift"); 4378 Qshift = intern ("shift");
4267 staticpro (&Qshift); 4379 staticpro (&Qshift);
4380 /* This is the end of symbol initialization. */
4268 4381
4269 /* Text property `display' should be nonsticky by default. */ 4382 /* Text property `display' should be nonsticky by default. */
4270 Vtext_property_default_nonsticky 4383 Vtext_property_default_nonsticky
@@ -4314,6 +4427,11 @@ or when you set the mouse color. */);
4314 doc: /* A string indicating the foreground color of the cursor box. */); 4427 doc: /* A string indicating the foreground color of the cursor box. */);
4315 Vx_cursor_fore_pixel = Qnil; 4428 Vx_cursor_fore_pixel = Qnil;
4316 4429
4430 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size,
4431 doc: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS).
4432Text larger than this is clipped. */);
4433 Vx_max_tooltip_size = Fcons (make_number (80), make_number (40));
4434
4317 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager, 4435 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager,
4318 doc: /* Non-nil if no window manager is in use. 4436 doc: /* Non-nil if no window manager is in use.
4319Emacs doesn't try to figure this out; this is always nil 4437Emacs doesn't try to figure this out; this is always nil
@@ -4386,6 +4504,9 @@ Chinese, Japanese, and Korean. */);
4386 tip_frame = Qnil; 4504 tip_frame = Qnil;
4387 staticpro (&tip_frame); 4505 staticpro (&tip_frame);
4388 4506
4507 last_show_tip_args = Qnil;
4508 staticpro (&last_show_tip_args);
4509
4389#if 0 /* MAC_TODO */ 4510#if 0 /* MAC_TODO */
4390 defsubr (&Sx_file_dialog); 4511 defsubr (&Sx_file_dialog);
4391#endif 4512#endif