1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; 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>
30 #include <libgnomeprint/gnome-font.h>
33 #include "object-editor.h"
38 /*============================================================================*/
39 /* Private macros and constants. */
40 /*============================================================================*/
42 #define DEFAULT_SIDEBAR_WIDTH 340
44 /*============================================================================*/
45 /* Private data types */
46 /*============================================================================*/
48 struct _glUISidebarPrivate {
53 GtkWidget *empty_child;
56 /*============================================================================*/
58 /*============================================================================*/
60 static GtkVBoxClass *parent_class;
62 /*============================================================================*/
63 /* Local function prototypes */
64 /*============================================================================*/
66 static void gl_ui_sidebar_class_init (glUISidebarClass *class);
67 static void gl_ui_sidebar_instance_init (glUISidebar *sidebar);
68 static void gl_ui_sidebar_finalize (GObject *object);
70 static void gl_ui_sidebar_construct (glUISidebar *sidebar);
72 static void selection_changed_cb (glView *view,
73 glUISidebar *sidebar);
77 /****************************************************************************/
78 /* Boilerplate Object stuff. */
79 /****************************************************************************/
81 gl_ui_sidebar_get_type (void)
83 static GType type = 0;
86 static const GTypeInfo info = {
87 sizeof (glUISidebarClass),
90 (GClassInitFunc) gl_ui_sidebar_class_init,
95 (GInstanceInitFunc) gl_ui_sidebar_instance_init,
99 type = g_type_register_static (GTK_TYPE_VBOX,
100 "glUISidebar", &info, 0);
107 gl_ui_sidebar_class_init (glUISidebarClass *class)
109 GObjectClass *object_class = (GObjectClass *) class;
111 gl_debug (DEBUG_UI, "START");
113 parent_class = g_type_class_peek_parent (class);
115 object_class->finalize = gl_ui_sidebar_finalize;
117 gl_debug (DEBUG_UI, "END");
121 gl_ui_sidebar_instance_init (glUISidebar *sidebar)
123 gl_debug (DEBUG_UI, "START");
125 sidebar->priv = g_new0 (glUISidebarPrivate, 1);
127 gl_debug (DEBUG_UI, "END");
131 gl_ui_sidebar_finalize (GObject *object)
133 glUISidebar *sidebar;
135 gl_debug (DEBUG_UI, "START");
137 g_return_if_fail (object != NULL);
138 g_return_if_fail (GL_IS_UI_SIDEBAR (object));
140 sidebar = GL_UI_SIDEBAR (object);
142 if (sidebar->priv->view) {
143 g_object_unref (G_OBJECT(sidebar->priv->view));
146 G_OBJECT_CLASS (parent_class)->finalize (object);
148 g_free (sidebar->priv);
150 gl_debug (DEBUG_UI, "END");
153 /****************************************************************************/
154 /* Create a NEW sidebar. */
155 /****************************************************************************/
157 gl_ui_sidebar_new (void)
159 glUISidebar *sidebar;
161 gl_debug (DEBUG_UI, "START");
163 sidebar = g_object_new (gl_ui_sidebar_get_type (), NULL);
165 gtk_widget_set_size_request (GTK_WIDGET (sidebar), DEFAULT_SIDEBAR_WIDTH, -1);
167 gl_ui_sidebar_construct (sidebar);
169 gl_debug (DEBUG_UI, "END");
171 return GTK_WIDGET(sidebar);
174 /******************************************************************************/
175 /* Initialize property toolbar. */
176 /******************************************************************************/
178 gl_ui_sidebar_construct (glUISidebar *sidebar)
180 gl_debug (DEBUG_UI, "START");
182 sidebar->priv->empty_child = gl_object_editor_new (GL_STOCK_PROPERTIES,
183 _("Object properties"),
184 GL_OBJECT_EDITOR_EMPTY,
187 sidebar->priv->child = gtk_widget_ref (sidebar->priv->empty_child);
188 gtk_widget_show (sidebar->priv->child);
189 gtk_container_add (GTK_CONTAINER(sidebar), sidebar->priv->child);
191 gtk_widget_set_sensitive (GTK_WIDGET (sidebar), FALSE);
193 gl_debug (DEBUG_UI, "END");
196 /****************************************************************************/
197 /* Set view associated with sidebar. */
198 /****************************************************************************/
200 gl_ui_sidebar_set_view (glUISidebar *sidebar,
203 gl_debug (DEBUG_UI, "START");
205 g_return_if_fail (view && GL_IS_VIEW (view));
207 gtk_widget_set_sensitive (GTK_WIDGET (sidebar), TRUE);
209 sidebar->priv->view = GL_VIEW (g_object_ref (G_OBJECT (view)));
211 g_signal_connect (G_OBJECT(view), "selection_changed",
212 G_CALLBACK(selection_changed_cb), sidebar);
214 gl_debug (DEBUG_UI, "END");
217 /*---------------------------------------------------------------------------*/
218 /* PRIVATE. View "selection state changed" callback. */
219 /*---------------------------------------------------------------------------*/
221 selection_changed_cb (glView *view,
222 glUISidebar *sidebar)
224 gl_debug (DEBUG_UI, "START");
226 g_return_if_fail (view && GL_IS_VIEW (view));
227 g_return_if_fail (sidebar && GL_IS_UI_SIDEBAR (sidebar));
229 gtk_container_remove (GTK_CONTAINER(sidebar), sidebar->priv->child);
231 if (gl_view_is_selection_empty (view) || !gl_view_is_selection_atomic (view)) {
233 sidebar->priv->child = gtk_widget_ref (sidebar->priv->empty_child);
237 sidebar->priv->child = gtk_widget_ref (gl_view_get_editor (view));
241 gtk_widget_show (sidebar->priv->child);
243 gtk_box_pack_start (GTK_BOX(sidebar), sidebar->priv->child, TRUE, TRUE, 0);
245 gl_debug (DEBUG_UI, "END");