// Generated by gmmproc 2.78.1 -- DO NOT MODIFY!


#include <glibmm.h>

#include <gtkmm/sorter.h>
#include <gtkmm/private/sorter_p.h>


/* Copyright (C) 2020 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 <gtk/gtk.h>

using Order = Gtk::Sorter::Order;
using Change = Gtk::Sorter::Change;

namespace
{


extern "C" {
static void Sorter_signal_changed_connect_callback(GtkSorter* self, GtkSorterChange p0,void* data)
{
  using namespace Gtk;
  using SlotType = sigc::slot<void(Change)>;

  auto obj = dynamic_cast<Sorter*>(Glib::ObjectBase::_get_current_wrapper((GObject*) self));
  // Do not try to call a signal on a disassociated wrapper.
  if(obj)
  {
    try
    {
      if(const auto slot = Glib::SignalProxyNormal::data_to_slot(data))
        (*static_cast<SlotType*>(slot))(static_cast<Change>(p0)
);
    }
    catch(...)
    {
       Glib::exception_handlers_invoke();
    }
  }
}
} // extern "C"

static const Glib::SignalProxyInfo Sorter_signal_changed_info =
{
  "changed",
  (GCallback) &Sorter_signal_changed_connect_callback,
  (GCallback) &Sorter_signal_changed_connect_callback
};


using Sorter_compare_vfunc_functype = GtkOrdering (*)(GtkSorter* self, gpointer item1, gpointer item2);
Sorter_compare_vfunc_functype Sorter_compare_vfunc_funcptr;
extern "C" {
static GtkOrdering Sorter_compare_vfunc_c_callback(GtkSorter* self, gpointer item1, gpointer item2)
{
  return Sorter_compare_vfunc_funcptr( self, item1, item2);
}
} // extern "C"
using Sorter_get_order_vfunc_functype = GtkSorterOrder (*)(GtkSorter* self);
Sorter_get_order_vfunc_functype Sorter_get_order_vfunc_funcptr;
extern "C" {
static GtkSorterOrder Sorter_get_order_vfunc_c_callback(GtkSorter* self)
{
  return Sorter_get_order_vfunc_funcptr( self);
}
} // extern "C"
} // anonymous namespace

// static
GType Glib::Value<Gtk::Sorter::Order>::value_type()
{
  return gtk_sorter_order_get_type();
}

// static
GType Glib::Value<Gtk::Sorter::Change>::value_type()
{
  return gtk_sorter_change_get_type();
}


namespace Glib
{

Glib::RefPtr<Gtk::Sorter> wrap(GtkSorter* object, bool take_copy)
{
  return Glib::make_refptr_for_instance<Gtk::Sorter>( dynamic_cast<Gtk::Sorter*> (Glib::wrap_auto ((GObject*)(object), take_copy)) );
  //We use dynamic_cast<> in case of multiple inheritance.
}

} /* namespace Glib */


