diff options
author | Havoc Pennington <hp@pobox.com> | 2001-02-17 17:21:21 +0000 |
---|---|---|
committer | Havoc Pennington <hp@src.gnome.org> | 2001-02-17 17:21:21 +0000 |
commit | e90d8357a9d9bedba20ac2b6feb67294fb232e28 (patch) | |
tree | f8e820165a9452afbb68b59e831634a7edd6a641 /gtk | |
parent | ca26902c651c7868c3e9880c0b2864d7ad42554f (diff) | |
download | gtk+-e90d8357a9d9bedba20ac2b6feb67294fb232e28.tar.gz |
fix screwup with shadowed variables that had broken size request in some
2001-02-17 Havoc Pennington <hp@pobox.com>
* gtk/gtklabel.c (gtk_label_ensure_layout): fix screwup with
shadowed variables that had broken size request in some cases,
leading to bogus tooltips (#50996)
2001-02-06 Jon K Hellan <hellan@acm.org>
Implement fast browsing of tooltips, bug #50619
* gtk/gtktooltips.h (struct _GtkTooltips): Add use_sticky_delay
and last_popdown
* gtk/gtktooltips.c (gtk_tooltips_init): Initialize sticky_delay,
use_sticky_delay and last_popdown.
(gtk_tooltips_draw_tips, gtk_tooltips_set_active_widget): Record
time of popdown.
(gtk_tooltips_set_active_widget): Unset sticky behaviour if widget
is NULL.
(gtk_tooltips_recently_shown): New static function. Return true
if < sticky_delay has elapsed since last popdown.
(gtk_tooltips_event_handler): Display window after sticky_delay
(presumably < normal delay) if < STICKY_REVERT_DELAY has elapsed
since last popdown.
2001-02-17 Havoc Pennington <hp@pobox.com>
* gtk/gtktypeutils.h (GtkSignalFunc): change it to take (void)
instead of (). #6394
* gtk/gtkprogressbar.c (gtk_progress_bar_get_text): Add
G_CONST_RETURN, make it return by reference, #50473
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtklabel.c | 22 | ||||
-rw-r--r-- | gtk/gtkprogressbar.c | 13 | ||||
-rw-r--r-- | gtk/gtkprogressbar.h | 6 | ||||
-rw-r--r-- | gtk/gtktooltips.c | 55 | ||||
-rw-r--r-- | gtk/gtktooltips.h | 2 | ||||
-rw-r--r-- | gtk/gtktypeutils.h | 2 |
6 files changed, 77 insertions, 23 deletions
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index bef3322efc..4db79be579 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -525,7 +525,7 @@ gtk_label_ensure_layout (GtkLabel *label, { GtkWidget *widget; PangoRectangle logical_rect; - gint width, height; + gint rwidth, rheight; widget = GTK_WIDGET (label); @@ -550,8 +550,8 @@ gtk_label_ensure_layout (GtkLabel *label, * don't think it's really that slow. */ - width = label->misc.xpad * 2; - height = label->misc.ypad * 2; + rwidth = label->misc.xpad * 2; + rheight = label->misc.ypad * 2; if (!label->layout) { @@ -613,8 +613,8 @@ gtk_label_ensure_layout (GtkLabel *label, pango_layout_set_width (label->layout, aux_info->width * PANGO_SCALE); pango_layout_get_extents (label->layout, NULL, &logical_rect); - width += aux_info->width; - height += PANGO_PIXELS (logical_rect.height); + rwidth += aux_info->width; + rheight += PANGO_PIXELS (logical_rect.height); } else { @@ -681,8 +681,8 @@ gtk_label_ensure_layout (GtkLabel *label, } pango_layout_set_width (label->layout, width); - width += PANGO_PIXELS (real_width); - height += PANGO_PIXELS (height); + rwidth += PANGO_PIXELS (real_width); + rheight += PANGO_PIXELS (height); } } else /* !label->wrap */ @@ -690,15 +690,15 @@ gtk_label_ensure_layout (GtkLabel *label, pango_layout_set_width (label->layout, -1); pango_layout_get_extents (label->layout, NULL, &logical_rect); - width += PANGO_PIXELS (logical_rect.width); - height += PANGO_PIXELS (logical_rect.height); + rwidth += PANGO_PIXELS (logical_rect.width); + rheight += PANGO_PIXELS (logical_rect.height); } if (widthp) - *widthp = width; + *widthp = rwidth; if (heightp) - *heightp = height; + *heightp = rheight; } static void diff --git a/gtk/gtkprogressbar.c b/gtk/gtkprogressbar.c index 5cca5c8a16..3ee7f849cb 100644 --- a/gtk/gtkprogressbar.c +++ b/gtk/gtkprogressbar.c @@ -253,7 +253,7 @@ gtk_progress_bar_get_arg (GtkObject *object, GTK_VALUE_FLOAT (*arg) = pbar->pulse_fraction; break; case ARG_TEXT: - GTK_VALUE_STRING (*arg) = gtk_progress_bar_get_text (pbar); + GTK_VALUE_STRING (*arg) = g_strdup (gtk_progress_bar_get_text (pbar)); break; default: arg->type = GTK_TYPE_INVALID; @@ -939,11 +939,14 @@ gtk_progress_bar_set_orientation (GtkProgressBar *pbar, * gtk_progress_bar_get_text: * @pbar: a #GtkProgressBar * - * Retrieves the text displayed superimposed on the progress bar. + * Retrieves the text displayed superimposed on the progress bar, + * if any, otherwise %NULL. The return value is a reference + * to the text, not a copy of it, so will become invalid + * if you change the text in the progress bar. * - * Return value: a string which must be freed, or %NULL + * Return value: text, or %NULL; don't free the string **/ -gchar* +G_CONST_RETURN gchar* gtk_progress_bar_get_text (GtkProgressBar *pbar) { g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), NULL); @@ -951,7 +954,7 @@ gtk_progress_bar_get_text (GtkProgressBar *pbar) if (GTK_PROGRESS (pbar)->use_text_format) return NULL; else - return g_strdup (GTK_PROGRESS (pbar)->format); + return GTK_PROGRESS (pbar)->format; } /** diff --git a/gtk/gtkprogressbar.h b/gtk/gtkprogressbar.h index b4252960e3..266c5049ac 100644 --- a/gtk/gtkprogressbar.h +++ b/gtk/gtkprogressbar.h @@ -128,9 +128,9 @@ void gtk_progress_bar_set_pulse_step (GtkProgressBar *pbar, void gtk_progress_bar_set_orientation (GtkProgressBar *pbar, GtkProgressBarOrientation orientation); -gchar* gtk_progress_bar_get_text (GtkProgressBar *pbar); -gfloat gtk_progress_bar_get_fraction (GtkProgressBar *pbar); -gfloat gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar); +G_CONST_RETURN gchar* gtk_progress_bar_get_text (GtkProgressBar *pbar); +gfloat gtk_progress_bar_get_fraction (GtkProgressBar *pbar); +gfloat gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar); GtkProgressBarOrientation gtk_progress_bar_get_orientation (GtkProgressBar *pbar); diff --git a/gtk/gtktooltips.c b/gtk/gtktooltips.c index 5de565ada5..faf7254340 100644 --- a/gtk/gtktooltips.c +++ b/gtk/gtktooltips.c @@ -38,6 +38,12 @@ #define DEFAULT_DELAY 500 /* Default delay in ms */ +#define STICKY_DELAY 0 /* Delay before popping up next tip + * if we're sticky + */ +#define STICKY_REVERT_DELAY 1000 /* Delay before sticky tooltips revert + * to normal + */ static void gtk_tooltips_class_init (GtkTooltipsClass *klass); static void gtk_tooltips_init (GtkTooltips *tooltips); @@ -105,6 +111,9 @@ gtk_tooltips_init (GtkTooltips *tooltips) tooltips->delay = DEFAULT_DELAY; tooltips->enabled = TRUE; tooltips->timer_tag = 0; + tooltips->use_sticky_delay = FALSE; + tooltips->last_popdown.tv_sec = -1; + tooltips->last_popdown.tv_usec = -1; } GtkTooltips * @@ -310,7 +319,10 @@ gtk_tooltips_draw_tips (GtkTooltips * tooltips) 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 (&tooltips->last_popdown); + } gtk_widget_ensure_style (tooltips->tip_window); style = tooltips->tip_window->style; @@ -369,7 +381,11 @@ gtk_tooltips_set_active_widget (GtkTooltips *tooltips, GtkWidget *widget) { if (tooltips->tip_window) - gtk_widget_hide (tooltips->tip_window); + { + if (GTK_WIDGET_VISIBLE (tooltips->tip_window)) + g_get_current_time (&tooltips->last_popdown); + gtk_widget_hide (tooltips->tip_window); + } if (tooltips->timer_tag) { gtk_timeout_remove (tooltips->timer_tag); @@ -396,6 +412,22 @@ gtk_tooltips_set_active_widget (GtkTooltips *tooltips, } } } + else + { + tooltips->use_sticky_delay = FALSE; + } +} + +static gboolean +gtk_tooltips_recently_shown (GtkTooltips *tooltips) +{ + GTimeVal now; + glong msec; + + g_get_current_time (&now); + msec = (now.tv_sec - tooltips->last_popdown.tv_sec) * 1000 + + (now.tv_usec - tooltips->last_popdown.tv_usec) / 1000; + return (msec < STICKY_REVERT_DELAY); } static gint @@ -429,14 +461,31 @@ gtk_tooltips_event_handler (GtkWidget *widget, if (tooltips->enabled && (!old_tips_data || old_tips_data->widget != widget)) { + guint delay; + gtk_tooltips_set_active_widget (tooltips, widget); - tooltips->timer_tag = gtk_timeout_add (tooltips->delay, + if (tooltips->use_sticky_delay && + gtk_tooltips_recently_shown (tooltips)) + delay = STICKY_DELAY; + else + delay = tooltips->delay; + tooltips->timer_tag = gtk_timeout_add (delay, gtk_tooltips_timeout, (gpointer) tooltips); } break; + case GDK_LEAVE_NOTIFY: + { + gboolean use_sticky_delay; + + use_sticky_delay = tooltips->tip_window && + GTK_WIDGET_VISIBLE (tooltips->tip_window); + gtk_tooltips_set_active_widget (tooltips, NULL); + tooltips->use_sticky_delay = use_sticky_delay; + } + break; default: gtk_tooltips_set_active_widget (tooltips, NULL); break; diff --git a/gtk/gtktooltips.h b/gtk/gtktooltips.h index 0b9f62a4f9..12adf631d5 100644 --- a/gtk/gtktooltips.h +++ b/gtk/gtktooltips.h @@ -68,6 +68,8 @@ struct _GtkTooltips guint delay : 30; guint enabled : 1; gint timer_tag; + gboolean use_sticky_delay; + GTimeVal last_popdown; }; struct _GtkTooltipsClass diff --git a/gtk/gtktypeutils.h b/gtk/gtktypeutils.h index 38ee2ef47d..d8d6b9c42b 100644 --- a/gtk/gtktypeutils.h +++ b/gtk/gtktypeutils.h @@ -121,7 +121,7 @@ typedef void (*GtkCallbackMarshal) (GtkObject *object, gpointer data, guint n_args, GtkArg *args); -typedef void (*GtkSignalFunc) (); +typedef void (*GtkSignalFunc) (void); typedef GSignalCMarshaller GtkSignalMarshaller; #define GTK_SIGNAL_FUNC(f) ((GtkSignalFunc) (f)) |