summaryrefslogtreecommitdiff
path: root/plugins/gtk+/glade-gtk-paned.c
blob: db220766b7361c725407d17806d40b0033eacee8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * glade-gtk-paned.c - GladeWidgetAdaptor for GtkPaned
 *
 * Copyright (C) 2013 Tristan Van Berkom
 *
 * Authors:
 *      Tristan Van Berkom <tristan.van.berkom@gmail.com>
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
#include <config.h>
#include <glib/gi18n-lib.h>
#include <gladeui/glade.h>

void
glade_gtk_paned_post_create (GladeWidgetAdaptor * adaptor,
                             GObject * paned, GladeCreateReason reason)
{
  g_return_if_fail (GTK_IS_PANED (paned));

  if (reason == GLADE_CREATE_USER &&
      gtk_paned_get_child1 (GTK_PANED (paned)) == NULL)
    gtk_paned_add1 (GTK_PANED (paned), glade_placeholder_new ());

  if (reason == GLADE_CREATE_USER &&
      gtk_paned_get_child2 (GTK_PANED (paned)) == NULL)
    gtk_paned_add2 (GTK_PANED (paned), glade_placeholder_new ());
}

void
glade_gtk_paned_add_child (GladeWidgetAdaptor * adaptor,
                           GObject * object, GObject * child)
{
  GtkPaned *paned;
  GtkWidget *child1, *child2;
  gboolean loading;

  g_return_if_fail (GTK_IS_PANED (object));

  paned = GTK_PANED (object);
  loading = glade_util_object_is_loading (object);

  child1 = gtk_paned_get_child1 (paned);
  child2 = gtk_paned_get_child2 (paned);

  if (loading == FALSE)
    {
      /* Remove a placeholder */
      if (child1 && GLADE_IS_PLACEHOLDER (child1))
        {
          gtk_container_remove (GTK_CONTAINER (object), child1);
          child1 = NULL;
        }
      else if (child2 && GLADE_IS_PLACEHOLDER (child2))
        {
          gtk_container_remove (GTK_CONTAINER (object), child2);
          child2 = NULL;
        }
    }

  /* Add the child */
  if (child1 == NULL)
    gtk_paned_add1 (paned, GTK_WIDGET (child));
  else if (child2 == NULL)
    gtk_paned_add2 (paned, GTK_WIDGET (child));

  if (GLADE_IS_PLACEHOLDER (child) == FALSE && loading)
    {
      GladeWidget *gchild = glade_widget_get_from_gobject (child);

      if (gchild && glade_widget_get_packing_properties (gchild))
        {
          if (child1 == NULL)
            glade_widget_pack_property_set (gchild, "first", TRUE);
          else if (child2 == NULL)
            glade_widget_pack_property_set (gchild, "first", FALSE);
        }
    }
}

void
glade_gtk_paned_remove_child (GladeWidgetAdaptor * adaptor,
                              GObject * object, GObject * child)
{
  gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child));

  glade_gtk_paned_post_create (adaptor, object, GLADE_CREATE_USER);
}

void
glade_gtk_paned_set_child_property (GladeWidgetAdaptor * adaptor,
                                    GObject * container,
                                    GObject * child,
                                    const gchar * property_name,
                                    const GValue * value)
{
  if (strcmp (property_name, "first") == 0)
    {
      GtkPaned *paned = GTK_PANED (container);
      gboolean first = g_value_get_boolean (value);
      GtkWidget *place, *wchild = GTK_WIDGET (child);

      place = (first) ? gtk_paned_get_child1 (paned) :
          gtk_paned_get_child2 (paned);

      if (place && GLADE_IS_PLACEHOLDER (place))
        gtk_container_remove (GTK_CONTAINER (container), place);

      g_object_ref (child);
      gtk_container_remove (GTK_CONTAINER (container), wchild);
      if (first)
        gtk_paned_add1 (paned, wchild);
      else
        gtk_paned_add2 (paned, wchild);
      g_object_unref (child);

      /* Ensure placeholders */
      if (glade_util_object_is_loading (child) == FALSE)
        {
          if ((place = gtk_paned_get_child1 (paned)) == NULL)
            gtk_paned_add1 (paned, glade_placeholder_new ());

          if ((place = gtk_paned_get_child2 (paned)) == NULL)
            gtk_paned_add2 (paned, glade_placeholder_new ());
        }
    }
  else
    /* Chain Up */
    GLADE_WIDGET_ADAPTOR_GET_ADAPTOR_CLASS
        (GTK_TYPE_CONTAINER)->child_set_property (adaptor,
                                                  container, child,
                                                  property_name, value);
}

void
glade_gtk_paned_get_child_property (GladeWidgetAdaptor * adaptor,
                                    GObject * container,
                                    GObject * child,
                                    const gchar * property_name, GValue * value)
{
  if (strcmp (property_name, "first") == 0)
    g_value_set_boolean (value, GTK_WIDGET (child) ==
                         gtk_paned_get_child1 (GTK_PANED (container)));
  else
    /* Chain Up */
    GLADE_WIDGET_ADAPTOR_GET_ADAPTOR_CLASS
        (GTK_TYPE_CONTAINER)->child_get_property (adaptor,
                                                  container, child,
                                                  property_name, value);
}