1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * ui-sidebar.c: Object property sidebar
8 * Copyright (C) 2003 Jim Evins <evins@snaught.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "ui-sidebar.h"
29 #include <glib/gi18n.h>
32 #include "object-editor.h"
37 /*===========================================================================*/
38 /* Private macros and constants. */
39 /*===========================================================================*/
41 #define DEFAULT_SIDEBAR_WIDTH 340
43 /*===========================================================================*/
44 /* Private data types */
45 /*===========================================================================*/
47 struct _glUISidebarPrivate {
52 GtkWidget *empty_child;
55 /*===========================================================================*/
57 /*===========================================================================*/
60 /*===========================================================================*/
61 /* Local function prototypes */
62 /*===========================================================================*/
64 static void gl_ui_sidebar_finalize (GObject *object);
66 static void gl_ui_sidebar_construct (glUISidebar *sidebar);
68 static void selection_changed_cb (glView *view,
69 glUISidebar *sidebar);
73 /****************************************************************************/
74 /* Boilerplate Object stuff. */
75 /****************************************************************************/
76 G_DEFINE_TYPE (glUISidebar, gl_ui_sidebar, GTK_TYPE_VBOX);
79 gl_ui_sidebar_class_init (glUISidebarClass *class)
81 GObjectClass *object_class = G_OBJECT_CLASS (class);
83 gl_debug (DEBUG_UI, "START");
85 gl_ui_sidebar_parent_class = g_type_class_peek_parent (class);
87 object_class->finalize = gl_ui_sidebar_finalize;
89 gl_debug (DEBUG_UI, "END");
93 gl_ui_sidebar_init (glUISidebar *sidebar)
95 gl_debug (DEBUG_UI, "START");
97 sidebar->priv = g_new0 (glUISidebarPrivate, 1);
99 gl_debug (DEBUG_UI, "END");
103 gl_ui_sidebar_finalize (GObject *object)
105 glUISidebar *sidebar = GL_UI_SIDEBAR (object);
107 gl_debug (DEBUG_UI, "START");
109 g_return_if_fail (object != NULL);
110 g_return_if_fail (GL_IS_UI_SIDEBAR (object));
112 if (sidebar->priv->view) {
113 g_object_unref (G_OBJECT(sidebar->priv->view));
115 g_free (sidebar->priv);
117 G_OBJECT_CLASS (gl_ui_sidebar_parent_class)->finalize (object);
119 gl_debug (DEBUG_UI, "END");
122 /****************************************************************************/
123 /* Create a NEW sidebar. */
124 /****************************************************************************/
126 gl_ui_sidebar_new (void)
128 glUISidebar *sidebar;
130 gl_debug (DEBUG_UI, "START");
132 sidebar = g_object_new (gl_ui_sidebar_get_type (), NULL);
134 gtk_widget_set_size_request (GTK_WIDGET (sidebar), DEFAULT_SIDEBAR_WIDTH, -1);
136 gl_ui_sidebar_construct (sidebar);
138 gl_debug (DEBUG_UI, "END");
140 return GTK_WIDGET(sidebar);
143 /******************************************************************************/
144 /* Initialize property toolbar. */
145 /******************************************************************************/
147 gl_ui_sidebar_construct (glUISidebar *sidebar)
149 gl_debug (DEBUG_UI, "START");
151 sidebar->priv->empty_child = gl_object_editor_new (GL_STOCK_PROPERTIES,
152 _("Object properties"),
154 GL_OBJECT_EDITOR_EMPTY,
157 sidebar->priv->child = gtk_widget_ref (sidebar->priv->empty_child);
158 gtk_widget_show (sidebar->priv->child);
159 gtk_container_add (GTK_CONTAINER(sidebar), sidebar->priv->child);
161 gtk_widget_set_sensitive (GTK_WIDGET (sidebar), FALSE);
163 gl_debug (DEBUG_UI, "END");
166 /****************************************************************************/
167 /* Set view associated with sidebar. */
168 /****************************************************************************/
170 gl_ui_sidebar_set_view (glUISidebar *sidebar,
173 gl_debug (DEBUG_UI, "START");
175 g_return_if_fail (view && GL_IS_VIEW (view));
177 gtk_widget_set_sensitive (GTK_WIDGET (sidebar), TRUE);
179 sidebar->priv->view = GL_VIEW (g_object_ref (G_OBJECT (view)));
181 g_signal_connect (G_OBJECT(view), "selection_changed",
182 G_CALLBACK(selection_changed_cb), sidebar);
184 gl_debug (DEBUG_UI, "END");
187 /*---------------------------------------------------------------------------*/
188 /* PRIVATE. View "selection state changed" callback. */
189 /*---------------------------------------------------------------------------*/
191 selection_changed_cb (glView *view,
192 glUISidebar *sidebar)
194 gl_debug (DEBUG_UI, "START");
196 g_return_if_fail (view && GL_IS_VIEW (view));
197 g_return_if_fail (sidebar && GL_IS_UI_SIDEBAR (sidebar));
199 gtk_container_remove (GTK_CONTAINER(sidebar), sidebar->priv->child);
201 if (gl_view_is_selection_empty (view) || !gl_view_is_selection_atomic (view)) {
203 sidebar->priv->child = gtk_widget_ref (sidebar->priv->empty_child);
207 sidebar->priv->child = gtk_widget_ref (gl_view_get_editor (view));
211 gtk_widget_show (sidebar->priv->child);
213 gtk_box_pack_start (GTK_BOX(sidebar), sidebar->priv->child, TRUE, TRUE, 0);
215 gl_debug (DEBUG_UI, "END");