/* Copyright (C) 1998-2002 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 <https://www.gnu.org/licenses/>.
 */

_CONFIGINCLUDE(gtkmmconfig.h)

#include <glibmm/interface.h>
_DEFS(gtkmm,gtk)
_PINCLUDE(glibmm/private/interface_p.h)

#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C"
{
typedef struct _GtkEditableInterface GtkEditableInterface;
}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

namespace Gtk
{
class GTKMM_API Widget;

/** Base class for text-editing widgets.
 *
 * The Gtk::Editable class is a base class for widgets for editing text,
 * such as Gtk::Entry. It cannot be instantiated by itself. The editable
 * class contains functions for generically manipulating an editable widget,
 * a large number of action signals used for key bindings, and several
 * signals that an application can connect to to modify the behavior of a
 * widget.
 */
class GTKMM_API Editable : public Glib::Interface
{
  _CLASS_INTERFACE(Editable,GtkEditable,GTK_EDITABLE,GtkEditableInterface, , , GTKMM_API)

public:
  _WRAP_METHOD(Glib::ustring get_text() const, gtk_editable_get_text)
  _WRAP_METHOD(void set_text(const Glib::ustring& text), gtk_editable_set_text)
  _WRAP_METHOD(Glib::ustring get_complete_text() const, gtk_editable_get_complete_text)

  _WRAP_METHOD(void delete_selection(), gtk_editable_delete_selection)
  _WRAP_METHOD(void set_editable(bool is_editable = true), gtk_editable_set_editable)
  _WRAP_METHOD(bool get_editable() const, gtk_editable_get_editable)

  _WRAP_METHOD(void insert_text(const Glib::ustring& new_text, int new_text_length, int& position), gtk_editable_insert_text)
  _WRAP_METHOD(void delete_text(int start_pos, int end_pos), gtk_editable_delete_text)

  _WRAP_METHOD(Glib::ustring get_chars(int start_pos, int end_pos) const, gtk_editable_get_chars)

  _WRAP_METHOD(void select_region(int start_pos, int end_pos), gtk_editable_select_region)
  _WRAP_METHOD(bool get_selection_bounds(int& start_pos, int& end_pos) const, gtk_editable_get_selection_bounds)

  _WRAP_METHOD(void set_position(int position), gtk_editable_set_position)
  _WRAP_METHOD(int get_position() const, gtk_editable_get_position)

  _WRAP_METHOD(float get_alignment() const, gtk_editable_get_alignment)
  _WRAP_METHOD(void set_alignment(float xalign), gtk_editable_set_alignment)

  _WRAP_METHOD(int get_width_chars() const, gtk_editable_get_width_chars)
  _WRAP_METHOD(void set_width_chars(int n_chars), gtk_editable_set_width_chars)

  _WRAP_METHOD(int get_max_width_chars() const, gtk_editable_get_max_width_chars)
  _WRAP_METHOD(void set_max_width_chars(int n_chars), gtk_editable_set_max_width_chars)

  _WRAP_METHOD(bool get_enable_undo() const, gtk_editable_get_enable_undo)
  _WRAP_METHOD(void set_enable_undo(bool enable_undo = true), gtk_editable_set_enable_undo)

  _WRAP_METHOD(void set_input_interceptor(Widget& interceptor), gtk_editable_set_input_interceptor)
  /** See set_input_interceptor().
   * @newin{4,24}
   */
  void unset_input_interceptor();
  _WRAP_METHOD_DOCS_ONLY(gtk_editable_get_input_interceptor)
  Widget* get_input_interceptor();
  _WRAP_METHOD(const Widget* get_input_interceptor() const, gtk_editable_get_input_interceptor, constversion)

  // Don't wrap API for implementations. Should it be wrapped?
  _IGNORE(gtk_editable_install_properties, gtk_editable_get_delegate, gtk_editable_init_delegate,
    gtk_editable_finish_delegate, gtk_editable_delegate_set_property, gtk_editable_delegate_get_property,
    gtk_editable_delegate_get_accessible_platform_state)

