// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#ifndef WSCROLLBAR_H_
#define WSCROLLBAR_H_

#include <Wt/WWidget>

namespace Wt {

class WScrollArea;
class DomElement;

/*! \class WScrollBar Wt/WScrollBar Wt/WScrollBar
 *  \brief A scrollbar attached to a scroll area.
 *
 * A WScrollArea always has two scrollbars (even if they are not visible,
 * for example when the policy is WScrollArea::ScrollBarAlwaysOff). Using the
 * tie(WScrollBar *one, WScrollBar *two) functions, it is possible to tie two
 * scrollbars together, so that they will scroll together.
 *
 * \sa WScrollArea
 */
class WT_API WScrollBar : public WObject
{
public:
  /*! \brief Returns the orientation of this scrollbar.
   */
  Orientation orientation() const { return orientation_; }

  /*! \brief Ties two scrollbars together.
   *
   * The effect of this call is that these scrollbars will keep their
   * positions synchronised.
   */
  static void tie(WScrollBar *one, WScrollBar *two);

  /*! \brief Unties two scrollbars, that were previously tied together.
   *
   * Undo a tie(WScrollBar *one, WScrollBar *two);
   *
   */
  static void unTie(WScrollBar *one, WScrollBar *two);

  /*! \brief Sets the scrollbar value (in pixels).
   *
   * This will move the scrollbar to the given value.
   */
  void setValue(int value);

private:
  WScrollBar(WScrollArea *area, Orientation orientation);
  ~WScrollBar();

  WScrollArea *scrollArea_;
  Orientation orientation_;

  std::vector<WScrollBar *> ties_;
  bool tiesChanged_;

  int value_;
  bool valueSet_;

  void updateDom(DomElement& element, bool all);

  friend class WScrollArea;
};

}

#endif // WSCROLLBAR_H_
