aboutsummaryrefslogtreecommitdiffstats
path: root/src/macfns.c
diff options
context:
space:
mode:
authorSteven Tamm2004-05-30 00:18:41 +0000
committerSteven Tamm2004-05-30 00:18:41 +0000
commit50bf76732ba3cd84d56185685e58604dd139ba94 (patch)
tree1f86ade4b3d5ac94add211e8ffbb8690941033fc /src/macfns.c
parentf2f82fa491294e51620ef6eddfd03912e28e2936 (diff)
downloademacs-50bf76732ba3cd84d56185685e58604dd139ba94.tar.gz
emacs-50bf76732ba3cd84d56185685e58604dd139ba94.zip
Support Tooltips with the Carbon emacs port.
Some code cleanup using helper macros.
Diffstat (limited to 'src/macfns.c')
-rw-r--r--src/macfns.c391
1 files changed, 255 insertions, 136 deletions
diff --git a/src/macfns.c b/src/macfns.c
index 625ca29336c..4147325c288 100644
--- a/src/macfns.c
+++ b/src/macfns.c
@@ -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
@@ -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
@@ -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,26 @@ 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;
3777 unsigned long mask;
3778
3779 BLOCK_INPUT; 3806 BLOCK_INPUT;
3780 mask = CWBackPixel | CWOverrideRedirect | CWSaveUnder | CWEventMask; 3807 Rect r;
3781 /* Window managers looks at the override-redirect flag to 3808
3782 determine whether or net to give windows a decoration (Xlib 3809 SetRect (&r, 0, 0, 1, 1);
3783 3.2.8). */ 3810 if (CreateNewWindow (kHelpWindowClass,
3784 attrs.override_redirect = True; 3811 kWindowNoActivatesAttribute
3785 attrs.save_under = True; 3812 | kWindowIgnoreClicksAttribute,
3786 attrs.background_pixel = FRAME_BACKGROUND_PIXEL (f); 3813 &r, &tip_window) == noErr)
3787 /* Arrange for getting MapNotify and UnmapNotify events. */ 3814 {
3788 attrs.event_mask = StructureNotifyMask; 3815 FRAME_MAC_WINDOW (f) = tip_window;
3789 tip_window 3816 SetWRefCon (tip_window, (long) f->output_data.mac);
3790 = FRAME_W32_WINDOW (f) 3817 /* so that update events can find this mac_output struct */
3791 = XCreateWindow (FRAME_W32_DISPLAY (f), 3818 f->output_data.mac->mFP = f;
3792 FRAME_W32_DISPLAY_INFO (f)->root_window, 3819 ShowWindow (tip_window);
3793 /* x, y, width, height */ 3820 }
3794 0, 0, 1, 1,
3795 /* Border. */
3796 1,
3797 CopyFromParent, InputOutput, CopyFromParent,
3798 mask, &attrs);
3799 UNBLOCK_INPUT; 3821 UNBLOCK_INPUT;
3800 } 3822 }
3801 3823
@@ -3813,8 +3835,8 @@ x_create_tip_frame (dpyinfo, parms)
3813 FRAME_LINES (f). */ 3835 FRAME_LINES (f). */
3814 width = FRAME_COLS (f); 3836 width = FRAME_COLS (f);
3815 height = FRAME_LINES (f); 3837 height = FRAME_LINES (f);
3816 FRAME_LINES (f) = 0;
3817 SET_FRAME_COLS (f, 0); 3838 SET_FRAME_COLS (f, 0);
3839 FRAME_LINES (f) = 0;
3818 change_frame_size (f, height, width, 1, 0, 0); 3840 change_frame_size (f, height, width, 1, 0, 0);
3819 3841
3820 /* Add `tooltip' frame parameter's default value. */ 3842 /* Add `tooltip' frame parameter's default value. */
@@ -3822,6 +3844,26 @@ x_create_tip_frame (dpyinfo, parms)
3822 Fmodify_frame_parameters (frame, Fcons (Fcons (intern ("tooltip"), Qt), 3844 Fmodify_frame_parameters (frame, Fcons (Fcons (intern ("tooltip"), Qt),
3823 Qnil)); 3845 Qnil));
3824 3846
3847 /* Set up faces after all frame parameters are known. This call
3848 also merges in face attributes specified for new frames.
3849
3850 Frame parameters may be changed if .Xdefaults contains
3851 specifications for the default font. For example, if there is an
3852 `Emacs.default.attributeBackground: pink', the `background-color'
3853 attribute of the frame get's set, which let's the internal border
3854 of the tooltip frame appear in pink. Prevent this. */
3855 {
3856 Lisp_Object bg = Fframe_parameter (frame, Qbackground_color);
3857
3858 /* Set tip_frame here, so that */
3859 tip_frame = frame;
3860 call1 (Qface_set_after_frame_default, frame);
3861
3862 if (!EQ (bg, Fframe_parameter (frame, Qbackground_color)))
3863 Fmodify_frame_parameters (frame, Fcons (Fcons (Qbackground_color, bg),
3864 Qnil));
3865 }
3866
3825 f->no_split = 1; 3867 f->no_split = 1;
3826 3868
3827 UNGCPRO; 3869 UNGCPRO;
@@ -3833,17 +3875,80 @@ x_create_tip_frame (dpyinfo, parms)
3833 3875
3834 /* Now that the frame is official, it counts as a reference to 3876 /* Now that the frame is official, it counts as a reference to
3835 its display. */ 3877 its display. */
3836 FRAME_W32_DISPLAY_INFO (f)->reference_count++; 3878 FRAME_MAC_DISPLAY_INFO (f)->reference_count++;
3879
3880 /* Setting attributes of faces of the tooltip frame from resources
3881 and similar will increment face_change_count, which leads to the
3882 clearing of all current matrices. Since this isn't necessary
3883 here, avoid it by resetting face_change_count to the value it
3884 had before we created the tip frame. */
3885 face_change_count = face_change_count_before;
3837 3886
3887 /* Discard the unwind_protect. */
3838 return unbind_to (count, frame); 3888 return unbind_to (count, frame);
3839#endif /* MAC_TODO */ 3889}
3840 return Qnil; 3890
3891
3892/* Compute where to display tip frame F. PARMS is the list of frame
3893 parameters for F. DX and DY are specified offsets from the current
3894 location of the mouse. WIDTH and HEIGHT are the width and height
3895 of the tooltip. Return coordinates relative to the root window of
3896 the display in *ROOT_X, and *ROOT_Y. */
3897
3898static void
3899compute_tip_xy (f, parms, dx, dy, width, height, root_x, root_y)
3900 struct frame *f;
3901 Lisp_Object parms, dx, dy;
3902 int width, height;
3903 int *root_x, *root_y;
3904{
3905 Lisp_Object left, top;
3906
3907 /* User-specified position? */
3908 left = Fcdr (Fassq (Qleft, parms));
3909 top = Fcdr (Fassq (Qtop, parms));
3910
3911 /* Move the tooltip window where the mouse pointer is. Resize and
3912 show it. */
3913 if (!INTEGERP (left) || !INTEGERP (top))
3914 {
3915 Point mouse_pos;
3916
3917 BLOCK_INPUT;
3918 GetMouse (&mouse_pos);
3919 LocalToGlobal (&mouse_pos);
3920 *root_x = mouse_pos.h;
3921 *root_y = mouse_pos.v;
3922 UNBLOCK_INPUT;
3923 }
3924
3925 if (INTEGERP (top))
3926 *root_y = XINT (top);
3927 else if (*root_y + XINT (dy) - height < 0)
3928 *root_y -= XINT (dy);
3929 else
3930 {
3931 *root_y -= height;
3932 *root_y += XINT (dy);
3933 }
3934
3935 if (INTEGERP (left))
3936 *root_x = XINT (left);
3937 else if (*root_x + XINT (dx) + width <= FRAME_MAC_DISPLAY_INFO (f)->width)
3938 /* It fits to the right of the pointer. */
3939 *root_x += XINT (dx);
3940 else if (width + XINT (dx) <= *root_x)
3941 /* It fits to the left of the pointer. */
3942 *root_x -= width + XINT (dx);
3943 else
3944 /* Put it left-justified on the screen -- it ought to fit that way. */
3945 *root_x = 0;
3841} 3946}
3842 3947
3843 3948
3844DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0, 3949DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
3845 doc : /* Show STRING in a "tooltip" window on frame FRAME. 3950 doc: /* Show STRING in a "tooltip" window on frame FRAME.
3846A tooltip window is a small window displaying a string. 3951A tooltip window is a small X window displaying a string.
3847 3952
3848FRAME nil or omitted means use the selected frame. 3953FRAME nil or omitted means use the selected frame.
3849 3954
@@ -3859,19 +3964,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 3964DX isn't specified). Likewise for the y-position; if a `top' frame
3860parameter is specified, it determines the y-position of the tooltip 3965parameter is specified, it determines the y-position of the tooltip
3861window, otherwise it is displayed at the mouse position, with offset 3966window, otherwise it is displayed at the mouse position, with offset
3862DY added (default is 10). */) 3967DY added (default is -10).
3863 (string, frame, parms, timeout, dx, dy) 3968
3969A tooltip's maximum size is specified by `x-max-tooltip-size'.
3970Text larger than the specified size is clipped. */)
3971 (string, frame, parms, timeout, dx, dy)
3864 Lisp_Object string, frame, parms, timeout, dx, dy; 3972 Lisp_Object string, frame, parms, timeout, dx, dy;
3865{ 3973{
3866 struct frame *f; 3974 struct frame *f;
3867 struct window *w; 3975 struct window *w;
3868 Window root, child; 3976 int root_x, root_y;
3869 Lisp_Object buffer, top, left;
3870 struct buffer *old_buffer; 3977 struct buffer *old_buffer;
3871 struct text_pos pos; 3978 struct text_pos pos;
3872 int i, width, height; 3979 int i, width, height;
3873 int root_x, root_y, win_x, win_y;
3874 unsigned pmask;
3875 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 3980 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
3876 int old_windows_or_buffers_changed = windows_or_buffers_changed; 3981 int old_windows_or_buffers_changed = windows_or_buffers_changed;
3877 int count = SPECPDL_INDEX (); 3982 int count = SPECPDL_INDEX ();
@@ -3920,13 +4025,11 @@ DY added (default is 10). */)
3920 call1 (Qcancel_timer, timer); 4025 call1 (Qcancel_timer, timer);
3921 } 4026 }
3922 4027
3923#if 0 /* MAC_TODO : Mac specifics */
3924 BLOCK_INPUT; 4028 BLOCK_INPUT;
3925 compute_tip_xy (f, parms, dx, dy, &root_x, &root_y); 4029 compute_tip_xy (f, parms, dx, dy, FRAME_PIXEL_WIDTH (f),
3926 XMoveWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 4030 FRAME_PIXEL_HEIGHT (f), &root_x, &root_y);
3927 root_x, root_y - FRAME_PIXEL_HEIGHT (f)); 4031 MoveWindow (FRAME_MAC_WINDOW (f), root_x, root_y, false);
3928 UNBLOCK_INPUT; 4032 UNBLOCK_INPUT;
3929#endif /* MAC_TODO */
3930 goto start_timer; 4033 goto start_timer;
3931 } 4034 }
3932 } 4035 }
@@ -3953,26 +4056,36 @@ DY added (default is 10). */)
3953 4056
3954 /* Create a frame for the tooltip, and record it in the global 4057 /* Create a frame for the tooltip, and record it in the global
3955 variable tip_frame. */ 4058 variable tip_frame. */
3956 frame = x_create_tip_frame (FRAME_MAC_DISPLAY_INFO (f), parms); 4059 frame = x_create_tip_frame (FRAME_MAC_DISPLAY_INFO (f), parms, string);
3957 f = XFRAME (frame); 4060 f = XFRAME (frame);
3958 4061
3959 /* Set up the frame's root window. Currently we use a size of 80 4062 /* 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)); 4063 w = XWINDOW (FRAME_ROOT_WINDOW (f));
3963 w->left_col = w->top_line = make_number (0); 4064 w->left_col = w->top_line = make_number (0);
3964 w->total_cols = make_number (80); 4065
3965 w->total_lines = make_number (40); 4066 if (CONSP (Vx_max_tooltip_size)
4067 && INTEGERP (XCAR (Vx_max_tooltip_size))
4068 && XINT (XCAR (Vx_max_tooltip_size)) > 0
4069 && INTEGERP (XCDR (Vx_max_tooltip_size))
4070 && XINT (XCDR (Vx_max_tooltip_size)) > 0)
4071 {
4072 w->total_cols = XCAR (Vx_max_tooltip_size);
4073 w->total_lines = XCDR (Vx_max_tooltip_size);
4074 }
4075 else
4076 {
4077 w->total_cols = make_number (80);
4078 w->total_lines = make_number (40);
4079 }
4080
4081 FRAME_TOTAL_COLS (f) = XINT (w->total_cols);
3966 adjust_glyphs (f); 4082 adjust_glyphs (f);
3967 w->pseudo_window_p = 1; 4083 w->pseudo_window_p = 1;
3968 4084
3969 /* Display the tooltip text in a temporary buffer. */ 4085 /* 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; 4086 old_buffer = current_buffer;
3973 set_buffer_internal_1 (XBUFFER (buffer)); 4087 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f))->buffer));
3974 Ferase_buffer (); 4088 current_buffer->truncate_lines = Qnil;
3975 Finsert (1, &string);
3976 clear_glyph_matrix (w->desired_matrix); 4089 clear_glyph_matrix (w->desired_matrix);
3977 clear_glyph_matrix (w->current_matrix); 4090 clear_glyph_matrix (w->current_matrix);
3978 SET_TEXT_POS (pos, BEGV, BEGV_BYTE); 4091 SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
@@ -3993,7 +4106,7 @@ DY added (default is 10). */)
3993 /* Let the row go over the full width of the frame. */ 4106 /* Let the row go over the full width of the frame. */
3994 row->full_width_p = 1; 4107 row->full_width_p = 1;
3995 4108
3996 /* There's a glyph at the end of rows that is use to place 4109 /* 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. */ 4110 the cursor there. Don't include the width of this glyph. */
3998 if (row->used[TEXT_AREA]) 4111 if (row->used[TEXT_AREA])
3999 { 4112 {
@@ -4014,17 +4127,13 @@ DY added (default is 10). */)
4014 4127
4015 /* Move the tooltip window where the mouse pointer is. Resize and 4128 /* Move the tooltip window where the mouse pointer is. Resize and
4016 show it. */ 4129 show it. */
4017#if 0 /* TODO : Mac specifics */ 4130 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 4131
4020 BLOCK_INPUT; 4132 BLOCK_INPUT;
4021 XQueryPointer (FRAME_W32_DISPLAY (f), FRAME_W32_DISPLAY_INFO (f)->root_window, 4133 MoveWindow (FRAME_MAC_WINDOW (f), root_x, root_y, false);
4022 &root, &child, &root_x, &root_y, &win_x, &win_y, &pmask); 4134 SizeWindow (FRAME_MAC_WINDOW (f), width, height, true);
4023 XMoveResizeWindow (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), 4135 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; 4136 UNBLOCK_INPUT;
4027#endif /* MAC_TODO */
4028 4137
4029 /* Draw into the window. */ 4138 /* Draw into the window. */
4030 w->must_be_updated_p = 1; 4139 w->must_be_updated_p = 1;
@@ -4046,8 +4155,8 @@ DY added (default is 10). */)
4046 4155
4047DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0, 4156DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
4048 doc: /* Hide the current tooltip window, if there is any. 4157 doc: /* Hide the current tooltip window, if there is any.
4049Value is t is tooltip was open, nil otherwise. */) 4158Value is t if tooltip was open, nil otherwise. */)
4050 () 4159 ()
4051{ 4160{
4052 int count; 4161 int count;
4053 Lisp_Object deleted, frame, timer; 4162 Lisp_Object deleted, frame, timer;
@@ -4249,7 +4358,8 @@ syms_of_macfns ()
4249 staticpro (&Qsuppress_icon); 4358 staticpro (&Qsuppress_icon);
4250 Qundefined_color = intern ("undefined-color"); 4359 Qundefined_color = intern ("undefined-color");
4251 staticpro (&Qundefined_color); 4360 staticpro (&Qundefined_color);
4252 /* This is the end of symbol initialization. */ 4361 Qcancel_timer = intern ("cancel-timer");
4362 staticpro (&Qcancel_timer);
4253 4363
4254 Qhyper = intern ("hyper"); 4364 Qhyper = intern ("hyper");
4255 staticpro (&Qhyper); 4365 staticpro (&Qhyper);
@@ -4265,6 +4375,7 @@ syms_of_macfns ()
4265 staticpro (&Qcontrol); 4375 staticpro (&Qcontrol);
4266 Qshift = intern ("shift"); 4376 Qshift = intern ("shift");
4267 staticpro (&Qshift); 4377 staticpro (&Qshift);
4378 /* This is the end of symbol initialization. */
4268 4379
4269 /* Text property `display' should be nonsticky by default. */ 4380 /* Text property `display' should be nonsticky by default. */
4270 Vtext_property_default_nonsticky 4381 Vtext_property_default_nonsticky
@@ -4314,6 +4425,11 @@ or when you set the mouse color. */);
4314 doc: /* A string indicating the foreground color of the cursor box. */); 4425 doc: /* A string indicating the foreground color of the cursor box. */);
4315 Vx_cursor_fore_pixel = Qnil; 4426 Vx_cursor_fore_pixel = Qnil;
4316 4427
4428 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size,
4429 doc: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS).
4430Text larger than this is clipped. */);
4431 Vx_max_tooltip_size = Fcons (make_number (80), make_number (40));
4432
4317 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager, 4433 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager,
4318 doc: /* Non-nil if no window manager is in use. 4434 doc: /* Non-nil if no window manager is in use.
4319Emacs doesn't try to figure this out; this is always nil 4435Emacs doesn't try to figure this out; this is always nil
@@ -4386,6 +4502,9 @@ Chinese, Japanese, and Korean. */);
4386 tip_frame = Qnil; 4502 tip_frame = Qnil;
4387 staticpro (&tip_frame); 4503 staticpro (&tip_frame);
4388 4504
4505 last_show_tip_args = Qnil;
4506 staticpro (&last_show_tip_args);
4507
4389#if 0 /* MAC_TODO */ 4508#if 0 /* MAC_TODO */
4390 defsubr (&Sx_file_dialog); 4509 defsubr (&Sx_file_dialog);
4391#endif 4510#endif