From 3fe6119b93141d74c9f34f69d2b3b6ae016c2abf Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 28 Apr 2025 09:58:10 +0200 Subject: adw: implement WindowTitle --- adw/include/adwaitamm/private/windowtitle_p.hpp | 39 +++++++++ adw/include/adwaitamm/windowtitle.hpp | 78 +++++++++++++++++ adw/src/private/windowtitle_p.cpp | 42 +++++++++ adw/src/windowtitle.cpp | 110 ++++++++++++++++++++++++ adw/src/wrap_init.cpp | 4 + 5 files changed, 273 insertions(+) create mode 100644 adw/include/adwaitamm/private/windowtitle_p.hpp create mode 100644 adw/include/adwaitamm/windowtitle.hpp create mode 100644 adw/src/private/windowtitle_p.cpp create mode 100644 adw/src/windowtitle.cpp diff --git a/adw/include/adwaitamm/private/windowtitle_p.hpp b/adw/include/adwaitamm/private/windowtitle_p.hpp new file mode 100644 index 0000000..460505a --- /dev/null +++ b/adw/include/adwaitamm/private/windowtitle_p.hpp @@ -0,0 +1,39 @@ +/** + * @author Felix Morgner (felix.morgner@gmail.com) + * @copyright Copyright (c) 2025 + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#ifndef LIBADWAITAMM_PRIVATE_WINDOW_TITLE_P_HPP +#define LIBADWAITAMM_PRIVATE_WINDOW_TITLE_P_HPP + +#include +#include + +#include + +#define _ADWAITA_INSIDE +#include +#undef _ADWAITA_INSIDE + +namespace Adwaita +{ + struct WindowTitle_Class : Glib::Class + { + using BaseClassParent = GtkWidgetClass; + using BaseClassType = AdwWindowTitleClass; + using BaseObjectType = AdwWindowTitle; + using CppClassParent = Gtk::Widget_Class; + using CppObjectType = struct WindowTitle; + + auto init() -> Glib::Class const &; + auto static class_init_function(void * gclass, void * data) -> void; + auto static wrap_new(GObject * object) -> Glib::ObjectBase *; + + protected: + auto static close_attempt(BaseObjectType * self) -> void; + auto static closed(BaseObjectType * self) -> void; + }; +} // namespace Adwaita + +#endif \ No newline at end of file diff --git a/adw/include/adwaitamm/windowtitle.hpp b/adw/include/adwaitamm/windowtitle.hpp new file mode 100644 index 0000000..d142a95 --- /dev/null +++ b/adw/include/adwaitamm/windowtitle.hpp @@ -0,0 +1,78 @@ +/** + * @author Felix Morgner (felix.morgner@gmail.com) + * @copyright Copyright (c) 2025 + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#ifndef LIBADWAITAMM_WINDOW_TITLE_HPP +#define LIBADWAITAMM_WINDOW_TITLE_HPP + +#include "helpers/gobj_mixin.hpp" + +#include +#include +#include + +#include + +#include + +#define _ADWAITA_INSIDE +#include +#undef _ADWAITA_INSIDE + +namespace Adwaita +{ + struct WindowTitle final : Gtk::Widget, + helpers::gobj_mixin + { + + using BaseObjectType = AdwWindowTitle; + using BaseClassType = AdwWindowTitleClass; + using CppObjectType = WindowTitle; + using CppClassType = struct WindowTitle_Class; + + using helpers::gobj_mixin::gobj; + using helpers::gobj_mixin::gobj_copy; + +#pragma mark - Special Member Functions + WindowTitle(Glib::ustring const & title, Glib::ustring const & subtitle); + WindowTitle(WindowTitle const & other) = delete; + WindowTitle(WindowTitle && other) noexcept = default; + + auto operator=(WindowTitle const & other) noexcept -> WindowTitle & = delete; + auto operator=(WindowTitle && other) noexcept -> WindowTitle & = default; + +#pragma mark - GObject Support + auto static get_type() -> GType; + auto static get_base_type() -> GType; + +#pragma mark - Getters + [[nodiscard]] auto get_subtitle() const -> Glib::ustring; + [[nodiscard]] auto get_title() const -> Glib::ustring; + +#pragma mark - Setters + auto set_subtitle(Glib::ustring const & value) -> void; + auto set_title(Glib::ustring const & value) -> void; + +#pragma mark - Properties + [[nodiscard]] auto property_subtitle() -> Glib::PropertyProxy; + [[nodiscard]] auto property_subtitle() const -> Glib::PropertyProxy_ReadOnly; + [[nodiscard]] auto property_title() -> Glib::PropertyProxy; + [[nodiscard]] auto property_title() const -> Glib::PropertyProxy_ReadOnly; + + protected: + friend WindowTitle_Class; + +#pragma mark - Internal Constructors + explicit WindowTitle(Glib::ConstructParams const & params); + explicit WindowTitle(BaseObjectType * gobj); + }; +} // namespace Adwaita + +namespace Glib +{ + auto wrap(AdwWindowTitle * object, bool copy = false) -> Adwaita::WindowTitle *; +} // namespace Glib + +#endif \ No newline at end of file diff --git a/adw/src/private/windowtitle_p.cpp b/adw/src/private/windowtitle_p.cpp new file mode 100644 index 0000000..77f92d8 --- /dev/null +++ b/adw/src/private/windowtitle_p.cpp @@ -0,0 +1,42 @@ +/** + * @author Felix Morgner (felix.morgner@gmail.com) + * @copyright Copyright (c) 2025 + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "adwaitamm/private/windowtitle_p.hpp" + +#include "adwaitamm/windowtitle.hpp" + +#include +#include +#include + +#include +#include + +namespace Adwaita +{ + + auto WindowTitle_Class::init() -> Glib::Class const & + { + if (!gtype_) + { + class_init_func_ = &class_init_function; + gtype_ = adw_window_title_get_type(); + } + return *this; + } + + auto WindowTitle_Class::class_init_function(void * gclass, void * data) -> void + { + auto const klass = static_cast(gclass); + CppClassParent::class_init_function(klass, data); + } + + auto WindowTitle_Class::wrap_new(GObject * object) -> Glib::ObjectBase * + { + return Gtk::manage(new WindowTitle(ADW_WINDOW_TITLE(object))); + } + +} // namespace Adwaita \ No newline at end of file diff --git a/adw/src/windowtitle.cpp b/adw/src/windowtitle.cpp new file mode 100644 index 0000000..5433f14 --- /dev/null +++ b/adw/src/windowtitle.cpp @@ -0,0 +1,110 @@ +/** + * @author Felix Morgner (felix.morgner@gmail.com) + * @copyright Copyright (c) 2025 + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "adwaitamm/windowtitle.hpp" + +#include "adwaitamm/private/windowtitle_p.hpp" + +#include +#include +#include +#include +#include + +#include + +#include +#include + +namespace Adwaita +{ + + namespace + { + auto constinit _class = WindowTitle_Class{}; + + namespace property_name + { + auto constexpr subtitle = "subtitle"; + auto constexpr title = "title"; + } // namespace property_name + } // namespace + + WindowTitle::WindowTitle(Glib::ustring const & title, Glib::ustring const & subtitle) + : Glib::ObjectBase{nullptr} + , Gtk::Widget{Glib::ConstructParams{_class.init(), "title", title.c_str(), "subtitle", subtitle.c_str(), nullptr}} + { + } + + auto WindowTitle::get_type() -> GType + { + return _class.init().get_type(); + } + + auto WindowTitle::get_base_type() -> GType + { + return adw_window_title_get_type(); + } + + auto WindowTitle::get_subtitle() const -> Glib::ustring + { + return adw_window_title_get_subtitle(const_cast(unwrap(this))); + } + + auto WindowTitle::get_title() const -> Glib::ustring + { + return adw_window_title_get_title(const_cast(unwrap(this))); + } + + auto WindowTitle::set_subtitle(Glib::ustring const & value) -> void + { + return adw_window_title_set_subtitle(unwrap(this), value.c_str()); + } + + auto WindowTitle::set_title(Glib::ustring const & value) -> void + { + return adw_window_title_set_title(unwrap(this), value.c_str()); + } + + auto WindowTitle::property_subtitle() -> Glib::PropertyProxy + { + return {this, property_name::subtitle}; + } + + auto WindowTitle::property_subtitle() const -> Glib::PropertyProxy_ReadOnly + { + return {this, property_name::subtitle}; + } + + auto WindowTitle::property_title() -> Glib::PropertyProxy + { + return {this, property_name::title}; + } + + auto WindowTitle::property_title() const -> Glib::PropertyProxy_ReadOnly + { + return {this, property_name::title}; + } + + WindowTitle::WindowTitle(Glib::ConstructParams const & params) + : Gtk::Widget{params} + { + } + + WindowTitle::WindowTitle(BaseObjectType * gobj) + : Gtk::Widget(GTK_WIDGET(gobj)) + { + } + +} // namespace Adwaita + +namespace Glib +{ + auto wrap(AdwWindowTitle * object, bool copy) -> Adwaita::WindowTitle * + { + return dynamic_cast(Glib::wrap_auto(G_OBJECT(object), copy)); + } +} // namespace Glib \ No newline at end of file diff --git a/adw/src/wrap_init.cpp b/adw/src/wrap_init.cpp index 4f6cd25..d7dece1 100644 --- a/adw/src/wrap_init.cpp +++ b/adw/src/wrap_init.cpp @@ -30,10 +30,12 @@ #include "adwaitamm/private/switchrow_p.hpp" #include "adwaitamm/private/toast_p.hpp" #include "adwaitamm/private/toastoverlay_p.hpp" +#include "adwaitamm/private/windowtitle_p.hpp" #include "adwaitamm/stylemanager.hpp" #include "adwaitamm/switchrow.hpp" #include "adwaitamm/toast.hpp" #include "adwaitamm/toastoverlay.hpp" +#include "adwaitamm/windowtitle.hpp" #include @@ -61,6 +63,7 @@ namespace Adwaita WRAP_CLASS(SwitchRow, switch_row); WRAP_CLASS(Toast, toast); WRAP_CLASS(ToastOverlay, toast_overlay); + WRAP_CLASS(WindowTitle, window_title); ENSURE_TYPE(AboutDialog); ENSURE_TYPE(ActionRow); @@ -76,5 +79,6 @@ namespace Adwaita ENSURE_TYPE(SwitchRow); ENSURE_TYPE(Toast); ENSURE_TYPE(ToastOverlay); + ENSURE_TYPE(WindowTitle); } } // namespace Adwaita \ No newline at end of file -- cgit v1.2.3