/* Copyright (C) 2019 The gtkmm Development Team
 *
 * 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.1 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, see <http://www.gnu.org/licenses/>.
 */

#include <gtkmm/widget.h>
#include <gtkmm/editable.h>
#include <gtkmm/entrybuffer.h>
#include <giomm/menumodel.h>
#include <pangomm/attrlist.h>
#include <pangomm/tabarray.h>

_DEFS(gtkmm,gtk)
_PINCLUDE(gtkmm/private/widget_p.h)

namespace Gtk
{

/** A simple single-line text entry field.
 *
 * The %Gtk::Text widget is a single-line text entry widget.
 * A fairly large set of key bindings are supported by default. If the
 * entered text is longer than the allocation of the widget, the widget
 * will scroll so that the cursor position is visible.
 *
 * When using an entry for passwords and other sensitive information,
 * it can be put into “password mode” using set_visibility().
 * In this mode, entered text is displayed using an “invisible” character.
 * By default, GTK picks the best invisible character that is available
 * in the current font, but it can be changed with set_invisible_char().
 *
 * If you are looking to add icons or progress display in an entry, look
 * at Gtk::Entry. There are other alternatives for more specialized use cases,
 * such as Gtk::SearchEntry.
 * If you need multi-line editable text, look at Gtk::TextView.
 *
 * @see Entry, TextView
 * @newin{3,96}
 *
 * @ingroup Widgets
 */
class GTKMM_API Text : public Widget,  public Editable
{
  _CLASS_GTKOBJECT(Text, GtkText, GTK_TEXT, Gtk::Widget, GtkWidget, , , GTKMM_API)
  _IMPLEMENTS_INTERFACE(Editable)
public:
  _CTOR_DEFAULT
  _WRAP_CTOR(Text(const Glib::RefPtr<EntryBuffer>& buffer), gtk_text_new_with_buffer)

  _WRAP_METHOD(Glib::RefPtr<EntryBuffer> get_buffer(), gtk_text_get_buffer, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const EntryBuffer> get_buffer() const, gtk_text_get_buffer, refreturn, constversion)
  _WRAP_METHOD(void set_buffer(const Glib::RefPtr<EntryBuffer>& buffer), gtk_text_set_buffer)

  _WRAP_METHOD(void set_visibility(bool visible = true), gtk_text_set_visibility)
  _WRAP_METHOD(bool get_visibility() const, gtk_text_get_visibility)
  _WRAP_METHOD(void set_invisible_char(gunichar ch), gtk_text_set_invisible_char)
  _WRAP_METHOD(void unset_invisible_char(), gtk_text_unset_invisible_char)
  _WRAP_METHOD(gunichar get_invisible_char() const, gtk_text_get_invisible_char)
  _WRAP_METHOD(void set_overwrite_mode(bool overwrite = true), gtk_text_set_overwrite_mode)
  _WRAP_METHOD(bool get_overwrite_mode() const, gtk_text_get_overwrite_mode)
  _WRAP_METHOD(void set_max_length(int max), gtk_text_set_max_length)
  _WRAP_METHOD(int get_max_length() const, gtk_text_get_max_length)
  _WRAP_METHOD(guint16 get_text_length() const, gtk_text_get_text_length)
  _WRAP_METHOD(void set_activates_default(bool setting = true), gtk_text_set_activates_default)
  _WRAP_METHOD(bool get_activates_default() const, gtk_text_get_activates_default)
  _WRAP_METHOD(Glib::ustring get_placeholder_text() const, gtk_text_get_placeholder_text)
  _WRAP_METHOD(void set_placeholder_text(const Glib::ustring& text), gtk_text_set_placeholder_text)

  _WRAP_METHOD(void set_input_purpose(InputPurpose purpose), gtk_text_set_input_purpose)
  _WRAP_METHOD(InputPurpose get_input_purpose() const, gtk_text_get_input_purpose)

  _WRAP_METHOD(void set_input_hints(InputHints hints), gtk_text_set_input_hints)
  _WRAP_METHOD(InputHints get_input_hints() const, gtk_text_get_input_hints)

  _WRAP_METHOD(void set_attributes(Pango::AttrList& attrs), gtk_text_set_attributes)
  _WRAP_METHOD(Pango::AttrList get_attributes() const, gtk_text_get_attributes)

#m4 _CONVERSION(`PangoTabArray*',`Pango::TabArray',`Pango::TabArray(($3))')
#m4 _CONVERSION(`const Pango::TabArray&',`PangoTabArray*',`const_cast<Pango::TabArray&>($3).gobj()')
  _WRAP_METHOD(void set_tabs(const Pango::TabArray& tabs), gtk_text_set_tabs)
  _WRAP_METHOD(Pango::TabArray get_tabs() const, gtk_text_get_tabs)

  _WRAP_METHOD(bool grab_focus_without_selecting(), gtk_text_grab_focus_without_selecting)

  _WRAP_METHOD(void set_extra_menu(const Glib::RefPtr<Gio::MenuModel>& model), gtk_text_set_extra_menu)
  _WRAP_METHOD(Glib::RefPtr<Gio::MenuModel> get_extra_menu(), gtk_text_get_extra_menu, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Gio::MenuModel> get_extra_menu() const, gtk_text_get_extra_menu, refreturn, constversion)

  _WRAP_METHOD(void set_enable_emoji_completion(bool enable_emoji_completion = true), gtk_text_set_enable_emoji_completion)
  _WRAP_METHOD(bool get_enable_emoji_completion() const, gtk_text_get_enable_emoji_completion)
  _WRAP_METHOD(void set_propagate_text_width(bool propagate_text_width = true), gtk_text_set_propagate_text_width)
  _WRAP_METHOD(bool get_propagate_text_width() const, gtk_text_get_propagate_text_width)
  _WRAP_METHOD(void set_truncate_multiline(bool truncate_multiline = true), gtk_text_set_truncate_multiline)
  _WRAP_METHOD(bool get_truncate_multiline() const, gtk_text_get_truncate_multiline)

  // Action signals
  _IGNORE_SIGNAL(activate, move-cursor, insert-at-cursor, delete-from-cursor,
    backspace, cut-clipboard, copy-clipboard, paste-clipboard, toggle-overwrite,
    preedit-changed, insert-emoji)

  _WRAP_PROPERTY("buffer", Glib::RefPtr<EntryBuffer>)
  _WRAP_PROPERTY("max-length", int)
  _WRAP_PROPERTY("visibility", bool)
  _WRAP_PROPERTY("invisible-char", gunichar)
  _WRAP_PROPERTY("invisible-char-set", bool)
  _WRAP_PROPERTY("activates-default", bool)
  _WRAP_PROPERTY("scroll-offset", int)
  _WRAP_PROPERTY("truncate-multiline", bool)
  _WRAP_PROPERTY("overwrite-mode", bool)
  _WRAP_PROPERTY("im-module", Glib::ustring)
  _WRAP_PROPERTY("placeholder-text", Glib::ustring)
  _WRAP_PROPERTY("input-purpose", InputPurpose)
  _WRAP_PROPERTY("input-hints", InputHints)
  _WRAP_PROPERTY("attributes", Pango::AttrList)
  _WRAP_PROPERTY("tabs", Pango::TabArray)
  _WRAP_PROPERTY("enable-emoji-completion", bool)
  _WRAP_PROPERTY("propagate-text-width", bool)
  _WRAP_PROPERTY("extra-menu", Glib::RefPtr<Gio::MenuModel>)
};

} //namespace Gtk
