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 "gtkpanedhandleprivate.h" |
24 | #include "gtkwidgetprivate.h" |
25 | #include "gtkcssnodeprivate.h" |
26 | #include "gtkcssstyleprivate.h" |
27 | #include "gtkrendericonprivate.h" |
28 | #include "gtkcssboxesprivate.h" |
29 | #include "gtkintl.h" |
30 | |
31 | #include "gtkpaned.h" |
32 | |
33 | |
34 | G_DEFINE_TYPE (GtkPanedHandle, gtk_paned_handle, GTK_TYPE_WIDGET); |
35 | |
36 | static void |
37 | gtk_paned_handle_snapshot (GtkWidget *widget, |
38 | GtkSnapshot *snapshot) |
39 | { |
40 | GtkCssStyle *style = gtk_css_node_get_style (cssnode: gtk_widget_get_css_node (widget)); |
41 | int width, height; |
42 | |
43 | width = gtk_widget_get_width (widget); |
44 | height = gtk_widget_get_height (widget); |
45 | |
46 | if (width > 0 && height > 0) |
47 | gtk_css_style_snapshot_icon (style, snapshot, width, height); |
48 | } |
49 | |
50 | #define HANDLE_EXTRA_SIZE 6 |
51 | |
52 | static gboolean |
53 | gtk_paned_handle_contains (GtkWidget *widget, |
54 | double x, |
55 | double y) |
56 | { |
57 | GtkWidget *paned; |
58 | GtkCssBoxes boxes; |
59 | graphene_rect_t area; |
60 | |
61 | gtk_css_boxes_init (boxes: &boxes, widget); |
62 | |
63 | graphene_rect_init_from_rect (r: &area, src: gtk_css_boxes_get_border_rect (boxes: &boxes)); |
64 | |
65 | paned = gtk_widget_get_parent (widget); |
66 | if (!gtk_paned_get_wide_handle (GTK_PANED (paned))) |
67 | graphene_rect_inset (r: &area, d_x: - HANDLE_EXTRA_SIZE, d_y: - HANDLE_EXTRA_SIZE); |
68 | |
69 | return graphene_rect_contains_point (r: &area, p: &GRAPHENE_POINT_INIT (x, y)); |
70 | } |
71 | |
72 | static void |
73 | gtk_paned_handle_finalize (GObject *object) |
74 | { |
75 | GtkPanedHandle *self = GTK_PANED_HANDLE (object); |
76 | GtkWidget *widget; |
77 | |
78 | widget = _gtk_widget_get_first_child (GTK_WIDGET (self)); |
79 | while (widget != NULL) |
80 | { |
81 | GtkWidget *next = _gtk_widget_get_next_sibling (widget); |
82 | |
83 | gtk_widget_unparent (widget); |
84 | |
85 | widget = next; |
86 | } |
87 | |
88 | G_OBJECT_CLASS (gtk_paned_handle_parent_class)->finalize (object); |
89 | } |
90 | |
91 | static void |
92 | gtk_paned_handle_class_init (GtkPanedHandleClass *klass) |
93 | { |
94 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
95 | GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
96 | |
97 | object_class->finalize = gtk_paned_handle_finalize; |
98 | |
99 | widget_class->snapshot = gtk_paned_handle_snapshot; |
100 | widget_class->contains = gtk_paned_handle_contains; |
101 | |
102 | gtk_widget_class_set_css_name (widget_class, I_("separator" )); |
103 | } |
104 | |
105 | static void |
106 | gtk_paned_handle_init (GtkPanedHandle *self) |
107 | { |
108 | } |
109 | |
110 | GtkWidget * |
111 | gtk_paned_handle_new (void) |
112 | { |
113 | return g_object_new (GTK_TYPE_PANED_HANDLE, NULL); |
114 | } |
115 | |