diff options
author | Havoc Pennington <hp@redhat.com> | 2001-05-07 15:58:47 +0000 |
---|---|---|
committer | Havoc Pennington <hp@src.gnome.org> | 2001-05-07 15:58:47 +0000 |
commit | b4e4a0ed9d66132efad0539bc5901b35ea262d88 (patch) | |
tree | 7eea37afc0c2f32334112872547373758ac7d6b6 /gtk/gtkscale.c | |
parent | 607ac1e1b31dc21598830a22930bcc39a77cb5c3 (diff) | |
download | gtk+-b4e4a0ed9d66132efad0539bc5901b35ea262d88.tar.gz |
fix some shell typos
2001-05-04 Havoc Pennington <hp@redhat.com>
* configure.in: fix some shell typos
* gtk/gtkcolorsel.c (gtk_color_selection_destroy): warning fix
* gtk/gtkimage.c: handle animations
* gtk/gtkcheckbutton.c (gtk_check_button_size_request): request
border_width * 2, not just border_width
* gtk/gtkscale.c: add "format_value" signal to allow people
to override the way values are drawn.
(gtk_scale_get_value_size): fix width/height mistake,
and compute size from actual displayed text, not
from made-up text.
* gtk/gtktexttag.c (gtk_text_tag_class_init): fix return type in
signal registration
* tests/testtext.c: Add "Remove all tags" menu item for testing
* gtk/gtktextbuffer.c (gtk_text_buffer_remove_all_tags): implement
* demos/gtk-demo/main.c (main): add hack so we can find modules
without installing gtk
* demos/gtk-demo/textview.c (insert_text): demo font scaling
* gtk/gtkcellrenderertext.c: Add "scale" property (font scaling
factor)
(gtk_cell_renderer_text_set_property): remove some bogus
g_object_notify
* gtk/gtktexttag.c: add "scale" property which is a font scaling
factor
* gtk/gtktextlayout.c (add_text_attrs): add font scale attribute
to layout
* gtk/gtktextiter.c (gtk_text_iter_is_start): rename from
gtk_text_iter_is_first
2001-05-04 Havoc Pennington <hp@redhat.com>
* pixops/pixops.c (pixops_process): merge fix from stable: Patch
from hoshem@mel.comcen.com.au to fix nonzero X offsets. Fixes
bug #50371.
* gdk-pixbuf/pixops/pixops.c (pixops_composite_nearest): merge
from stable: Patch from OKADA Mitsuru <m-okada@fjb.co.jp> to fix
confusion of using "src" instead of "p".
(pixops_composite_color_nearest): Use a more accurate (and
correct, to begin with) compositing method. This cures checks
showing through on images with no alpha.
* gdk-pixbuf.c (gdk_pixbuf_fill): fix bug that left some trailing
bytes unfilled.
* gdk-pixbuf-io.h: fix UpdatedNotifyFunc to use signed ints
* gdk-pixbuf-loader.h (struct _GdkPixbufLoaderClass): Change
area_updated signal to use signed ints. Removed animation-related
signals.
* io-gif.c, io-gif-animation.h, io-gif-animation.c: Massive
rewrite action
* gdk-pixbuf-animation.c: Add GdkPixbufAnimationIter to abstract
all the pesky details. Remove old frame-based API. Make
GdkPixbufAnimation an abstract base class, derived by the loaders.
Diffstat (limited to 'gtk/gtkscale.c')
-rw-r--r-- | gtk/gtkscale.c | 113 |
1 files changed, 72 insertions, 41 deletions
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c index a2769b2851..992cdfe41d 100644 --- a/gtk/gtkscale.c +++ b/gtk/gtkscale.c @@ -27,6 +27,7 @@ #include <math.h> #include "gtkintl.h" #include "gtkscale.h" +#include "gtkmarshal.h" enum { ARG_0, @@ -35,6 +36,12 @@ enum { ARG_VALUE_POS }; +enum { + FORMAT_VALUE, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; static void gtk_scale_class_init (GtkScaleClass *klass); static void gtk_scale_init (GtkScale *scale); @@ -78,6 +85,22 @@ gtk_scale_get_type (void) return scale_type; } +gboolean +single_string_accumulator (GSignalInvocationHint *ihint, + GValue *return_accu, + const GValue *handler_return, + gpointer dummy) +{ + gboolean continue_emission; + gchar *str; + + str = g_value_get_string (handler_return); + g_value_set_string (return_accu, str); + continue_emission = str == NULL; + + return continue_emission; +} + static void gtk_scale_class_init (GtkScaleClass *class) { @@ -104,6 +127,16 @@ gtk_scale_class_init (GtkScaleClass *class) GTK_ARG_READWRITE, ARG_VALUE_POS); + signals[FORMAT_VALUE] = + g_signal_newc ("format_value", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GtkScaleClass, format_value), + single_string_accumulator, NULL, + gtk_marshal_STRING__DOUBLE, + G_TYPE_STRING, 1, + G_TYPE_DOUBLE); + object_class->set_arg = gtk_scale_set_arg; object_class->get_arg = gtk_scale_get_arg; @@ -280,58 +313,27 @@ gtk_scale_get_value_size (GtkScale *scale, { PangoLayout *layout; PangoRectangle logical_rect; - gchar buffer[128]; - gdouble value; - gint digits; - gint i, j; + gchar *txt; range = GTK_RANGE (scale); layout = gtk_widget_create_pango_layout (GTK_WIDGET (scale), NULL); - value = ABS (range->adjustment->lower); - if (value == 0) value = 1; - digits = log10 (value) + 1; - if (digits > 13) - digits = 13; - - i = 0; - if (range->adjustment->lower < 0) - buffer[i++] = '-'; - for (j = 0; j < digits; j++) - buffer[i++] = '0'; - if (GTK_RANGE (scale)->digits) - buffer[i++] = '.'; - for (j = 0; j < GTK_RANGE (scale)->digits; j++) - buffer[i++] = '0'; - buffer[i] = '\0'; - - pango_layout_set_text (layout, buffer, i); + txt = _gtk_scale_format_value (scale, range->adjustment->lower); + pango_layout_set_text (layout, txt, -1); + g_free (txt); + pango_layout_get_pixel_extents (layout, NULL, &logical_rect); if (width) *width = logical_rect.width; if (height) - *height = logical_rect.width; + *height = logical_rect.height; + + txt = _gtk_scale_format_value (scale, range->adjustment->upper); + pango_layout_set_text (layout, txt, -1); + g_free (txt); - value = ABS (range->adjustment->upper); - if (value == 0) value = 1; - digits = log10 (value) + 1; - if (digits > 13) - digits = 13; - - i = 0; - if (range->adjustment->upper < 0) - buffer[i++] = '-'; - for (j = 0; j < digits; j++) - buffer[i++] = '0'; - if (GTK_RANGE (scale)->digits) - buffer[i++] = '.'; - for (j = 0; j < GTK_RANGE (scale)->digits; j++) - buffer[i++] = '0'; - buffer[i] = '\0'; - - pango_layout_set_text (layout, buffer, i); pango_layout_get_pixel_extents (layout, NULL, &logical_rect); if (width) @@ -383,3 +385,32 @@ gtk_scale_draw_background (GtkRange *range) gtk_scale_draw_value (GTK_SCALE (range)); } + +/** + * _gtk_scale_format_value: + * @scale: a #GtkScale + * @value: adjustment value + * + * Emits "format_value" signal to format the value, if no user + * signal handlers, falls back to a default format. + * + * Return value: formatted value + **/ +gchar* +_gtk_scale_format_value (GtkScale *scale, + gdouble value) +{ + gchar *fmt = NULL; + + g_signal_emit (G_OBJECT (scale), + signals[FORMAT_VALUE], + 0, + value, + &fmt); + + if (fmt) + return fmt; + else + return g_strdup_printf ("%0.*f", GTK_RANGE (scale)->digits, + value); +} |