Blame gtk/gtkvscale.c

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