/* Glom
 *
 * Copyright (C) 2001-2004 Murray Cumming
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef GLOM_MODE_DATA_ENTRY_H
#define GLOM_MODE_DATA_ENTRY_H

#include "config.h" // For GLOM_ENABLE_CLIENT_ONLY

#include <gtkmm.h>
#include <libglom/data_structure/field.h>
#include <glom/utility_widgets/layoutwidgetfield.h>
#include <gtkmm/builder.h>

#ifdef GLOM_ENABLE_MAEMO
#include <hildonmm/entry.h>
#endif

namespace Glom
{

class Application;

namespace DataWidgetChildren
{

class Entry
:
#ifdef GLOM_ENABLE_MAEMO
  public Hildon::Entry,
#else
  public Gtk::Entry,
#endif
  public LayoutWidgetField
{
public:
  explicit Entry(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder);
  explicit Entry(Field::glom_field_type glom_type = Field::TYPE_TEXT);
  virtual ~Entry();

  virtual void set_layout_item(const sharedptr<LayoutItem>& layout_item, const Glib::ustring& table_name);

  void set_glom_type(Field::glom_field_type glom_type);

  //Override this so we can store the text to compare later.
  //This is not virtual, so you must not use it via Gtk::Entry.
  void set_text(const Glib::ustring& text); //override

  /** Set the text from a Gnome::Gda::Value.
   */
  virtual void set_value(const Gnome::Gda::Value& value);

  virtual Gnome::Gda::Value get_value() const;

  virtual void set_read_only(bool read_only = true);

private:
  void init();

  //Overrides of default signal handlers:
  virtual void on_changed(); //From Gtk::Entry.
  virtual void on_activate(); //From Gtk::Entry.
  virtual bool on_focus_out_event(GdkEventFocus* event); //From Gtk::Widget

  virtual void check_for_change();

#ifndef GLOM_ENABLE_CLIENT_ONLY
  virtual bool on_button_press_event(GdkEventButton *event); //override
#endif // !GLOM_ENABLE_CLIENT_ONLY

  virtual Application* get_application();

  Glib::ustring m_old_text;
  Field::glom_field_type m_glom_type; //Store the type so we can validate the text accordingly.

  //Gnome::Gda::Value m_value; //The last-stored value. We have this because the displayed value might be unparseable.
};

} //namespace DataWidetChildren
} //namespace Glom

#endif // GLOM_MODE_DATA_ENTRY_H
