Debian Codegraph @

gtk/src/window.ccg

raw
1 /* Copyright (C) 1998-2002 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
15 */
16
17 #include <glibmm/vectorutils.h>
18
19 #include <gtkmm/accelgroup.h>
20 #include <gdkmm/cursor.h>
21 #include <gtk/gtk.h>
22
23
24 namespace Gtk
25 {
26
27 _DEPRECATE_IFDEF_START
28 Glib::RefPtr<AccelGroup> Window::get_accel_group()
29 {
30 if(!accel_group_)
31 {
32 accel_group_ = AccelGroup::create();
33 add_accel_group(accel_group_);
34 }
35
36 return accel_group_;
37 }
38 _DEPRECATE_IFDEF_END
39
40 std::vector< Glib::RefPtr<AccelGroup> > Window::get_accel_groups()
41 {
42 return Glib::SListHandler< Glib::RefPtr<AccelGroup> >::slist_to_vector(
43 gtk_accel_groups_from_object(G_OBJECT(gobj())), Glib::OWNERSHIP_NONE);
44 }
45
46 void Window::raise()
47 {
48 get_window()->raise();
49 }
50
51 void Window::set_manage()
52 {
53 g_warning("gtkmm: Attempt to call Gtk::manage() on a Gtk::Window, but a Gtk::Window has no parent container to manage its lifetime.\n");
54 }
55
56 void Window::destroy_()
57 {
58 //Called from destructors.
59 //overridden so that the correct _release_c_instance() ends up being called by the destructor.
60 //destroy_() is virtual, but _release_c_instance() is not.
61
62 //GTKMM_LIFECYCLE
63
64 #ifdef GLIBMM_DEBUG_REFCOUNTING
65 g_warning("Gtk::Window::destroy_(): gobject_: %p\n", (void*) gobject_);
66 if(gobject_)
67 g_warning(" gtypename: %s\n", G_OBJECT_TYPE_NAME(gobject_));
68 #endif
69
70 if ( !cpp_destruction_in_progress_ )
71 {
72 cpp_destruction_in_progress_ = true;
73
74 //destroy the C instance:
75 _release_c_instance();
76 }
77
78 //The C++ destructor will be reached later. This function was called by a destructor.
79 }
80
81 void Window::_release_c_instance()
82 {
83 //We override this, (though it's not virtual - we just call it from this class),
84 //because top-level windows can only be destroyed with gtk_widget_destroy, according to Owen Taylor. murrayc.
85 #ifdef GLIBMM_DEBUG_REFCOUNTING
86 g_warning("Gtk::Window::_release_c_instance() gobject_=%p\n", (void*) gobject_);
87 #endif
88
89 cpp_destruction_in_progress_ = true;
90
91 // remove our hook.
92 GtkWidget* object = GTK_WIDGET(gobj());
93 if (object)
94 {
95 //We can't do anything with the gobject_ if it's already been disposed.
96 //This prevents us from unref-ing it again, or destroying it again after GTK+ has told us that it has been disposed.
97 if (!gobject_disposed_)
98 {
99 //Windows can not be unrefed. They are "self-owning".
100 gtk_widget_destroy(object);
101 }
102
103 //If the GObject still exists, disconnect the C++ wrapper from it.
104 //The C++ wrapper is being deleted right now.
105 disconnect_cpp_wrapper();
106
107 //Glib::Object::~Object() will not g_object_unref() it too, because gobject_ is now 0.
108 }
109 }
110
111 void Window_Class::dispose_vfunc_callback(GObject* self)
112 {
113 //Avoid disposal of Windows on delete_event (window close) signal.
114
115 #ifdef GLIBMM_DEBUG_REFCOUNTING
116 g_warning("Window_Class::dispose_vfunc_callback(): gobject_: %p\n", (void*)self);
117 #endif
118
119 const auto obj = dynamic_cast<Widget*>(
120 Glib::ObjectBase::_get_current_wrapper(self));
121
122 // This function might be invoked recursively because we're triggering
123 // several signal emissions, particularly signal_hide(). Therefore we
124 // have to test for cpp_destruction_in_progress_ at this point.
125
126 if(obj && !obj->_cpp_destruction_is_in_progress()) //When it should really be destroyed, we zero gobj_.
127 {
128 const auto pWidget = obj->gobj();
129 g_return_if_fail(pWidget == GTK_WIDGET(self));
130
131 // Abort dispose if the widget isn't managed, in order to prevent
132 // the nasty self-destroying behaviour of GTK+. This applies to:
133 //
134 // - GtkWindow, if it received "delete_event"
135 // - GtkDialog, which destroys on "response" by default
136
137 #ifdef GLIBMM_DEBUG_REFCOUNTING
138 g_warning("Window_Class::dispose_vfunc_callback(): before gtk_widget_hide().");
139 #endif
140
141 // Now hide the widget. The C++ object must _not_ be accessed anymore
142 // after this call, because a signal_hide() handler might delete it.
143 gtk_widget_hide(pWidget);
144
145 #ifdef GLIBMM_DEBUG_REFCOUNTING
146 g_warning("Window_Class::dispose_vfunc_callback(): after gtk_widget_hide().");
147 #endif
148
149 // GTKMM_LIFECYCLE
150 return; // Prevent calling of normal C dispose vfunc (see below)
151 }
152 else
153 {
154 #ifdef GLIBMM_DEBUG_REFCOUNTING
155 //g_warning("Window_Class::dispose_vfunc_callback(): unreferenced: before gtk_widget_hide().");
156 #endif
157
158 // Always hide widgets on object destruction, regardless of whether
159 // the widget is managed or not. This is done for consistency so that
160 // connecting to signal_hide() is guaranteed to work.
161 //gtk_widget_hide(pWidget);
162
163 #ifdef GLIBMM_DEBUG_REFCOUNTING
164 //g_warning("Window_Class::dispose_vfunc_callback(): unreferenced: after gtk_widget_hide().");
165 #endif
166
167 const auto base = static_cast<GObjectClass*>(
168 g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)));
169
170 #ifdef GLIBMM_DEBUG_REFCOUNTING
171 g_warning("Window_Class::dispose_vfunc_callback(): before calling base->dispose.");
172 #endif
173
174 if(base->dispose)
175 (*base->dispose)(self);
176
177 #ifdef GLIBMM_DEBUG_REFCOUNTING
178 g_warning("Window_Class::dispose_vfunc_callback(): after calling base->dispose.");
179 #endif
180 }
181 }
182
183 void Window::unset_focus()
184 {
185 gtk_window_set_focus(gobj(), nullptr /* See GTK+ docs */);
186 }
187
188 void Window::unset_default()
189 {
190 gtk_window_set_default(gobj(), nullptr /* See GTK+ docs */);
191 }
192
193 void Window::unset_transient_for()
194 {
195 gtk_window_set_transient_for(gobj(), nullptr /* See GTK+ docs */);
196 }
197
198 void Window::unset_attached_to()
199 {
200 gtk_window_set_attached_to(gobj(), nullptr /* See GTK+ docs */);
201 }
202
203 void Window::unset_application()
204 {
205 gtk_window_set_application(gobj(), nullptr /* See GTK+ docs */);
206 }
207
208 #ifndef GTKMM_DISABLE_DEPRECATED
209 // This works. The base class GtkWidget contains the opacity property.
210 Glib::PropertyProxy< double > Window::property_opacity()
211 {
212 return Glib::PropertyProxy< double >(this, "opacity");
213 }
214
215 Glib::PropertyProxy_ReadOnly< double > Window::property_opacity() const
216 {
217 return Glib::PropertyProxy_ReadOnly< double >(this, "opacity");
218 }
219 #endif // GTKMM_DISABLE_DEPRECATED
220
221 } // namespace Gtk