diff options
Diffstat (limited to 'adw/src/spinrow.cpp')
| -rw-r--r-- | adw/src/spinrow.cpp | 383 |
1 files changed, 383 insertions, 0 deletions
diff --git a/adw/src/spinrow.cpp b/adw/src/spinrow.cpp new file mode 100644 index 0000000..0f86ca0 --- /dev/null +++ b/adw/src/spinrow.cpp @@ -0,0 +1,383 @@ +/** + * @author Felix Morgner (felix.morgner@gmail.com) + * @copyright Copyright (c) 2025 + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "adwaitamm/spinrow.hpp" + +#include "adwaitamm/actionrow.hpp" +#include "adwaitamm/private/spinrow_p.hpp" + +#include <sigc++/functors/slot.h> + +#include <glibmm/exceptionhandler.h> +#include <glibmm/object.h> +#include <glibmm/objectbase.h> +#include <glibmm/propertyproxy.h> +#include <glibmm/refptr.h> +#include <glibmm/signalproxy.h> +#include <glibmm/wrap.h> + +#include <gtkmm/adjustment.h> +#include <gtkmm/spinbutton.h> + +#include <glib-object.h> +#include <glib.h> +#include <gtk/gtk.h> + +namespace Adwaita +{ + namespace + { + auto constinit _class = SpinRow_Class{}; + + namespace property_name + { + auto constexpr adjustment = "adjustment"; + auto constexpr climb_rate = "climb-rate"; + auto constexpr digits = "digits"; + auto constexpr numeric = "numeric"; + auto constexpr snap_to_ticks = "snap-to-ticks"; + auto constexpr update_policy = "update-policy"; + auto constexpr value = "value"; + auto constexpr wrap = "wrap"; + } // namespace property_name + + namespace signal_handler + { + auto input(AdwSpinRow * self, double * new_value, void * user_data) -> int + try + { + auto object = Glib::wrap(self); + if (object) + { + auto slot = Glib::SignalProxyNormal::data_to_slot(user_data); + if (slot) + { + return (*static_cast<sigc::slot<int(double &)> *>(slot))(*new_value); + } + } + return {}; + } + catch (...) + { + Glib::exception_handlers_invoke(); + return {}; + } + + auto input_notify(AdwSpinRow * self, double * new_value, void * user_data) -> gboolean + try + { + auto object = Glib::wrap(self); + if (object) + { + auto slot = Glib::SignalProxyNormal::data_to_slot(user_data); + if (slot) + { + (*static_cast<sigc::slot<int(double &)> *>(slot))(*new_value); + } + } + return {}; + } + catch (...) + { + Glib::exception_handlers_invoke(); + return {}; + } + + auto output(AdwSpinRow * self, void * user_data) -> gboolean + try + { + auto object = Glib::wrap(self); + if (object) + { + auto slot = Glib::SignalProxyNormal::data_to_slot(user_data); + if (slot) + { + return static_cast<gboolean>((*static_cast<sigc::slot<bool()> *>(slot))()); + } + } + return {}; + } + catch (...) + { + Glib::exception_handlers_invoke(); + return {}; + } + + auto output_notify(AdwSpinRow * self, void * user_data) -> gboolean + try + { + auto object = Glib::wrap(self); + if (object) + { + auto slot = Glib::SignalProxyNormal::data_to_slot(user_data); + if (slot) + { + (*static_cast<sigc::slot<bool()> *>(slot))(); + } + } + return {}; + } + catch (...) + { + Glib::exception_handlers_invoke(); + return {}; + } + } // namespace signal_handler + + namespace signal_info + { + auto const input = Glib::SignalProxyInfo{ + "input", + reinterpret_cast<GCallback>(&signal_handler::input), + reinterpret_cast<GCallback>(&signal_handler::input_notify), + }; + + auto const output = Glib::SignalProxyInfo{ + "output", + reinterpret_cast<GCallback>(&signal_handler::output), + reinterpret_cast<GCallback>(&signal_handler::output_notify), + }; + + auto const wrapped = Glib::SignalProxyInfo{ + "wrapped", + reinterpret_cast<GCallback>(&Glib::SignalProxyNormal::slot0_void_callback), + reinterpret_cast<GCallback>(&Glib::SignalProxyNormal::slot0_void_callback), + }; + } // namespace signal_info + } // namespace + + SpinRow::SpinRow(Gtk::Adjustment & adjustment, double climb_rate, unsigned int digits) + : Glib::ObjectBase{nullptr} + , ActionRow{Glib::ConstructParams{_class.init(), "adjustment", unwrap(&adjustment), "climb-rate", climb_rate, "digits", digits, nullptr}} + { + } + + SpinRow::SpinRow(double min, double max, double step) + : Glib::ObjectBase{nullptr} + , ActionRow{ADW_ACTION_ROW(adw_spin_row_new_with_range(min, max, step))} + { + } + + auto SpinRow::get_type() -> GType + { + return _class.init().get_type(); + } + + auto SpinRow::get_base_type() -> GType + { + return adw_spin_row_get_type(); + } + + auto SpinRow::configure(Gtk::Adjustment & adjustment, double climb_rate, unsigned int digits) -> void + { + return adw_spin_row_configure(unwrap(this), unwrap(&adjustment), climb_rate, digits); + } + + auto SpinRow::update() -> void + { + return adw_spin_row_update(unwrap(this)); + } + + auto SpinRow::get_adjustment() const -> Glib::RefPtr<Gtk::Adjustment> + { + // Take a copy, since SpinRow owns the adjustment + return Glib::wrap(adw_spin_row_get_adjustment(const_cast<BaseObjectType *>(unwrap(this))), true); + } + + auto SpinRow::get_climb_rate() const -> double + { + return adw_spin_row_get_climb_rate(const_cast<BaseObjectType *>(unwrap(this))); + } + + auto SpinRow::get_digits() const -> unsigned int + { + return adw_spin_row_get_digits(const_cast<BaseObjectType *>(unwrap(this))); + } + + auto SpinRow::get_numeric() const -> bool + { + return adw_spin_row_get_numeric(const_cast<BaseObjectType *>(unwrap(this))); + } + + auto SpinRow::get_snap_to_ticks() const -> bool + { + return adw_spin_row_get_snap_to_ticks(const_cast<BaseObjectType *>(unwrap(this))); + } + + auto SpinRow::get_update_policy() const -> Gtk::SpinButton::UpdatePolicy + { + return static_cast<Gtk::SpinButton::UpdatePolicy>(adw_spin_row_get_update_policy(const_cast<BaseObjectType *>(unwrap(this)))); + } + + auto SpinRow::get_value() const -> double + { + return adw_spin_row_get_value(const_cast<BaseObjectType *>(unwrap(this))); + } + + auto SpinRow::get_wrap() const -> bool + { + return adw_spin_row_get_wrap(const_cast<BaseObjectType *>(unwrap(this))); + } + + auto SpinRow::set_adjustment(Gtk::Adjustment & value) -> void + { + return adw_spin_row_set_adjustment(unwrap(this), unwrap(&value)); + } + + auto SpinRow::set_climb_rate(double value) -> void + { + return adw_spin_row_set_climb_rate(unwrap(this), value); + } + + auto SpinRow::set_digits(unsigned int value) -> void + { + return adw_spin_row_set_digits(unwrap(this), value); + } + + auto SpinRow::set_numeric(bool value) -> void + { + return adw_spin_row_set_numeric(unwrap(this), value); + } + + auto SpinRow::set_range(double min, double max) -> void + { + return adw_spin_row_set_range(unwrap(this), min, max); + } + + auto SpinRow::set_snap_to_ticks(bool value) -> void + { + return adw_spin_row_set_snap_to_ticks(unwrap(this), value); + } + + auto SpinRow::set_update_policy(Gtk::SpinButton::UpdatePolicy value) -> void + { + return adw_spin_row_set_update_policy(unwrap(this), static_cast<GtkSpinButtonUpdatePolicy>(value)); + } + + auto SpinRow::set_value(double value) -> void + { + return adw_spin_row_set_value(unwrap(this), value); + } + + auto SpinRow::set_wrap(bool value) -> void + { + return adw_spin_row_set_wrap(unwrap(this), value); + } + + [[nodiscard]] auto SpinRow::property_adjustment() -> Glib::PropertyProxy<Glib::RefPtr<Gtk::Adjustment>> + { + return {this, property_name::adjustment}; + } + + [[nodiscard]] auto SpinRow::property_adjustment() const -> Glib::PropertyProxy_ReadOnly<Glib::RefPtr<Gtk::Adjustment>> + { + return {this, property_name::adjustment}; + } + + [[nodiscard]] auto SpinRow::property_climb_rate() -> Glib::PropertyProxy<double> + { + return {this, property_name::climb_rate}; + } + + [[nodiscard]] auto SpinRow::property_climb_rate() const -> Glib::PropertyProxy_ReadOnly<double> + { + return {this, property_name::climb_rate}; + } + + [[nodiscard]] auto SpinRow::property_digits() -> Glib::PropertyProxy<unsigned int> + { + return {this, property_name::digits}; + } + + [[nodiscard]] auto SpinRow::property_digits() const -> Glib::PropertyProxy_ReadOnly<unsigned int> + { + return {this, property_name::digits}; + } + + [[nodiscard]] auto SpinRow::property_numeric() -> Glib::PropertyProxy<bool> + { + return {this, property_name::numeric}; + } + + [[nodiscard]] auto SpinRow::property_numeric() const -> Glib::PropertyProxy_ReadOnly<bool> + { + return {this, property_name::numeric}; + } + + [[nodiscard]] auto SpinRow::property_snap_to_ticks() -> Glib::PropertyProxy<bool> + { + return {this, property_name::snap_to_ticks}; + } + + [[nodiscard]] auto SpinRow::property_snap_to_ticks() const -> Glib::PropertyProxy_ReadOnly<bool> + { + return {this, property_name::snap_to_ticks}; + } + + [[nodiscard]] auto SpinRow::property_update_policy() -> Glib::PropertyProxy<Gtk::SpinButton::UpdatePolicy> + { + return {this, property_name::update_policy}; + } + + [[nodiscard]] auto SpinRow::property_update_policy() const -> Glib::PropertyProxy_ReadOnly<Gtk::SpinButton::UpdatePolicy> + { + return {this, property_name::update_policy}; + } + + [[nodiscard]] auto SpinRow::property_value() -> Glib::PropertyProxy<double> + { + return {this, property_name::value}; + } + + [[nodiscard]] auto SpinRow::property_value() const -> Glib::PropertyProxy_ReadOnly<double> + { + return {this, property_name::value}; + } + + [[nodiscard]] auto SpinRow::property_wrap() -> Glib::PropertyProxy<bool> + { + return {this, property_name::wrap}; + } + + [[nodiscard]] auto SpinRow::property_wrap() const -> Glib::PropertyProxy_ReadOnly<bool> + { + return {this, property_name::wrap}; + } + + auto SpinRow::signal_input() -> Glib::SignalProxy<int(double &)> + { + return {this, &signal_info::input}; + } + + auto SpinRow::signal_output() -> Glib::SignalProxy<bool()> + { + return {this, &signal_info::output}; + } + + auto SpinRow::signal_wrapped() -> Glib::SignalProxy<void()> + { + return {this, &signal_info::wrapped}; + } + + SpinRow::SpinRow(Glib::ConstructParams const & params) + : ActionRow{params} + { + } + + SpinRow::SpinRow(BaseObjectType * gobj) + : ActionRow(ADW_ACTION_ROW(gobj)) + { + } + +} // namespace Adwaita + +namespace Glib +{ + auto wrap(AdwSpinRow * object, bool copy) -> Adwaita::SpinRow * + { + return dynamic_cast<Adwaita::SpinRow *>(Glib::wrap_auto(G_OBJECT(object), copy)); + } +} // namespace Glib
\ No newline at end of file |
