/* Copyright (C) 2007 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/>.
 */

#include <vector>

#include <gtkmm/widget.h>
#include <giomm/resource.h> //For ResourceError, thrown by create_from_resource().
#include <utility> //For std::forward()

_DEFS(gtkmm,gtk)
_PINCLUDE(glibmm/private/object_p.h)

namespace Gtk
{
class GTKMM_API Application;

/** Exception class for Gtk::Builder errors.
 */
_WRAP_GERROR(BuilderError,GtkBuilderError,GTK_BUILDER_ERROR, decl_prefix GTKMM_API)

/** Build an interface from an XML UI definition description.
 *
 * This object represents an `instantiation' of an UI definition description.
 * When one of these objects is created, the XML file is read, and the user interface
 * is created. The %Gtk::Builder object then provides an interface for accessing the
 * widgets in the user interface by the names assigned to them inside the UI description.
 *
 * A %Gtk::Builder holds a reference to all objects that it has constructed
 * and drops these references when it is deleted. This deletion can
 * cause the destruction of non-widget objects or widgets which are not
 * contained in a toplevel window. For toplevel windows constructed by a
 * builder, it is the responsibility of the user to get them with get_widget()
 * or get_widget_derived() and delete them to get rid of them and all
 * the widgets they contain.
 *
 * The methods get_widget() and get_widget_derived()
 * can be used to access the widgets in the interface by the names assigned
 * to them inside the UI description. Toplevel windows returned by these
 * methods will stay around until the user explicitly deletes them.
 * Other widgets will either be part of a
 * larger hierarchy constructed by the builder (in which case you should
 * not have to worry about their lifecycle), or without a parent, in which
 * case they have to be added to some container before the builder is deleted
 * to make use of them.
 *
 * Non-widget objects need to be fetched with get_object() or get_objects()
 * to keep them beyond the lifespan of the builder.
 *
 * @par %Gtk::Builder and Glib::Property
 * A derived widget that contains Glib::Property members must be registered with
 * its own name in the GType system. It must be registered before any of the
 * create_from_*() or add_from_*() methods are called, meaning that you may have
 * to create an instance of your derived widget just to have its class registered.
 * There is no reasonably easy way to combine %Gtk::Builder with non-widget objects
 * containing Glib::Property members. Combining it with widgets containing
 * Glib::Property members requires glibmm 2.62 or newer.
 * See also get_widget_derived() and Glib::Property.
 */
class GTKMM_API Builder : public Glib::Object
{
  _CLASS_GOBJECT(Builder, GtkBuilder, GTK_BUILDER, Glib::Object, GObject, , , GTKMM_API)

protected:
  Builder();
  _IGNORE(gtk_builder_new)

public:
  /** Creates a new builder object.
   */
  _WRAP_CREATE()

  /** Parses a file containing a GtkBuilder UI definition.
   *
   * @param filename the name of the file to parse.
   * @result A new Builder object, or a null pointer if an error occurred.
   * @throws BuilderError, Glib::MarkupError, Glib::FileError
   */
  static Glib::RefPtr<Builder> create_from_file(const std::string& filename);

  /** Parses a file containing a GtkBuilder UI definition, building only the requested object.
   *
   * If you are adding an object that depends on an object that is not
   * its child (for instance a GtkTreeView that depends on its
   * GtkTreeModel), you have to explicitely list all of them.
   *
   * @param filename the name of the file to parse.
   * @param object_id The object to build.
   * @result A new Builder object, or a null pointer if an error occurred.
   * @throws BuilderError, Glib::MarkupError, Glib::FileError
   */
  static Glib::RefPtr<Builder> create_from_file(const std::string& filename, const Glib::ustring& object_id);

  //This is just to avoid the ambiguous call when using a string literal,
  //caused by the overload that takes a std::vector<Glib::ustring>.
  /** Parses a file containing a GtkBuilder UI definition, building only the requested object.
   *
   * If you are adding an object that depends on an object that is not
   * its child (for instance a GtkTreeView that depends on its
   * GtkTreeModel), you have to explicitely list all of them.
   *
   * @param filename the name of the file to parse.
   * @param object_id The object to build.
   * @result A new Builder object, or a null pointer if an error occurred.
   * @throws BuilderError, Glib::MarkupError, Glib::FileError
   */
  static Glib::RefPtr<Builder> create_from_file(const std::string& filename, const char* object_id);

