1 | /* |
2 | * Copyright © 2018 Benjamin Otte |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2.1 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | * |
17 | * Authors: Benjamin Otte <otte@gnome.org> |
18 | */ |
19 | |
20 | #include "config.h" |
21 | |
22 | #include "gtkrootprivate.h" |
23 | #include "gtknative.h" |
24 | #include "gtknativeprivate.h" |
25 | #include "gtkcssnodeprivate.h" |
26 | #include "gtkwidgetprivate.h" |
27 | #include "gdk/gdk-private.h" |
28 | #include "gtkprivate.h" |
29 | #include "gtkintl.h" |
30 | |
31 | #include "gtkshortcutmanager.h" |
32 | |
33 | /** |
34 | * GtkRoot: |
35 | * |
36 | * `GtkRoot` is the interface implemented by all widgets that can act as a toplevel |
37 | * widget. |
38 | * |
39 | * The root widget takes care of providing the connection to the windowing system |
40 | * and manages layout, drawing and event delivery for its widget hierarchy. |
41 | * |
42 | * The obvious example of a `GtkRoot` is `GtkWindow`. |
43 | * |
44 | * To get the display to which a `GtkRoot` belongs, use |
45 | * [method@Gtk.Root.get_display]. |
46 | * |
47 | * `GtkRoot` also maintains the location of keyboard focus inside its widget |
48 | * hierarchy, with [method@Gtk.Root.set_focus] and [method@Gtk.Root.get_focus]. |
49 | */ |
50 | |
51 | G_DEFINE_INTERFACE_WITH_CODE (GtkRoot, gtk_root, GTK_TYPE_WIDGET, |
52 | g_type_interface_add_prerequisite (g_define_type_id, GTK_TYPE_NATIVE)) |
53 | |
54 | static GdkDisplay * |
55 | gtk_root_default_get_display (GtkRoot *self) |
56 | { |
57 | return gdk_display_get_default (); |
58 | } |
59 | |
60 | |
61 | static GtkConstraintSolver * |
62 | gtk_root_default_get_constraint_solver (GtkRoot *self) |
63 | { |
64 | return NULL; |
65 | } |
66 | |
67 | static GtkWidget * |
68 | gtk_root_default_get_focus (GtkRoot *self) |
69 | { |
70 | return NULL; |
71 | } |
72 | |
73 | static void |
74 | gtk_root_default_set_focus (GtkRoot *self, |
75 | GtkWidget *focus) |
76 | { |
77 | } |
78 | |
79 | static void |
80 | gtk_root_default_init (GtkRootInterface *iface) |
81 | { |
82 | iface->get_display = gtk_root_default_get_display; |
83 | iface->get_constraint_solver = gtk_root_default_get_constraint_solver; |
84 | iface->get_focus = gtk_root_default_get_focus; |
85 | iface->set_focus = gtk_root_default_set_focus; |
86 | } |
87 | |
88 | /** |
89 | * gtk_root_get_display: |
90 | * @self: a `GtkRoot` |
91 | * |
92 | * Returns the display that this `GtkRoot` is on. |
93 | * |
94 | * Returns: (transfer none): the display of @root |
95 | */ |
96 | GdkDisplay * |
97 | gtk_root_get_display (GtkRoot *self) |
98 | { |
99 | GtkRootInterface *iface; |
100 | |
101 | g_return_val_if_fail (GTK_IS_ROOT (self), NULL); |
102 | |
103 | iface = GTK_ROOT_GET_IFACE (ptr: self); |
104 | return iface->get_display (self); |
105 | } |
106 | |
107 | GtkConstraintSolver * |
108 | gtk_root_get_constraint_solver (GtkRoot *self) |
109 | { |
110 | GtkRootInterface *iface; |
111 | |
112 | g_return_val_if_fail (GTK_IS_ROOT (self), NULL); |
113 | |
114 | iface = GTK_ROOT_GET_IFACE (ptr: self); |
115 | return iface->get_constraint_solver (self); |
116 | } |
117 | |
118 | /** |
119 | * gtk_root_set_focus: |
120 | * @self: a `GtkRoot` |
121 | * @focus: (nullable): widget to be the new focus widget, or %NULL |
122 | * to unset the focus widget |
123 | * |
124 | * If @focus is not the current focus widget, and is focusable, sets |
125 | * it as the focus widget for the root. |
126 | * |
127 | * If @focus is %NULL, unsets the focus widget for the root. |
128 | * |
129 | * To set the focus to a particular widget in the root, it is usually |
130 | * more convenient to use [method@Gtk.Widget.grab_focus] instead of |
131 | * this function. |
132 | */ |
133 | void |
134 | gtk_root_set_focus (GtkRoot *self, |
135 | GtkWidget *focus) |
136 | { |
137 | g_return_if_fail (GTK_IS_ROOT (self)); |
138 | g_return_if_fail (focus == NULL || GTK_IS_WIDGET (focus)); |
139 | |
140 | GTK_ROOT_GET_IFACE (ptr: self)->set_focus (self, focus); |
141 | } |
142 | |
143 | /** |
144 | * gtk_root_get_focus: |
145 | * @self: a `GtkRoot` |
146 | * |
147 | * Retrieves the current focused widget within the root. |
148 | * |
149 | * Note that this is the widget that would have the focus |
150 | * if the root is active; if the root is not focused then |
151 | * `gtk_widget_has_focus (widget)` will be %FALSE for the |
152 | * widget. |
153 | * |
154 | * Returns: (nullable) (transfer none): the currently focused widget |
155 | */ |
156 | GtkWidget * |
157 | gtk_root_get_focus (GtkRoot *self) |
158 | { |
159 | g_return_val_if_fail (GTK_IS_ROOT (self), NULL); |
160 | |
161 | return GTK_ROOT_GET_IFACE (ptr: self)->get_focus (self); |
162 | } |
163 | |
164 | void |
165 | gtk_root_start_layout (GtkRoot *self) |
166 | { |
167 | gtk_native_queue_relayout (native: GTK_NATIVE (ptr: self)); |
168 | } |
169 | |
170 | void |
171 | gtk_root_stop_layout (GtkRoot *self) |
172 | { |
173 | } |
174 | |
175 | void |
176 | gtk_root_queue_restyle (GtkRoot *self) |
177 | { |
178 | gtk_root_start_layout (self); |
179 | } |
180 | |