summaryrefslogtreecommitdiff
path: root/adw/src/private/dialog_p.cpp
blob: 7af615afe66627829e29e4c762aae26091c6629d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
 * @author Felix Morgner (felix.morgner@gmail.com)
 * @copyright Copyright (c) 2025
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "adwaitamm/private/dialog_p.hpp"

#include "adwaitamm/dialog.hpp"

#include <glibmm/class.h>
#include <glibmm/exceptionhandler.h>
#include <glibmm/objectbase.h>

#include <gtkmm/object.h>
#include <gtkmm/private/widget_p.h>
#include <gtkmm/shortcutmanager.h>

#include <adwaita.h>
#include <glib-object.h>

namespace Adwaita
{

  auto Dialog_Class::init() -> Glib::Class const &
  {
    if (!gtype_)
    {
      class_init_func_ = &class_init_function;
      register_derived_type(adw_dialog_get_type());
      Gtk::ShortcutManager::add_interface(get_type());
    }
    return *this;
  }

  auto Dialog_Class::class_init_function(void * gclass, void * data) -> void
  {
    auto const klass = static_cast<BaseClassType *>(gclass);
    CppClassParent::class_init_function(klass, data);

    klass->close_attempt = &close_attempt;
    klass->closed = &closed;
  }

  auto Dialog_Class::wrap_new(GObject * object) -> Glib::ObjectBase *
  {
    return Gtk::manage(new Dialog(ADW_DIALOG(object)));
  }

  auto Dialog_Class::close_attempt(BaseObjectType * self) -> void
  {
    auto base_object = static_cast<Glib::ObjectBase *>(Glib::ObjectBase::_get_current_wrapper(G_OBJECT(self)));
    if (base_object && base_object->is_derived_())
    {
      auto object = dynamic_cast<CppObjectType *>(base_object);
      if (object)
      {
        try
        {
          return object->on_close_attempt();
        }
        catch (...)
        {
          Glib::exception_handlers_invoke();
        }
      }
    }

    auto base_class = static_cast<BaseClassType *>(g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)));
    if (base_class && base_class->close_attempt)
    {
      return (base_class->close_attempt)(self);
    }
  }

  auto Dialog_Class::closed(BaseObjectType * self) -> void
  {
    auto base_object = static_cast<Glib::ObjectBase *>(Glib::ObjectBase::_get_current_wrapper(G_OBJECT(self)));
    if (base_object && base_object->is_derived_())
    {
      auto object = dynamic_cast<CppObjectType *>(base_object);
      if (object)
      {
        try
        {
          return object->on_closed();
        }
        catch (...)
        {
          Glib::exception_handlers_invoke();
        }
      }
    }

    auto base_class = static_cast<BaseClassType *>(g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)));
    if (base_class && base_class->closed)
    {
      return (base_class->closed)(self);
    }
  }
}  // namespace Adwaita