Re: Tooltips



famrom@idecnet.com (Guillermo S. Romero / Familia Romero) writes:

> >Anybody want this? Hate this?
> 
> I have not tested it, btu it sound good, cos whe I want to know what a row
> of buttons do, it is a pain to wait for each one.
> 
> If you could provide the demo thing so all can test it, I think we could
> give our opinion based in facts (maybe others found apps that do that, but I
> did not).

You can try the patch below against gtk+ 1.2.7. You only have to
compile gtktooltips.o: cc -c gtktooltips.c `gtk-config --libs`

Then build e.g. gnumeric with the new gtktooltips. For gnumeric, you
edit src/Makefile, and add <your path to gtk>/gtktooltips.o to the
huge list of files beginning with "gnumeric_OBJECTS =". Don't forget
that all the lines but the last in the list need a backslash at the
end.

Jon Kåre


--- old/gtk/gtktooltips.c
+++ new/gtk/gtktooltips.c
@@ -58,6 +58,9 @@
 static GtkDataClass *parent_class;
 static const gchar  *tooltips_data_key = "_GtkTooltipsData";
 
+/* FIXME: Make this a class variable if people like the feature */
+static GTimeVal last_popdown = { -1, -1 };
+
 GtkType
 gtk_tooltips_get_type (void)
 {
@@ -472,7 +475,10 @@
   if (!tooltips->tip_window)
     gtk_tooltips_force_window (tooltips);
   else if (GTK_WIDGET_VISIBLE (tooltips->tip_window))
-    gtk_widget_hide (tooltips->tip_window);
+    {
+      gtk_widget_hide (tooltips->tip_window);
+      g_get_current_time (&last_popdown);
+    }
 
   gtk_widget_ensure_style (tooltips->tip_window);
   style = tooltips->tip_window->style;
@@ -544,7 +550,11 @@
                                 GtkWidget   *widget)
 {
   if (tooltips->tip_window)
-    gtk_widget_hide (tooltips->tip_window);
+    {
+      if (GTK_WIDGET_VISIBLE (tooltips->tip_window))
+	g_get_current_time (&last_popdown);
+      gtk_widget_hide (tooltips->tip_window);
+    }
   if (tooltips->timer_tag)
     {
       gtk_timeout_remove (tooltips->timer_tag);
@@ -574,6 +584,23 @@
 }
 
 static gint
+gtk_tooltips_recently_shown (GtkTooltips *tooltips)
+{
+	GTimeVal now;
+	glong msec;
+
+	g_get_current_time (&now);
+	msec = (now.tv_sec  - last_popdown.tv_sec) * 1000 +
+		(now.tv_usec - last_popdown.tv_usec) / 1000;
+
+/*  	g_message ("%s\t%s: %ld\t%s: %d", __PRETTY_FUNCTION__, */
+/*  		   "msec", msec, */
+/*  		   "(msec <= tooltips->delay)", (msec <= tooltips->delay)); */
+	return (msec <= tooltips->delay);
+	
+}
+
+static gint
 gtk_tooltips_event_handler (GtkWidget *widget,
                             GdkEvent  *event)
 {
@@ -606,9 +633,12 @@
 	{
 	  gtk_tooltips_set_active_widget (tooltips, widget);
 	  
-	  tooltips->timer_tag = gtk_timeout_add (tooltips->delay,
-						 gtk_tooltips_timeout,
-						 (gpointer) tooltips);
+	  if (gtk_tooltips_recently_shown (tooltips))
+	    gtk_tooltips_timeout ((gpointer) tooltips);
+	  else
+  	    tooltips->timer_tag = gtk_timeout_add (tooltips->delay,
+						   gtk_tooltips_timeout,
+						   (gpointer) tooltips);
 	}
       break;
 






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]