  _IGNORE_SIGNAL(insert_text)

#m4begin
dnl // WRAP_SIGNAL "insert_text"
dnl // C++ prototype: void insert_text(const Glib::ustring& text, int* position)
dnl // C prototype: void insert_text(const char* text, int length, int* position)

  _SIGNAL_PROXY(
      insert_text, void, `const char* text, int length, int* position',
      insert_text, void, `const Glib::ustring&, int*',dnl // C++ prototype
      `Glib::ustring(text, text + length), position',`dnl // C -> C++ conversion
      /**
       * @param const Glib::ustring& text
       * @param int* position
       * @return void
       */')

  _SIGNAL_H(insert_text, void, `const Glib::ustring& text, int* position')
  _SIGNAL_PH(insert_text, void,
    `GtkEditable* self, const char* text, int length, int* position',,,,dnl // C prototype
    `self, text, length, position')dnl // C argument names

  _SIGNAL_CC(
      insert_text, insert_text, void, void,
      `const Glib::ustring& text, int* position',dnl // C++ arguments
      `text.data(), text.bytes(), position')dnl // C++ -> C conversion

  _SIGNAL_PCC(
      insert_text, insert_text, void, void,
      `GtkEditable* self, const char* text, int length, int* position',dnl // C arguments
      `self, text, length, position',dnl // C argument names
      `Glib::ustring(text, text + length), position',dnl // C -> C++ conversion
      self)
#m4end

  _WRAP_SIGNAL(void delete_text(int start_pos, int end_pos), "delete_text")
  _WRAP_SIGNAL(void changed(), "changed")
  // no_default_handler because the wrapped C signal has no default handler.
  _WRAP_SIGNAL(void input_intercepted(), "input-intercepted", no_default_handler)

  _WRAP_PROPERTY("text", Glib::ustring)
  _WRAP_PROPERTY("complete-text", Glib::ustring)
  _WRAP_PROPERTY("cursor-position", int)
  _WRAP_PROPERTY("enable-undo", bool)
  _WRAP_PROPERTY("selection-bound", int)
  _WRAP_PROPERTY("editable", bool)
  _WRAP_PROPERTY("width-chars", int)
  _WRAP_PROPERTY("max-width-chars", int)
  _WRAP_PROPERTY("xalign", float)
  _WRAP_PROPERTY("input-interceptor", Widget*)

protected:

#m4begin
dnl // WRAP_VFUNC "do_insert_text"
dnl // C++ prototype: void insert_text_vfunc(const Glib::ustring& text, int& position)
dnl // C prototype: void do_insert_text(const char* text, int length, int* position)

  _VFUNC_H(insert_text_vfunc, void, `const Glib::ustring& text, int& position')
  _VFUNC_PH(do_insert_text, void,
    `GtkEditable* self, const char* text, int length, int* position',,dnl // C prototype
    `self, text, length, position')dnl // C argument names
  _VFUNC_CC(
      insert_text_vfunc, do_insert_text, void, void,
      `const Glib::ustring& text, int& position',dnl // C++ arguments
      `text.data(), text.bytes(), &position')dnl // C++ -> C conversion
  _VFUNC_PCC(
      insert_text_vfunc, do_insert_text, void, void,
      `GtkEditable* self, const char* text, int length, int* position',dnl // C arguments
      `self, text, length, position',dnl // C argument names
      `Glib::ustring(text, text + length), *position',dnl // C -> C++ conversion
      self)
#m4end

  _WRAP_VFUNC(void delete_text(int start_pos, int end_pos), do_delete_text)

#m4 _CONVERSION(`Glib::ustring', `const char*', `($3).c_str()')
  _WRAP_VFUNC(Glib::ustring get_text() const, get_text, keep_return)

  _WRAP_VFUNC(void select_region(int start_pos, int end_pos), set_selection_bounds)
  _WRAP_VFUNC(bool get_selection_bounds(int& start_pos, int& end_pos) const, get_selection_bounds)
  // Don't wrap API for implementations. Should it be wrapped?
  // _WRAP_VFUNC(Editable* get_delegate(), get_delegate)
};

} // namespace Gtk
