1 /* dzl-dock-paned.c
2 *
3 * Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #define G_LOG_DOMAIN "dzl-dock-paned"
20
21 #include "config.h"
22
23 #include "dzl-dock-item.h"
24 #include "dzl-dock-paned.h"
25 #include "dzl-dock-paned-private.h"
26 #include "dzl-dock-stack.h"
27
28 typedef struct
29 {
30 GtkPositionType child_edge;
31 } DzlDockPanedPrivate;
32
33 G_DEFINE_TYPE_EXTENDED (DzlDockPaned, dzl_dock_paned, DZL_TYPE_MULTI_PANED, 0,
34 G_ADD_PRIVATE (DzlDockPaned)
35 G_IMPLEMENT_INTERFACE (DZL_TYPE_DOCK_ITEM, NULL))
36
37 static void
dzl_dock_paned_add(GtkContainer * container,GtkWidget * widget)38 dzl_dock_paned_add (GtkContainer *container,
39 GtkWidget *widget)
40 {
41 DzlDockPaned *self = (DzlDockPaned *)container;
42 DzlDockPanedPrivate *priv = dzl_dock_paned_get_instance_private (self);
43
44 g_assert (DZL_IS_DOCK_PANED (self));
45
46 if (DZL_IS_DOCK_STACK (widget))
47 dzl_dock_stack_set_edge (DZL_DOCK_STACK (widget), priv->child_edge);
48
49 GTK_CONTAINER_CLASS (dzl_dock_paned_parent_class)->add (container, widget);
50
51 if (DZL_IS_DOCK_ITEM (widget))
52 {
53 dzl_dock_item_adopt (DZL_DOCK_ITEM (self), DZL_DOCK_ITEM (widget));
54
55 /* Always available, so emit presented */
56 dzl_dock_item_emit_presented (DZL_DOCK_ITEM (widget));
57 }
58 }
59
60 static void
dzl_dock_paned_class_init(DzlDockPanedClass * klass)61 dzl_dock_paned_class_init (DzlDockPanedClass *klass)
62 {
63 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
64 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
65
66 container_class->add = dzl_dock_paned_add;
67
68 gtk_widget_class_set_css_name (widget_class, "dzldockpaned");
69 }
70
71 static void
dzl_dock_paned_init(DzlDockPaned * self)72 dzl_dock_paned_init (DzlDockPaned *self)
73 {
74 DzlDockPanedPrivate *priv = dzl_dock_paned_get_instance_private (self);
75
76 priv->child_edge = GTK_POS_TOP;
77 }
78
79 GtkWidget *
dzl_dock_paned_new(void)80 dzl_dock_paned_new (void)
81 {
82 return g_object_new (DZL_TYPE_DOCK_PANED, NULL);
83 }
84
85 static void
dzl_dock_paned_update_child_edge(GtkWidget * widget,gpointer user_data)86 dzl_dock_paned_update_child_edge (GtkWidget *widget,
87 gpointer user_data)
88 {
89 GtkPositionType child_edge = GPOINTER_TO_INT (user_data);
90
91 g_assert (GTK_IS_WIDGET (widget));
92
93 if (DZL_IS_DOCK_STACK (widget))
94 dzl_dock_stack_set_edge (DZL_DOCK_STACK (widget), child_edge);
95 }
96
97 void
dzl_dock_paned_set_child_edge(DzlDockPaned * self,GtkPositionType child_edge)98 dzl_dock_paned_set_child_edge (DzlDockPaned *self,
99 GtkPositionType child_edge)
100 {
101 DzlDockPanedPrivate *priv = dzl_dock_paned_get_instance_private (self);
102
103 g_return_if_fail (DZL_IS_DOCK_PANED (self));
104
105 if (priv->child_edge != child_edge)
106 {
107 priv->child_edge = child_edge;
108
109 gtk_container_foreach (GTK_CONTAINER (self),
110 dzl_dock_paned_update_child_edge,
111 GINT_TO_POINTER (child_edge));
112 }
113 }
114