From 0b4f979c001835b20ff75a848eee83f59c1397c0 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 28 Apr 2025 11:22:20 +0200 Subject: adw: implement SpinRow --- adw/src/spinrow.cpp | 383 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 383 insertions(+) create mode 100644 adw/src/spinrow.cpp (limited to 'adw/src/spinrow.cpp') 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 + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +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 *>(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 *>(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((*static_cast *>(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 *>(slot))(); + } + } + return {}; + } + catch (...) + { + Glib::exception_handlers_invoke(); + return {}; + } + } // namespace signal_handler + + namespace signal_info + { + auto const input = Glib::SignalProxyInfo{ + "input", + reinterpret_cast(&signal_handler::input), + reinterpret_cast(&signal_handler::input_notify), + }; + + auto const output = Glib::SignalProxyInfo{ + "output", + reinterpret_cast(&signal_handler::output), + reinterpret_cast(&signal_handler::output_notify), + }; + + auto const wrapped = Glib::SignalProxyInfo{ + "wrapped", + reinterpret_cast(&Glib::SignalProxyNormal::slot0_void_callback), + reinterpret_cast(&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 + { + // Take a copy, since SpinRow owns the adjustment + return Glib::wrap(adw_spin_row_get_adjustment(const_cast(unwrap(this))), true); + } + + auto SpinRow::get_climb_rate() const -> double + { + return adw_spin_row_get_climb_rate(const_cast(unwrap(this))); + } + + auto SpinRow::get_digits() const -> unsigned int + { + return adw_spin_row_get_digits(const_cast(unwrap(this))); + } + + auto SpinRow::get_numeric() const -> bool + { + return adw_spin_row_get_numeric(const_cast(unwrap(this))); + } + + auto SpinRow::get_snap_to_ticks() const -> bool + { + return adw_spin_row_get_snap_to_ticks(const_cast(unwrap(this))); + } + + auto SpinRow::get_update_policy() const -> Gtk::SpinButton::UpdatePolicy + { + return static_cast(adw_spin_row_get_update_policy(const_cast(unwrap(this)))); + } + + auto SpinRow::get_value() const -> double + { + return adw_spin_row_get_value(const_cast(unwrap(this))); + } + + auto SpinRow::get_wrap() const -> bool + { + return adw_spin_row_get_wrap(const_cast(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(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> + { + return {this, property_name::adjustment}; + } + + [[nodiscard]] auto SpinRow::property_adjustment() const -> Glib::PropertyProxy_ReadOnly> + { + return {this, property_name::adjustment}; + } + + [[nodiscard]] auto SpinRow::property_climb_rate() -> Glib::PropertyProxy + { + return {this, property_name::climb_rate}; + } + + [[nodiscard]] auto SpinRow::property_climb_rate() const -> Glib::PropertyProxy_ReadOnly + { + return {this, property_name::climb_rate}; + } + + [[nodiscard]] auto SpinRow::property_digits() -> Glib::PropertyProxy + { + return {this, property_name::digits}; + } + + [[nodiscard]] auto SpinRow::property_digits() const -> Glib::PropertyProxy_ReadOnly + { + return {this, property_name::digits}; + } + + [[nodiscard]] auto SpinRow::property_numeric() -> Glib::PropertyProxy + { + return {this, property_name::numeric}; + } + + [[nodiscard]] auto SpinRow::property_numeric() const -> Glib::PropertyProxy_ReadOnly + { + return {this, property_name::numeric}; + } + + [[nodiscard]] auto SpinRow::property_snap_to_ticks() -> Glib::PropertyProxy + { + return {this, property_name::snap_to_ticks}; + } + + [[nodiscard]] auto SpinRow::property_snap_to_ticks() const -> Glib::PropertyProxy_ReadOnly + { + return {this, property_name::snap_to_ticks}; + } + + [[nodiscard]] auto SpinRow::property_update_policy() -> Glib::PropertyProxy + { + return {this, property_name::update_policy}; + } + + [[nodiscard]] auto SpinRow::property_update_policy() const -> Glib::PropertyProxy_ReadOnly + { + return {this, property_name::update_policy}; + } + + [[nodiscard]] auto SpinRow::property_value() -> Glib::PropertyProxy + { + return {this, property_name::value}; + } + + [[nodiscard]] auto SpinRow::property_value() const -> Glib::PropertyProxy_ReadOnly + { + return {this, property_name::value}; + } + + [[nodiscard]] auto SpinRow::property_wrap() -> Glib::PropertyProxy + { + return {this, property_name::wrap}; + } + + [[nodiscard]] auto SpinRow::property_wrap() const -> Glib::PropertyProxy_ReadOnly + { + return {this, property_name::wrap}; + } + + auto SpinRow::signal_input() -> Glib::SignalProxy + { + return {this, &signal_info::input}; + } + + auto SpinRow::signal_output() -> Glib::SignalProxy + { + return {this, &signal_info::output}; + } + + auto SpinRow::signal_wrapped() -> Glib::SignalProxy + { + 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(Glib::wrap_auto(G_OBJECT(object), copy)); + } +} // namespace Glib \ No newline at end of file -- cgit v1.2.3