Blame gtk/gtkhscale.c

Packit 98cdb6
/* GTK - The GIMP Toolkit
Packit 98cdb6
 * Copyright (C) 2001 Red Hat, Inc.
Packit 98cdb6
 *
Packit 98cdb6
 * This library is free software; you can redistribute it and/or
Packit 98cdb6
 * modify it under the terms of the GNU Lesser General Public
Packit 98cdb6
 * License as published by the Free Software Foundation; either
Packit 98cdb6
 * version 2 of the License, or (at your option) any later version.
Packit 98cdb6
 *
Packit 98cdb6
 * This library is distributed in the hope that it will be useful,
Packit 98cdb6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 98cdb6
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 98cdb6
 * Lesser General Public License for more details.
Packit 98cdb6
 *
Packit 98cdb6
 * You should have received a copy of the GNU Lesser General Public
Packit 98cdb6
 * License along with this library; if not, write to the
Packit 98cdb6
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 98cdb6
 * Boston, MA 02111-1307, USA.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
/*
Packit 98cdb6
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
Packit 98cdb6
 * file for a list of people on the GTK+ Team.  See the ChangeLog
Packit 98cdb6
 * files for a list of changes.  These files are distributed with
Packit 98cdb6
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
#include "config.h"
Packit 98cdb6
Packit 98cdb6
#include <math.h>
Packit 98cdb6
#include <stdlib.h>
Packit 98cdb6
Packit 98cdb6
#include "gtkhscale.h"
Packit 98cdb6
#include "gtkorientable.h"
Packit 98cdb6
#include "gtkalias.h"
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
G_DEFINE_TYPE (GtkHScale, gtk_hscale, GTK_TYPE_SCALE)
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_hscale_class_init (GtkHScaleClass *class)
Packit 98cdb6
{
Packit 98cdb6
  GtkRangeClass *range_class = GTK_RANGE_CLASS (class);
Packit 98cdb6
Packit 98cdb6
  range_class->slider_detail = "hscale";
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_hscale_init (GtkHScale *hscale)
Packit 98cdb6
{
Packit 98cdb6
  gtk_orientable_set_orientation (GTK_ORIENTABLE (hscale),
Packit 98cdb6
                                  GTK_ORIENTATION_HORIZONTAL);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
GtkWidget *
Packit 98cdb6
gtk_hscale_new (GtkAdjustment *adjustment)
Packit 98cdb6
{
Packit 98cdb6
  g_return_val_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment),
Packit 98cdb6
                        NULL);
Packit 98cdb6
Packit 98cdb6
  return g_object_new (GTK_TYPE_HSCALE,
Packit 98cdb6
                       "adjustment", adjustment,
Packit 98cdb6
                       NULL);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_hscale_new_with_range:
Packit 98cdb6
 * @min: minimum value
Packit 98cdb6
 * @max: maximum value
Packit 98cdb6
 * @step: step increment (tick size) used with keyboard shortcuts
Packit 98cdb6
 *
Packit 98cdb6
 * Creates a new horizontal scale widget that lets the user input a
Packit 98cdb6
 * number between @min and @max (including @min and @max) with the
Packit 98cdb6
 * increment @step.  @step must be nonzero; it's the distance the
Packit 98cdb6
 * slider moves when using the arrow keys to adjust the scale value.
Packit 98cdb6
 *
Packit 98cdb6
 * Note that the way in which the precision is derived works best if @step
Packit 98cdb6
 * is a power of ten. If the resulting precision is not suitable for your
Packit 98cdb6
 * needs, use gtk_scale_set_digits() to correct it.
Packit 98cdb6
 *
Packit 98cdb6
 * Return value: a new #GtkHScale
Packit 98cdb6
 **/
Packit 98cdb6
GtkWidget *
Packit 98cdb6
gtk_hscale_new_with_range (gdouble min,
Packit 98cdb6
                           gdouble max,
Packit 98cdb6
                           gdouble step)
Packit 98cdb6
{
Packit 98cdb6
  GtkObject *adj;
Packit 98cdb6
  GtkScale *scale;
Packit 98cdb6
  gint digits;
Packit 98cdb6
Packit 98cdb6
  g_return_val_if_fail (min < max, NULL);
Packit 98cdb6
  g_return_val_if_fail (step != 0.0, NULL);
Packit 98cdb6
Packit 98cdb6
  adj = gtk_adjustment_new (min, min, max, step, 10 * step, 0);
Packit 98cdb6
Packit 98cdb6
  if (fabs (step) >= 1.0 || step == 0.0)
Packit 98cdb6
    {
Packit 98cdb6
      digits = 0;
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    {
Packit 98cdb6
      digits = abs ((gint) floor (log10 (fabs (step))));
Packit 98cdb6
      if (digits > 5)
Packit 98cdb6
        digits = 5;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  scale = g_object_new (GTK_TYPE_HSCALE,
Packit 98cdb6
                        "adjustment", adj,
Packit 98cdb6
                        "digits", digits,
Packit 98cdb6
                        NULL);
Packit 98cdb6
Packit 98cdb6
  return GTK_WIDGET (scale);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
#define __GTK_HSCALE_C__
Packit 98cdb6
#include "gtkaliasdef.c"