summaryrefslogtreecommitdiffstats
path: root/widgets/src/HubWindow.c
blob: 82cd72c97ae9ea529eb31bc8862701ad9aae045e (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
/*
 * Copyright (C) 2011  Red Hat, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Chris Lumens <clumens@redhat.com>
 */

#include "BaseWindow.h"
#include "HubWindow.h"
#include "intl.h"

/**
 * SECTION: HubWindow
 * @title: AnacondaHubWindow
 * @short_description: Window for displaying a Hub
 *
 * A #AnacondaHubWindow is a top-level window that displays a hub on the
 * entire screen.  A Hub allows selection of multiple configuration spokes
 * from a single interface, as well as a place to display current configuration
 * selections.
 *
 * The window consists of three areas:
 *
 * - A navigation area in the top of the screen, inherited from #AnacondaBaseWindow.
 *
 * - A selection area in the middle of the screen, taking up a majority of the space.
 *   This is where spokes will be displayed and the user can decide what to do.
 *
 * - An action area on the bottom of the screen.  This area is different for
 *   different kinds of hubs.  It may have buttons, or it may have progress
 *   information.
 *
 * <refsect2 id="AnacondaHubWindow-BUILDER-UI"><title>AnacondaHubWindow as GtkBuildable</title>
 * <para>
 * The AnacondaHubWindow implementation of the #GtkBuildable interface exposes
 * the @action_area and @scrolled_window as internal children with the names
 * "action_area" and "scrolled_window".  action_area, in this case, is largely
 * there to give a box to contain both the scrolled_window and a #GtkButtonBox.
 * </para>
 * <example>
 * <title>A <structname>AnacondaHubWindow</structname> UI definition fragment.</title>
 * <programlisting><![CDATA[
 * <object class="AnacondaHubWindow" id="hub1">
 *     <child internal-child="action_area">
 *         <object class="GtkVBox" id="vbox1">
 *             <child internal-child="scrolled_window">
 *                 <object class="GtkScrolledWindow" id="window1">
 *                     <child>...</child>
 *                 </object>
 *             </child>
 *             <child>
 *                 <object class="GtkHButtonBox" id="buttonbox1">
 *                     <child>...</child>
 *                 </object>
 *             </child>
 *         </object>
 *     </child>
 * </object>
 * ]]></programlisting>
 * </example>
 * </refsect2>
 */

struct _AnacondaHubWindowPrivate {
    GtkWidget *scrolled_window;
};

static void anaconda_hub_window_buildable_init(GtkBuildableIface *iface);

G_DEFINE_TYPE_WITH_CODE(AnacondaHubWindow, anaconda_hub_window, ANACONDA_TYPE_BASE_WINDOW,
                        G_IMPLEMENT_INTERFACE(GTK_TYPE_BUILDABLE, anaconda_hub_window_buildable_init))

static void anaconda_hub_window_class_init(AnacondaHubWindowClass *klass) {
    GObjectClass *object_class = G_OBJECT_CLASS(klass);

    g_type_class_add_private(object_class, sizeof(AnacondaHubWindowPrivate));
}

/**
 * anaconda_hub_window_new:
 *
 * Creates a new #AnacondaHubWindow, which is a window designed for displaying
 * multiple spokes in one location.
 *
 * Returns: A new #AnacondaHubWindow.
 */
GtkWidget *anaconda_hub_window_new() {
    return g_object_new(ANACONDA_TYPE_HUB_WINDOW, NULL);
}

static void anaconda_hub_window_init(AnacondaHubWindow *win) {
    GtkWidget *action_area = anaconda_base_window_get_action_area(ANACONDA_BASE_WINDOW(win));

    win->priv = G_TYPE_INSTANCE_GET_PRIVATE(win,
                                            ANACONDA_TYPE_HUB_WINDOW,
                                            AnacondaHubWindowPrivate);

    win->priv->scrolled_window = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(win->priv->scrolled_window),
                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
    gtk_box_pack_start(GTK_BOX(action_area), win->priv->scrolled_window, TRUE, TRUE, 0);

    /* The hub has different alignment requirements than a spoke. */
    gtk_alignment_set(GTK_ALIGNMENT(anaconda_base_window_get_alignment(ANACONDA_BASE_WINDOW(win))),
                      0.5, 0.0, 0.5, 0.5);
}

/**
 * anaconda_hub_window_get_spoke_area:
 * @win: a #AnacondaHubWindow
 *
 * Returns the scrolled window of @win where spokes may be displayed
 *
 * Returns: (transfer none): The spoke area
 *
 * Since: 1.0
 */
GtkWidget *anaconda_hub_window_get_spoke_area(AnacondaHubWindow *win) {
    return win->priv->scrolled_window;
}

static GtkBuildableIface *parent_buildable_iface;

static GObject *
anaconda_hub_window_buildable_get_internal_child (GtkBuildable *buildable,
                                                  GtkBuilder *builder,
                                                  const gchar *childname) {
    if (strcmp (childname, "scrolled_window") == 0)
        return G_OBJECT(anaconda_hub_window_get_spoke_area(ANACONDA_HUB_WINDOW(buildable)));

    return parent_buildable_iface->get_internal_child (buildable, builder, childname);
}

static void anaconda_hub_window_buildable_init (GtkBuildableIface *iface) {
    parent_buildable_iface = g_type_interface_peek_parent (iface);
    iface->get_internal_child = anaconda_hub_window_buildable_get_internal_child;
}