  /** Parses a file containing a GtkBuilder UI definition, building only the requested objects.
   *
   * If you are adding an object that depends on an object that is not
   * its child (for instance a GtkTreeView that depends on its
   * GtkTreeModel), you have to explicitely list all of them.
   *
   * @param filename the name of the file to parse.
   * @param object_ids The objects to build.
   * @result A new Builder object, or a null pointer if an error occurred.
   * @throws BuilderError, Glib::MarkupError, Glib::FileError
   */
  static Glib::RefPtr<Builder> create_from_file(const std::string& filename, const std::vector<Glib::ustring>& object_ids);

  /** Parses a resource file containing a GtkBuilder UI definition.
   *
   * @param resource_path The path of the resource file to parse.
   * @result A new Builder object, or a null pointer if an error occurred.
   * @throws BuilderError, Glib::MarkupError, Gio::ResourceError
   *
   * @newin{3,6}
   */
  static Glib::RefPtr<Builder> create_from_resource(const std::string& resource_path);

  /** Parses a resource file containing a GtkBuilder UI definition, building only the requested object.
   *
   * If you are adding an object that depends on an object that is not
   * its child (for instance a GtkTreeView that depends on its
   * GtkTreeModel), you have to explicitely list all of them.
   *
   * @param resource_path The path of the resource file to parse.
   * @param object_id The object to build.
   * @result A new Builder object, or a null pointer if an error occurred.
   * @throws BuilderError, Glib::MarkupError, Gio::ResourceError
   *
   * @newin{3,6}
   */
  static Glib::RefPtr<Builder> create_from_resource(const std::string& resource_path, const Glib::ustring& object_id);

  //This is just to avoid the ambiguous call when using a string literal,
  //caused by the overload that takes a std::vector<Glib::ustring>.
  /** Parses a resource file containing a GtkBuilder UI definition, building only the requested object.
   *
   * If you are adding an object that depends on an object that is not
   * its child (for instance a GtkTreeView that depends on its
   * GtkTreeModel), you have to explicitely list all of them.
   *
   * @param resource_path The path of the resource file to parse.
   * @param object_id The object to build.
   * @result A new Builder object, or a null pointer if an error occurred.
   * @throws BuilderError, Glib::MarkupError, Gio::ResourceError
   *
   * @newin{3,6}
   */
  static Glib::RefPtr<Builder> create_from_resource(const std::string& resource_path, const char* object_id);

  /** Parses a resource file containing a GtkBuilder UI definition, building only the requested objects.
   *
   * If you are adding an object that depends on an object that is not
   * its child (for instance a GtkTreeView that depends on its
   * GtkTreeModel), you have to explicitely list all of them.
   *
   * @param resource_path The path of the resource file to parse.
   * @param object_ids The objects to build.
   * @result A new Builder object, or a null pointer if an error occurred.
   * @throws BuilderError, Glib::MarkupError, Gio::ResourceError
   *
   * @newin{3,6}
   */
  static Glib::RefPtr<Builder> create_from_resource(const std::string& resource_path, const std::vector<Glib::ustring>& object_ids);


  /** Parses a string containing a GtkBuilder UI definition.
   *
   * @param buffer: the string to parse
   * @result A new Builder object, or a null pointer if an error occurred.
   * @throws BuilderError, Glib::MarkupError
   */
  static Glib::RefPtr<Builder> create_from_string(const Glib::ustring& buffer);

  //This is just to avoid the ambiguous call when using a string literal,
  //caused by the overload that takes a std::vector<Glib::ustring>.
  /** Parses a string containing a GtkBuilder UI definition building only the requested object.
   *
   * @param buffer The string to parse.
   * @param object_id The object to build.
   * @result A new Builder object, or a null pointer if an error occurred.
   * @throws BuilderError, Glib::MarkupError
   */
  static Glib::RefPtr<Builder> create_from_string(const Glib::ustring& buffer, const char* object_id);

  /** Parses a string containing a GtkBuilder UI definition building only the requested object.
   *
   * @param buffer The string to parse.
   * @param object_id The object to build.
   * @result A new Builder object, or a null pointer if an error occurred.
   * @throws BuilderError, Glib::MarkupError
   */
  static Glib::RefPtr<Builder> create_from_string(const Glib::ustring& buffer, const Glib::ustring& object_id);

