diff src/xfns.c @ 109604:43eca6c9f493

Use Gtk+ tooltips by default for Gtk+ Emacs. * lisp/cus-start.el (x-gtk-use-system-tooltips): New variable. * src/gtkutil.c (hierarchy_ch_cb, qttip_cb, xg_prepare_tooltip) (xg_show_tooltip, xg_hide_tooltip, xg_free_frame_widgets): New functions. (xg_create_frame_widgets): Set ttip_* to 0. Set a dummy tooltip text so qttip_cb is called. Connect query-tooltip to qttip_cb. Remove code that is commented out. * src/gtkutil.h (xg_free_frame_widgets, xg_prepare_tooltip) (xg_show_tooltip, xg_hide_tooltip): Declare. * src/xfns.c (x_gtk_use_system_tooltips): New variable. (Fx_show_tip): If USE_GTK and x_gtk_use_system_tooltips, call new gtkutil tooltip functions to show the tooltip. (Fx_hide_tip): Call xg_hide_tooltip. (syms_of_xfns): Defvar x-gtk-use-system-tooltips. * src/xterm.c (x_clear_frame): Check FRAME_GTK_WIDGET (f) before calling gtk_widget_queue_draw. (x_free_frame_resources): Call xg_free_frame_widgets. * src/xterm.h (struct x_output): Add ttip_widget, ttip_window and ttip_lbl.
author Jan D <jan.h.d@swipnet.se>
date Sun, 01 Aug 2010 15:57:07 +0200
parents 09fcb3817c1e
children c4c8e4a16194
line wrap: on
line diff
--- a/src/xfns.c	Sun Aug 01 06:37:41 2010 +0200
+++ b/src/xfns.c	Sun Aug 01 15:57:07 2010 +0200
@@ -161,6 +161,10 @@
 
 int x_gtk_whole_detached_tool_bar;
 
+/* If non-zero, use Gtk+ tooltips.  */
+
+static int x_gtk_use_system_tooltips;
+
 /* The background and shape of the mouse pointer, and shape when not
    over text or in the modeline.  */
 
@@ -4610,7 +4614,9 @@
    when this happens.  */
 
 static Lisp_Object
-x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms, Lisp_Object text)
+x_create_tip_frame (struct x_display_info *dpyinfo,
+                    Lisp_Object parms,
+                    Lisp_Object text)
 {
   struct frame *f;
   Lisp_Object frame, tem;
@@ -5037,6 +5043,27 @@
   else
     CHECK_NUMBER (dy);
 
+#ifdef USE_GTK
+  if (x_gtk_use_system_tooltips)
+    {
+      int ok; 
+
+      /* Hide a previous tip, if any.  */
+      Fx_hide_tip ();
+
+      BLOCK_INPUT;
+      if ((ok = xg_prepare_tooltip (f, string, &width, &height)) != 0)
+        {
+	  compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
+          xg_show_tooltip (f, root_x, root_y);
+          /* This is used in Fx_hide_tip.  */
+          XSETFRAME (tip_frame, f);
+        }
+      UNBLOCK_INPUT;
+      if (ok) goto start_timer;
+    }
+#endif /* USE_GTK */
+
   if (NILP (last_show_tip_args))
     last_show_tip_args = Fmake_vector (make_number (3), Qnil);
 
@@ -5197,6 +5224,7 @@
   int count;
   Lisp_Object deleted, frame, timer;
   struct gcpro gcpro1, gcpro2;
+  struct frame *f;
 
   /* Return quickly if nothing to do.  */
   if (NILP (tip_timer) && NILP (tip_frame))
@@ -5214,6 +5242,14 @@
   if (!NILP (timer))
     call1 (Qcancel_timer, timer);
 
+#ifdef USE_GTK
+  /* When using system tooltip, tip_frame is the Emacs frame on which
+     the tip is shown.  */
+  f = XFRAME (frame);
+  if (xg_hide_tooltip (f))
+    frame = Qnil;
+#endif
+
   if (FRAMEP (frame))
     {
       delete_frame (frame, Qnil);
@@ -5224,8 +5260,9 @@
 	 redisplay procedure is not called when a tip frame over menu
 	 items is unmapped.  Redisplay the menu manually...  */
       {
-	struct frame *f = SELECTED_FRAME ();
-	Widget w = f->output_data.x->menubar_widget;
+        Widget w;
+	f = SELECTED_FRAME ();
+	w = f->output_data.x->menubar_widget;
 
 	if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f)->screen)
 	    && w != NULL)
@@ -5894,6 +5931,12 @@
 the tool bar buttons.  */);
   x_gtk_whole_detached_tool_bar = 0;
 
+  DEFVAR_BOOL ("x-gtk-use-system-tooltips", &x_gtk_use_system_tooltips,
+    doc: /* *If non-nil with a Gtk+ built Emacs, the Gtk+ toolip is used.
+Otherwise use Emacs own tooltip implementation.
+When using Gtk+ tooltips, the tooltip face is not used.  */);
+  x_gtk_use_system_tooltips = 1;
+
   Fprovide (intern_c_string ("x"), Qnil);
 
 #ifdef USE_X_TOOLKIT