namespace Gtk
{


/* The *_Class implementation: */

const Glib::Class& Sorter_Class::init()
{
  if(!gtype_) // create the GType if necessary
  {
    // Glib::Class has to know the class init function to clone custom types.
    class_init_func_ = &Sorter_Class::class_init_function;

    // This is actually just optimized away, apparently with no harm.
    // Make sure that the parent type has been created.
    //CppClassParent::CppObjectType::get_type();

    // Create the wrapper type, with the same class/instance size as the base type.
    register_derived_type(gtk_sorter_get_type());

    // Add derived versions of interfaces, if the C type implements any interfaces:

  }

  return *this;
}


void Sorter_Class::class_init_function(void* g_class, void* class_data)
{
  const auto klass = static_cast<BaseClassType*>(g_class);
  CppClassParent::class_init_function(klass, class_data);

  klass->compare = &Sorter_compare_vfunc_c_callback;
  Sorter_compare_vfunc_funcptr = &compare_vfunc_callback;
  klass->get_order = &Sorter_get_order_vfunc_c_callback;
  Sorter_get_order_vfunc_funcptr = &get_order_vfunc_callback;

}

GtkOrdering Sorter_Class::compare_vfunc_callback(GtkSorter* self, gpointer item1, gpointer item2)
{
  const auto obj_base = static_cast<Glib::ObjectBase*>(
      Glib::ObjectBase::_get_current_wrapper((GObject*)self));

  // Non-gtkmmproc-generated custom classes implicitly call the default
  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
  // generated classes can use this optimisation, which avoids the unnecessary
  // parameter conversions if there is no possibility of the virtual function
  // being overridden:
  if(obj_base && obj_base->is_derived_())
  {
    const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
    if(obj) // This can be NULL during destruction.
    {
      try // Trap C++ exceptions which would normally be lost because this is a C callback.
      {
        // Call the virtual member method, which derived classes might override.
        return static_cast<GtkOrdering>(obj->compare_vfunc(item1, item2));
      }
      catch(...)
      {
        Glib::exception_handlers_invoke();
      }
    }
  }

  BaseClassType *const base = static_cast<BaseClassType*>(
      g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
  );

  // Call the original underlying C function:
  if(base && base->compare)
    return (*base->compare)(self, item1, item2);

  using RType = GtkOrdering;
  return RType();
}
GtkSorterOrder Sorter_Class::get_order_vfunc_callback(GtkSorter* self)
{
  const auto obj_base = static_cast<Glib::ObjectBase*>(
      Glib::ObjectBase::_get_current_wrapper((GObject*)self));

  // Non-gtkmmproc-generated custom classes implicitly call the default
  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
  // generated classes can use this optimisation, which avoids the unnecessary
  // parameter conversions if there is no possibility of the virtual function
  // being overridden:
  if(obj_base && obj_base->is_derived_())
  {
    const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
    if(obj) // This can be NULL during destruction.
    {
      try // Trap C++ exceptions which would normally be lost because this is a C callback.
      {
        // Call the virtual member method, which derived classes might override.
        return static_cast<GtkSorterOrder>(obj->get_order_vfunc());
      }
      catch(...)
      {
        Glib::exception_handlers_invoke();
      }
    }
  }

  BaseClassType *const base = static_cast<BaseClassType*>(
      g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
  );

  // Call the original underlying C function:
  if(base && base->get_order)
    return (*base->get_order)(self);

  using RType = GtkSorterOrder;
  return RType();
}


Glib::ObjectBase* Sorter_Class::wrap_new(GObject* object)
{
  return new Sorter((GtkSorter*)object);
}


/* The implementation: */

GtkSorter* Sorter::gobj_copy()
{
  reference();
  return gobj();
}

Sorter::Sorter(const Glib::ConstructParams& construct_params)
:
  Glib::Object(construct_params)
{

}

Sorter::Sorter(GtkSorter* castitem)
:
  Glib::Object((GObject*)(castitem))
{}


Sorter::Sorter(Sorter&& src) noexcept
: Glib::Object(std::move(src))
{}

Sorter& Sorter::operator=(Sorter&& src) noexcept
{
  Glib::Object::operator=(std::move(src));
  return *this;
}


Sorter::~Sorter() noexcept
{}


Sorter::CppClassType Sorter::sorter_class_; // initialize static member

GType Sorter::get_type()
{
  return sorter_class_.init().get_type();
}


GType Sorter::get_base_type()
{
  return gtk_sorter_get_type();
}


Sorter::Sorter()
:
  // Mark this class as non-derived to allow C++ vfuncs to be skipped.
  Glib::ObjectBase(nullptr),
  Glib::Object(Glib::ConstructParams(sorter_class_.init()))
{
  

}

Ordering Sorter::compare(gpointer item1, gpointer item2)
{
  return static_cast<Ordering>(gtk_sorter_compare(gobj(), item1, item2));
}

Order Sorter::get_order() const
{
  return static_cast<Order>(gtk_sorter_get_order(const_cast<GtkSorter*>(gobj())));
}

void Sorter::changed(Change change)
{
  gtk_sorter_changed(gobj(), static_cast<GtkSorterChange>(change));
}


Glib::SignalProxy<void(Change)> Sorter::signal_changed()
{
  return Glib::SignalProxy<void(Change) >(this, &Sorter_signal_changed_info);
}


Ordering Gtk::Sorter::compare_vfunc(gpointer item1, gpointer item2) 
{
  const auto base = static_cast<BaseClassType*>(
      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
  );

  if(base && base->compare)
  {
    Ordering retval(static_cast<Ordering>((*base->compare)(gobj(),item1,item2)));
    return retval;
  }

  using RType = Ordering;
  return RType();
}
Order Gtk::Sorter::get_order_vfunc() 
{
  const auto base = static_cast<BaseClassType*>(
      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
  );

  if(base && base->get_order)
  {
    Order retval(static_cast<Order>((*base->get_order)(gobj())));
    return retval;
  }

  using RType = Order;
  return RType();
}


} // namespace Gtk