  /** Parses a string containing a GtkBuilder UI definition building only the requested objects.
   *
   * If you are adding an object that depends on an object that is not
   * its child (for instance a GtkTreeView that depends on its
   * GtkTreeModel), you have to explicitely list all of them.
   *
   * @param buffer the string to parse
   * @param object_ids The objects to build.
   * @result A new Builder object, or a null pointer if an error occurred.
   * @throws BuilderError, Glib::MarkupError
   */
  static Glib::RefPtr<Builder> create_from_string(const Glib::ustring& buffer, const std::vector<Glib::ustring>& object_ids);
  _IGNORE(gtk_builder_add_objects_from_file)

  /** Parses a file containing a GtkBuilder UI definition,
   * and merges it with the current contents of the builder.
   *
   * @param filename The file to parse.
   * @result true on success or false if an error occurred.
   * @throws BuilderError, Glib::MarkupError, Glib::MarkupError
   */
  _WRAP_METHOD(bool add_from_file(const std::string& filename), gtk_builder_add_from_file, errthrow)

  //This is just to avoid the ambiguous call when using a string literal,
  //caused by the overload that takes a std::vector<Glib::ustring>.
  /** Parses a file containing a GtkBuilder UI definition,
   * building only the requested object,
   * and merges it with the current contents of the builder.
   *
   * If you are adding an object that depends on an object that is not
   * its child (for instance a GtkTreeView that depends on its
   * GtkTreeModel), you have to explicitely list all of them.
   *
   * @param filename The file to parse.
   * @param object_id The object to build.
   * @result true on success or false if an error occurred.
   * @throws BuilderError, Glib::MarkupError, Glib::MarkupError
   */
  bool add_from_file(const std::string& filename, const char* object_id);

  /** Parses a file containing a GtkBuilder UI definition,
   * building only the requested object,
   * and merges it with the current contents of the builder.
   *
   * If you are adding an object that depends on an object that is not
   * its child (for instance a GtkTreeView that depends on its
   * GtkTreeModel), you have to explicitely list all of them.
   *
   * @param filename The file to parse.
   * @param object_id The object to build.
   * @result true on success or false if an error occurred.
   * @throws BuilderError, Glib::MarkupError, Glib::MarkupError
   */
  bool add_from_file(const std::string& filename, const Glib::ustring& object_id);

#m4 _CONVERSION(`const std::vector<Glib::ustring>&',`const char**',`Glib::ArrayHandler<Glib::ustring>::vector_to_array($3).data()')
  _WRAP_METHOD(bool add_from_file(const std::string& filename, const std::vector<Glib::ustring>& object_ids),  gtk_builder_add_objects_from_file, errthrow)


  /** Parses a resource file containing a GtkBuilder UI definition,
   * and merges it with the current contents of the builder.
   *
   * @param resource_path The path of the resource file to parse.
   * @result true on success or false if an error occurred.
   * @throws BuilderError, Glib::MarkupError, Gio::ResourceError
   *
   * @newin{3,6}
   */
  _WRAP_METHOD(bool add_from_resource(const std::string& resource_path), gtk_builder_add_from_resource, errthrow)

  //This is just to avoid the ambiguous call when using a string literal,
  //caused by the overload that takes a std::vector<Glib::ustring>.
  /** Parses a resource file containing a GtkBuilder UI definition,
   * building only the requested object,
   * and merges it with the current contents of the builder.
   *
   * If you are adding an object that depends on an object that is not
   * its child (for instance a GtkTreeView that depends on its
   * GtkTreeModel), you have to explicitely list all of them.
   *
   * @param resource_path The path of the resource file to parse.
   * @param object_id The object to build.
   * @result true on success or false if an error occurred.
   * @throws BuilderError, Glib::MarkupError, Gio::ResourceError
   *
   * @newin{3,6}
   */
  bool add_from_resource(const std::string& resource_path, const char* object_id);

