// -*- c++ -*-
/* $Id: scale.ccg,v 1.2 2004/01/19 19:48:44 murrayc Exp $ */

/* 
 *
 * Copyright 1998-2002 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <gtkmm/adjustment.h>

#include <gtk/gtkscale.h>
#include <gtk/gtkhscale.h>
#include <gtk/gtkvscale.h>
#include <math.h>

namespace Gtk
{

int Scale::calc_digits_(double step) const
{
  int digits = 0;

  //Copied from gtk_[h|v]scale_new_with_range():
  if (fabs (step) >= 1.0 || step == 0.0)
     digits = 0;
  else {
    digits = abs ((int) floor (log10 (fabs (step))));
    if (digits > 5)
      digits = 5;
  }

  return digits;
}

VScale::VScale(double min, double max, double step)
:
  _CONSTRUCT_SPECIFIC(Scale, VScale)
{
  Adjustment* adjustment = manage(new Adjustment(min, min, max, step, 10 * step, step));
  // The adjustment will be destroyed along with the object
  set_adjustment(*adjustment);

  set_digits( calc_digits_(step) );
}

VScale::VScale(Adjustment& adjustment)
:
  _CONSTRUCT_SPECIFIC(Scale, VScale)
{
  set_adjustment(adjustment);
}

VScale::VScale()
:
  _CONSTRUCT_SPECIFIC(Scale, VScale)
{
  Adjustment* adjustment = manage(new Adjustment(0.0, 0.0, 0.0,
						  0.0, 0.0, 0.0));
  // The adjustment will be destroyed along with the object
  set_adjustment(*adjustment);
}


HScale::HScale(double min, double max, double step)
:
  _CONSTRUCT_SPECIFIC(Scale, HScale)
{
  Adjustment* adjustment = manage(new Adjustment(min, min, max, step, 10 * step, step));
  // The adjustment will be destroyed along with the object
  set_adjustment(*adjustment);

  set_digits( calc_digits_(step) );
}

HScale::HScale()
:
  _CONSTRUCT_SPECIFIC(Scale, HScale)
{
  Adjustment* adjustment = manage(new Adjustment(0.0, 0.0, 0.0,
						  0.0, 0.0, 0.0));
  // The adjustment will be destroyed along with the object
  set_adjustment(*adjustment);
}

HScale::HScale(Adjustment& adjustment)
:
  _CONSTRUCT_SPECIFIC(Scale, HScale)
{
  set_adjustment(adjustment);
}

} // namespace Gtk

