/* 
 * © 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 _LF_TEXTENTRY_H_
#define _LF_TEXTENTRY_H_

#include <mforms/mforms.h>

#include "lf_view.h"


namespace mforms {
namespace gtk {

class TextEntryImpl : public ViewImpl
{
  Gtk::Entry    *_entry;
  virtual Gtk::Widget *get_outer() const { return _entry; }
  
  static bool create(::mforms::TextEntry *self, bool passw)
  {
    return new TextEntryImpl(self, passw);
  }

  static void set_text(::mforms::TextEntry *self, const std::string &text)
  {
    TextEntryImpl* cb = self->get_data<TextEntryImpl>();

    if ( cb )
    {
      cb->_entry->set_text(text);
    }
  }

  static void set_max_length(::mforms::TextEntry *self, int len)
  {
    TextEntryImpl* cb = self->get_data<TextEntryImpl>();

    if ( cb )
    {
      cb->_entry->set_max_length(len);
    }
  }

  static std::string get_text(::mforms::TextEntry *self)
  {
    TextEntryImpl* cb = self->get_data<TextEntryImpl>();
    std::string ret("");
    if ( cb )
    {
      ret = cb->_entry->get_text().raw();
    }
    return ret;
  }
  
  static void set_password(::mforms::TextEntry *self, bool flag)
  {
    TextEntryImpl* cb = self->get_data<TextEntryImpl>();
    if (cb && cb->_entry)
      cb->_entry->set_visibility(!flag);
  }

  TextEntryImpl(::mforms::TextEntry *self, bool passw)
    : ViewImpl(self)
  {
    _entry= Gtk::manage(new Gtk::Entry());
    _entry->set_visibility(!passw);
    _entry->signal_changed().connect(sigc::mem_fun(self, &::mforms::TextEntry::callback));
  }

public:
  static void init()
  {
    ::mforms::ControlFactory *f = ::mforms::ControlFactory::get_instance();

    f->_textentry_impl.create   = &TextEntryImpl::create;
    f->_textentry_impl.set_text = &TextEntryImpl::set_text;
    f->_textentry_impl.set_max_length = &TextEntryImpl::set_max_length;
    f->_textentry_impl.get_text = &TextEntryImpl::get_text;
  }
};

  };
};

#endif