  /** Parses a resource file containing a GtkBuilder UI definition,
   * building only the requested object,
   * and merges it with the current contents of the builder.
   *
   * If you are adding an object that depends on an object that is not
   * its child (for instance a GtkTreeView that depends on its
   * GtkTreeModel), you have to explicitely list all of them.
   *
   * @param resource_path The path of the resource file to parse.
   * @param object_id The object to build.
   * @result true on success or false if an error occurred.
   * @throws BuilderError, Glib::MarkupError, Gio::ResourceError
   *
   * @newin{3,6}
   */
  bool add_from_resource(const std::string& resource_path, const Glib::ustring& object_id);

#m4 _CONVERSION(`const std::vector<Glib::ustring>&',`const char**',`Glib::ArrayHandler<Glib::ustring>::vector_to_array($3).data()')
  _WRAP_METHOD(bool add_from_resource(const std::string& resource_path, const std::vector<Glib::ustring>& object_ids),  gtk_builder_add_objects_from_resource, errthrow)

  //This is just to avoid the ambiguous call when using a string literal,
  //caused by the overload that takes a std::vector<Glib::ustring>.
  /** Parses a string containing a GtkBuilder UI definition
   * and merges it with the current contents of the builder.
   *
   * @param buffer The string to parse.
   * @result true on success or false if an error occurred.
   * @throws BuilderError, Glib::MarkupError
   */
  bool add_from_string(const Glib::ustring& buffer);

  /** Parses a string containing a GtkBuilder UI definition,
   * building only the requested object,
   * and merges it with the current contents of the builder.
   *
   * @param buffer The string to parse.
   * @param object_id The object to build.
   * @result true on success or false if an error occurred.
   * @throws BuilderError, Glib::MarkupError
   */
  bool add_from_string(const Glib::ustring& buffer, const char* object_id);

  /** Parses a string containing a GtkBuilder UI definition,
   * building only the requested object,
   * and merges it with the current contents of the builder.
   *
   * @param buffer The string to parse.
   * @param object_id The object to build.
   * @result true on success or false if an error occurred.
   * @throws BuilderError, Glib::MarkupError
   */
  bool add_from_string(const Glib::ustring& buffer, const Glib::ustring& object_id);

  /** Parses a string containing a GtkBuilder UI definition,
   * building only the requested objects,
   * and merges it with the current contents of the builder.
   *
   * @param buffer The string to parse.
   * @param object_ids The objects to build.
   * @result true on success or false if an error occurred.
   * @throws BuilderError, Glib::MarkupError
   */
  bool add_from_string(const Glib::ustring& buffer, const std::vector<Glib::ustring>& object_ids);
  _IGNORE(gtk_builder_add_objects_from_string)

  /** Parses a string containing a GtkBuilder UI definition
   * and merges it with the current contents of the builder.
   *
   * @param buffer The string to parse.
   * @param length The length of @a buffer (may be -1 if @a buffer is nul-terminated).
   * @result true on success or false if an error occurred.
   * @throws BuilderError, Glib::MarkupError
   */
  _WRAP_METHOD(bool add_from_string(const char* buffer, gssize length), gtk_builder_add_from_string, errthrow)

  _WRAP_METHOD(void expose_object(const Glib::ustring& name, const Glib::RefPtr<Glib::Object>& object), gtk_builder_expose_object)
#m4 _CONVERSION(`Widget&',`GObject*',`G_OBJECT(($3).gobj())')

  /** Add @a widget to the builder object pool so it can be referenced just like any
   * other object built by builder.
   *
   * @newin{3,12}
   *
   * @param name The name of the widget exposed to the builder.
   * @param widget The widget to expose.
   */
  _WRAP_METHOD(void expose_widget(const Glib::ustring& name, Widget& widget{object}), gtk_builder_expose_object)

  //TODO: Custom-implement this and prevent it from being used with GTK_WIDGET-derived types?
  // A Builder can contain objects that don't derive from Buildable,
  // for instance if objects have been added with expose_object().

  /** Gets the object named @a name.
   *
   * @param name Name of object to get.
   * @return The object named @a name or <tt>nullptr</tt> if it could not be found in the object tree.
   */
  _WRAP_METHOD(Glib::RefPtr<Glib::Object> get_object(const Glib::ustring& name), gtk_builder_get_object, refreturn)

