From 3a4e781aa4ec052b819a33ba27e2f6a5b78696ff Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 27 Mar 2025 19:44:46 +0100 Subject: adw: add more dialog functions --- adw/include/turns/adw/breakpoint.hpp | 3 +- adw/include/turns/adw/dialog.hpp | 12 +++++-- adw/include/turns/adw/helpers/gobj_mixin.hpp | 2 +- adw/src/breakpoint.cpp | 5 +++ adw/src/dialog.cpp | 50 +++++++++++++++++++++++++--- 5 files changed, 63 insertions(+), 9 deletions(-) diff --git a/adw/include/turns/adw/breakpoint.hpp b/adw/include/turns/adw/breakpoint.hpp index b274bbb..e5dabe3 100644 --- a/adw/include/turns/adw/breakpoint.hpp +++ b/adw/include/turns/adw/breakpoint.hpp @@ -84,19 +84,20 @@ namespace turns::adw using helpers::gobj_mixin::gobj; using helpers::gobj_mixin::gobj_copy; - explicit Breakpoint(BreakpointCondition & condition); Breakpoint(Breakpoint const & other) = delete; Breakpoint(Breakpoint && other) noexcept = default; auto operator=(Breakpoint const & other) noexcept -> Breakpoint & = delete; auto operator=(Breakpoint && other) noexcept -> Breakpoint & = default; + auto static create(BreakpointCondition & condition) -> Glib::RefPtr; auto static get_type() -> GType; auto static get_base_type() -> GType; auto property_condition() -> Glib::PropertyProxy; protected: + explicit Breakpoint(BreakpointCondition & condition); explicit Breakpoint(Glib::ConstructParams const & params); explicit Breakpoint(BaseObjectType * gobj); }; diff --git a/adw/include/turns/adw/dialog.hpp b/adw/include/turns/adw/dialog.hpp index 316a218..3536dfa 100644 --- a/adw/include/turns/adw/dialog.hpp +++ b/adw/include/turns/adw/dialog.hpp @@ -55,8 +55,16 @@ namespace turns::adw auto static get_type() -> GType; auto static get_base_type() -> GType; - auto add_breakpoint(adw::Breakpoint && breakpoint) -> void; + auto add_breakpoint(Glib::RefPtr const & breakpoint) -> void; auto close() -> void; + auto force_close() -> void; + auto get_can_close() const -> bool; + auto get_child() const -> Gtk::Widget *; + auto get_content_height() const -> int; + auto get_content_width() const -> int; + auto get_current_breakpoint() const -> Glib::RefPtr; + auto get_default_widget() const -> Gtk::Widget *; + auto get_focus() const -> Gtk::Widget *; auto present(Gtk::Widget * parent) -> void; auto set_title(Glib::ustring const & str) -> void; @@ -68,7 +76,7 @@ namespace turns::adw namespace Glib { - auto wrap(AdwDialog * object, bool copy = false) -> Glib::RefPtr; + auto wrap(AdwDialog * object, bool copy = false) -> turns::adw::Dialog *; } // namespace Glib #endif \ No newline at end of file diff --git a/adw/include/turns/adw/helpers/gobj_mixin.hpp b/adw/include/turns/adw/helpers/gobj_mixin.hpp index d9e5097..67600cf 100644 --- a/adw/include/turns/adw/helpers/gobj_mixin.hpp +++ b/adw/include/turns/adw/helpers/gobj_mixin.hpp @@ -28,7 +28,7 @@ namespace turns::adw::helpers using gobj_type = std::conditional_t, std::add_const_t, Glib::Object>; static_cast(self).reference(); - return self.gobj(); + return const_cast(self.gobj()); } }; diff --git a/adw/src/breakpoint.cpp b/adw/src/breakpoint.cpp index eb857ad..dd930a3 100644 --- a/adw/src/breakpoint.cpp +++ b/adw/src/breakpoint.cpp @@ -134,6 +134,11 @@ namespace turns::adw { } + auto Breakpoint::create(BreakpointCondition & condition) -> Glib::RefPtr + { + return Glib::make_refptr_for_instance(new Breakpoint(condition)); + } + auto Breakpoint::get_type() -> GType { return _class.init().get_type(); diff --git a/adw/src/dialog.cpp b/adw/src/dialog.cpp index 8047d65..868ad22 100644 --- a/adw/src/dialog.cpp +++ b/adw/src/dialog.cpp @@ -74,10 +74,10 @@ namespace turns::adw { } - auto Dialog::add_breakpoint(adw::Breakpoint && breakpoint) -> void + auto Dialog::add_breakpoint(Glib::RefPtr const & breakpoint) -> void { - breakpoint.reference(); - adw_dialog_add_breakpoint(Glib::unwrap(this), Glib::unwrap(&breakpoint)); + // Take a copy because the dialog will take ownership of the breakpoint. + adw_dialog_add_breakpoint(Glib::unwrap(this), Glib::unwrap_copy(breakpoint)); } auto Dialog::close() -> void @@ -85,6 +85,46 @@ namespace turns::adw adw_dialog_close(Glib::unwrap(this)); } + auto Dialog::force_close() -> void + { + adw_dialog_force_close(Glib::unwrap(this)); + } + + auto Dialog::get_can_close() const -> bool + { + return adw_dialog_get_can_close(const_cast(Glib::unwrap(this))); + } + + auto Dialog::get_child() const -> Gtk::Widget * + { + return Glib::wrap(adw_dialog_get_child(const_cast(Glib::unwrap(this))), true); + } + + auto Dialog::get_content_height() const -> int + { + return adw_dialog_get_content_height(const_cast(Glib::unwrap(this))); + } + + auto Dialog::get_content_width() const -> int + { + return adw_dialog_get_content_width(const_cast(Glib::unwrap(this))); + } + + auto Dialog::get_current_breakpoint() const -> Glib::RefPtr + { + return Glib::wrap(adw_dialog_get_current_breakpoint(const_cast(Glib::unwrap(this))), true); + } + + auto Dialog::get_default_widget() const -> Gtk::Widget * + { + return Glib::wrap(adw_dialog_get_default_widget(const_cast(Glib::unwrap(this)))); + } + + auto Dialog::get_focus() const -> Gtk::Widget * + { + return Glib::wrap(adw_dialog_get_focus(const_cast(Glib::unwrap(this)))); + } + auto Dialog::present(Gtk::Widget * parent) -> void { adw_dialog_present(Glib::unwrap(this), Glib::unwrap(parent)); @@ -99,8 +139,8 @@ namespace turns::adw namespace Glib { - auto wrap(AdwDialog * object, bool copy) -> Glib::RefPtr + auto wrap(AdwDialog * object, bool copy) -> turns::adw::Dialog * { - return Glib::make_refptr_for_instance(dynamic_cast(Glib::wrap_auto(G_OBJECT(object), copy))); + return dynamic_cast(Glib::wrap_auto(G_OBJECT(object), copy)); } } // namespace Glib \ No newline at end of file -- cgit v1.2.3