/* 
 * © 2008-2009 Sun Microsystems, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#ifndef _MFORMS_TEXTBOX_H_
#define _MFORMS_TEXTBOX_H_

#include <mforms/base.h>
#include <mforms/control.h>

#include <sigc++/sigc++.h>

namespace mforms {
  enum ScrollBars {
    NoScrollBar= 0,      // Don't show any scroll bar.
    HorizontalScrollBar, // Show only the horizontal scroll bar.
    VerticalScrollBar,   // Show only the vertical scroll bar.
    BothScrollBars       // Show both scroll bars.
  };

  class TextBox;

  struct TextBoxImplPtrs
  {
    bool (__stdcall *create)(TextBox *self, ScrollBars scroll_bars);
    void (__stdcall *set_bordered)(TextBox *self, bool flag);
    void (__stdcall *set_read_only)(TextBox *self, bool flag);
    void (__stdcall *set_text)(TextBox *self, const std::string &text);
    std::string (__stdcall *get_text)(TextBox *self);
    void (__stdcall *append_text)(TextBox *self, const std::string &text);
    void (__stdcall *set_padding)(TextBox *self, int pad);
  };

  class MFORMS_EXPORT TextBox : public Control
  {
  public:
    TextBox(ScrollBars scroll_bars);

    void set_bordered(bool flag);
    void set_read_only(bool flag);
    void set_value(const std::string &text);
    virtual std::string get_string_value();
    
    void append_text(const std::string &text);
    
    void set_padding(int pad);

    sigc::signal<void> signal_changed() { return _signal_changed; }

  public:
    void callback();

  protected:
    TextBoxImplPtrs *_textbox_impl;
    bool _updating;
    
    sigc::signal<void> _signal_changed;
  };
};

#endif