  /** Gets the object named @a name.
   *
   * @newin{3,8}
   *
   * @param name Name of object to get.
   * @return The object named @a name or <tt>nullptr</tt> if it could not be found in the object tree.
   */
  _WRAP_METHOD(Glib::RefPtr<const Glib::Object> get_object(const Glib::ustring& name) const, gtk_builder_get_object, refreturn, constversion)

  /** Gets the object named @a name, cast to a specific derived type.
   *
   * For instance:
   * @code
   * auto adjustment = refBuilder->get_object<Gtk::Adjustment>("adjustment_id");
   * adjustment->set_value(42);
   * @endcode
   *
   * @newin{3,96}
   *
   * @param name Name of object to get.
   * @return The object named @a name or <tt>nullptr</tt> if it could not be
   *   found in the object tree or could not be cast to the specified type.
   */
  template <class T_Object> inline
  Glib::RefPtr<T_Object> get_object(const Glib::ustring& name)
  {
    return std::dynamic_pointer_cast<T_Object>(get_object(name));
  }

  /** See the non-const version.
   * @newin{3,96}
   */
  template <class T_Object> inline
  Glib::RefPtr<const T_Object> get_object(const Glib::ustring& name) const
  {
    return const_cast<Builder*>(this)->get_object<const T_Object>(name);
  }

  /** Gets a widget from the Builder file.
   *
   * For instance:
   * @code
   * auto pGrid = refBuilder->get_widget<Gtk::Grid>("mygrid");
   * @endcode
   *
   * This method prints a warning message to the console if the widget
   * doesn't exist or has the wrong type, so you don't need to check that
   * manually.
   *
   * Note that you are responsible for deleting top-level widgets (windows and
   * dialogs) instantiated by the Builder object. Other widgets are instantiated as
   * managed so they will be deleted automatically if you add them to a
   * container widget.
   *
   * @param name The name of the widget.
   * @return A pointer to the widget, or <tt>nullptr</tt> on failure.
   *
   * @newin{3,96}
   */
  template <class T_Widget> inline
  T_Widget* get_widget(const Glib::ustring& name)
  {
    T_Widget* widget = nullptr;

    // The dynamic_cast<> should never fail if get_widget_checked() succeeded.
    widget = dynamic_cast<T_Widget*>(this->get_widget_checked(name, T_Widget::get_base_type()));

    if(!widget)
      g_critical("Gtk::Builder::get_widget(): dynamic_cast<> failed.");

    return widget;
  }

  /** See the non-const version.
   * @newin{3,96}
   */
  template <class T_Widget> inline
  const T_Widget* get_widget(const Glib::ustring& name) const
  {
    return const_cast<Builder*>(this)->get_widget<const T_Widget>(name);
  }

