1 | /* GTK - The GIMP Toolkit |
2 | * Copyright (C) 2021 Red Hat, Inc. |
3 | * |
4 | * Authors: |
5 | * - Matthias Clasen <mclasen@redhat.com> |
6 | * |
7 | * This library is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU Lesser General Public |
9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. |
11 | * |
12 | * This library is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | * Lesser General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU Lesser General Public |
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
19 | */ |
20 | |
21 | #include "config.h" |
22 | |
23 | #include "gtkpopovercontentprivate.h" |
24 | #include "gtkstylecontextprivate.h" |
25 | |
26 | #include "gtkwidgetprivate.h" |
27 | #include "gtkintl.h" |
28 | |
29 | /* A private class used as the child of GtkPopover. The only thing |
30 | * special here is that we need to queue a resize on the popover when |
31 | * our shadow changes. |
32 | */ |
33 | |
34 | G_DEFINE_TYPE (GtkPopoverContent, gtk_popover_content, GTK_TYPE_WIDGET); |
35 | |
36 | static void |
37 | gtk_popover_content_css_changed (GtkWidget *widget, |
38 | GtkCssStyleChange *change) |
39 | { |
40 | GTK_WIDGET_CLASS (gtk_popover_content_parent_class)->css_changed (widget, change); |
41 | |
42 | if (change == NULL || |
43 | gtk_css_style_change_changes_property (change, id: GTK_CSS_PROPERTY_BOX_SHADOW)) |
44 | gtk_widget_queue_resize (widget: gtk_widget_get_parent (widget)); |
45 | } |
46 | |
47 | static void |
48 | gtk_popover_content_finalize (GObject *object) |
49 | { |
50 | GtkPopoverContent *self = GTK_POPOVER_CONTENT (object); |
51 | GtkWidget *widget; |
52 | |
53 | widget = _gtk_widget_get_first_child (GTK_WIDGET (self)); |
54 | while (widget != NULL) |
55 | { |
56 | GtkWidget *next = _gtk_widget_get_next_sibling (widget); |
57 | |
58 | gtk_widget_unparent (widget); |
59 | |
60 | widget = next; |
61 | } |
62 | |
63 | G_OBJECT_CLASS (gtk_popover_content_parent_class)->finalize (object); |
64 | } |
65 | |
66 | static void |
67 | gtk_popover_content_class_init (GtkPopoverContentClass *klass) |
68 | { |
69 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
70 | GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
71 | |
72 | object_class->finalize = gtk_popover_content_finalize; |
73 | |
74 | widget_class->focus = gtk_widget_focus_child; |
75 | widget_class->grab_focus = gtk_widget_grab_focus_child; |
76 | widget_class->css_changed = gtk_popover_content_css_changed; |
77 | |
78 | gtk_widget_class_set_css_name (widget_class, I_("contents" )); |
79 | } |
80 | |
81 | static void |
82 | gtk_popover_content_init (GtkPopoverContent *self) |
83 | { |
84 | } |
85 | |
86 | GtkWidget * |
87 | gtk_popover_content_new (void) |
88 | { |
89 | return g_object_new (GTK_TYPE_POPOVER_CONTENT, NULL); |
90 | } |
91 | |