  /** Gets a widget whose details are specified in the GtkBuilder file,
   * but which is implemented by your own derived class.
   *
   * Your class must have a constructor like so:
   * @code
   * MyDerivedDialog::MyDerivedDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refBuilder)
   * : Gtk::Dialog(cobject) //Calls the base class constructor
   * @endcode
   * or, with additional parameters, for example:
   * @code
   * MyDerivedDialog::MyDerivedDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refBuilder,
   *   const Glib::ustring& msg, bool warning)
   * : Gtk::Dialog(cobject) //Calls the base class constructor
   * @endcode
   *
   * For instance:
   * @code
   * auto pDialog1 = Gtk::Builder::get_widget_derived<MyDerivedDialog>(refBuilder, "mydialog1");
   * auto pDialog2 = Gtk::Builder::get_widget_derived<MyDerivedDialog>(refBuilder, "mydialog2", "A storm is imminent!", true);
   * @endcode
   *
   * @note
   * If get_widget_derived() is called more than once for the same widget (the
   * same @a name), only the first call will call the widget's constructor.
   * The following calls will return a pointer to the widget instance that
   * was constructed by the first call.
   *
   * @par %Gtk::Builder and Glib::Property
   * If the widget contains Glib::Property members, your constructor must call
   * the Glib::ObjectBase constructor with a new GType name:
   * @code
   * MyDerivedDialog::MyDerivedDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refBuilder)
   * : Glib::ObjectBase("MyDialog"), // The GType name will be gtkmm__CustomObject_MyDialog
   *   Gtk::Dialog(cobject) // Calls the base class constructor
   *   m_my_property(*this, "my-property")
   * @endcode
   *
   * @param builder The Gtk::Builder from which to get the widget.
   * @param name The name of the widget.
   * @param args Additional arguments to pass to the constructor of the derived class.
   * @return A pointer to the widget, or <tt>nullptr</tt> on failure.
   *
   * @newin{3,96}
   */
  template <typename T_Widget, typename... Args> inline
  static T_Widget* get_widget_derived(const Glib::RefPtr<Gtk::Builder>& builder, const Glib::ustring& name, Args&&... args)
  {
     // Get the widget from the GtkBuilder file.
     using cwidget_type = typename T_Widget::BaseObjectType;
     auto pCWidget = (cwidget_type*)builder->get_cwidget(name);

     //The error was already reported by get_cwidget().
     if(!pCWidget)
       return nullptr;

     T_Widget* widget = nullptr;

     //Check whether there is already a C++ wrapper instance associated with this C instance:
     Glib::ObjectBase* pObjectBase = ObjectBase::_get_current_wrapper((GObject*)pCWidget);

     //If there is already a C++ instance, then return it again:
     if(pObjectBase)
     {
       widget = dynamic_cast<T_Widget*>( Glib::wrap((GtkWidget*)pCWidget) );
       //Newer, more spec-complaint, versions of g++ cannot resolve a specific wrap() function in a template.

       //The dynamic cast checks that it is of the correct type.
       //Somebody might be trying to call get_widget_derived() after already calling get_widget(),
       //or after already calling get_widget_derived() with a different derived C++ type.
       if(!widget)
        g_critical("Gtk::Builder::get_widget_derived(): dynamic_cast<> failed. An existing C++ instance, of a different type, seems to exist.");
     }
     else
     {
       //Create a new C++ instance to wrap the existing C instance:

       //Set the output variable. We needed to do this because we can not template the return type.
       widget = new T_Widget(pCWidget, builder, std::forward<Args>(args)...);
       // Don't add reference to widget. That's done only in methods that return
       // a Glib::RefPtr<Something>.
     }

    return widget;
  }

  /** See the non-const version.
   * @newin{3,96}
   */
  template <typename T_Widget, typename... Args> inline
  static const T_Widget* get_widget_derived(const Glib::RefPtr<const Gtk::Builder>& builder, const Glib::ustring& name, Args&&... args)
  {
    return get_widget_derived<const T_Widget>(std::const_pointer_cast<Gtk::Builder>(builder), name, std::forward<Args>(args)...);
  }

#m4 _CONVERSION(`GSList*',`std::vector<Glib::RefPtr<Glib::Object> >',`Glib::SListHandler<Glib::RefPtr<Glib::Object> >::slist_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
  _WRAP_METHOD(std::vector<Glib::RefPtr<Glib::Object> > get_objects(), gtk_builder_get_objects)

#m4 _CONVERSION(`GSList*',`std::vector<Glib::RefPtr<const Glib::Object> >',`Glib::SListHandler<Glib::RefPtr<const Glib::Object> >::slist_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
  _WRAP_METHOD(std::vector<Glib::RefPtr<const Glib::Object> > get_objects() const, gtk_builder_get_objects)

  _WRAP_METHOD(void set_translation_domain(const Glib::ustring& domain), gtk_builder_set_translation_domain)
  _WRAP_METHOD(Glib::ustring get_translation_domain() const, gtk_builder_get_translation_domain)

  // We ignore gtk_builder_get_type_from_name() because it only seems useful when implementing GtkBuildable for widgets.
  _IGNORE(gtk_builder_get_type_from_name)
  // We ignore BuilderScope methods and property because it seems unlikely
  // that a user of Builder wants to change the scope.
  _IGNORE(gtk_builder_set_scope, gtk_builder_get_scope)
  _IGNORE_PROPERTY(scope)

  _WRAP_PROPERTY("translation-domain", Glib::ustring)

protected:
  Gtk::Widget* get_widget_checked(const Glib::ustring& name, GType type);
  GtkWidget* get_cwidget(const Glib::ustring& name);

private:
  bool no_gtkmm_derived_types {false};
  void set_no_gtkmm_derived_types(bool status);
  bool get_no_gtkmm_derived_types() const;
  friend class GTKMM_API Buildable_Class;
  friend class GTKMM_API BuilderScope_Class;
};

} // namespace Gtk
