2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * ui-sidebar.c: Object property sidebar
6 * Copyright (C) 2003 Jim Evins <evins@snaught.com>.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <libgnomeprint/gnome-font.h>
27 #include "ui-sidebar.h"
29 #include "object-editor.h"
34 /*============================================================================*/
35 /* Private macros and constants. */
36 /*============================================================================*/
38 #define DEFAULT_SIDEBAR_WIDTH 320
40 /*============================================================================*/
42 /*============================================================================*/
44 static GObjectClass *parent_class;
46 static gchar* doc_verbs [] = {
47 "/commands/PropertyEditor",
52 /*============================================================================*/
53 /* Local function prototypes */
54 /*============================================================================*/
56 static void gl_ui_sidebar_class_init (glUISidebarClass *class);
57 static void gl_ui_sidebar_instance_init (glUISidebar *sidebar);
58 static void gl_ui_sidebar_finalize (GObject *object);
60 static void gl_ui_sidebar_construct (glUISidebar *sidebar,
61 BonoboUIComponent *ui_component);
63 static void selection_changed_cb (glView *view,
64 glUISidebar *sidebar);
68 /****************************************************************************/
69 /* Boilerplate Object stuff. */
70 /****************************************************************************/
72 gl_ui_sidebar_get_type (void)
74 static guint sidebar_type = 0;
77 GTypeInfo sidebar_info = {
78 sizeof (glUISidebarClass),
81 (GClassInitFunc) gl_ui_sidebar_class_init,
86 (GInstanceInitFunc) gl_ui_sidebar_instance_init,
90 g_type_register_static (GTK_TYPE_VBOX,
99 gl_ui_sidebar_class_init (glUISidebarClass *class)
101 GObjectClass *object_class = (GObjectClass *) class;
103 gl_debug (DEBUG_UI, "START");
105 parent_class = g_type_class_peek_parent (class);
107 object_class->finalize = gl_ui_sidebar_finalize;
109 gl_debug (DEBUG_UI, "END");
113 gl_ui_sidebar_instance_init (glUISidebar *sidebar)
115 gl_debug (DEBUG_UI, "START");
117 sidebar->view = NULL;
119 gl_debug (DEBUG_UI, "END");
123 gl_ui_sidebar_finalize (GObject *object)
125 glUISidebar *sidebar;
127 gl_debug (DEBUG_UI, "START");
129 g_return_if_fail (object != NULL);
130 g_return_if_fail (GL_IS_UI_SIDEBAR (object));
132 sidebar = GL_UI_SIDEBAR (object);
135 g_object_unref (G_OBJECT(sidebar->view));
139 G_OBJECT_CLASS (parent_class)->finalize (object);
141 gl_debug (DEBUG_UI, "END");
144 /****************************************************************************/
145 /* Create a NEW sidebar. */
146 /****************************************************************************/
148 gl_ui_sidebar_new (BonoboUIComponent *ui_component)
150 glUISidebar *sidebar;
152 gl_debug (DEBUG_UI, "START");
154 sidebar = g_object_new (gl_ui_sidebar_get_type (), NULL);
156 gtk_widget_set_size_request (GTK_WIDGET (sidebar), DEFAULT_SIDEBAR_WIDTH, -1);
158 gl_ui_sidebar_construct (sidebar, ui_component);
160 gl_debug (DEBUG_UI, "END");
162 return G_OBJECT(sidebar);
165 /******************************************************************************/
166 /* Initialize property toolbar. */
167 /******************************************************************************/
169 gl_ui_sidebar_construct (glUISidebar *sidebar,
170 BonoboUIComponent *ui_component)
172 gl_debug (DEBUG_UI, "START");
174 sidebar->ui_component = ui_component;
176 gl_ui_util_insert_widget (ui_component,
177 GTK_WIDGET (sidebar),
178 "/PropertySidebar/PropertyEditor");
180 sidebar->empty_child = gl_object_editor_new (GL_STOCK_PROPERTIES,
181 _("Object properties"),
182 GL_OBJECT_EDITOR_EMPTY,
185 sidebar->child = gtk_widget_ref (sidebar->empty_child);
186 gtk_widget_show (sidebar->child);
187 gtk_container_add (GTK_CONTAINER(sidebar), sidebar->child);
189 gl_ui_util_set_verb_list_sensitive (ui_component, doc_verbs, FALSE);
191 gl_debug (DEBUG_UI, "END");
194 /****************************************************************************/
195 /* Set view associated with sidebar. */
196 /****************************************************************************/
198 gl_ui_sidebar_set_view (glUISidebar *sidebar,
201 gl_debug (DEBUG_UI, "START");
203 g_return_if_fail (view && GL_IS_VIEW (view));
205 gl_ui_util_set_verb_list_sensitive (sidebar->ui_component, doc_verbs, TRUE);
207 sidebar->view = GL_VIEW (g_object_ref (G_OBJECT (view)));
209 g_signal_connect (G_OBJECT(view), "selection_changed",
210 G_CALLBACK(selection_changed_cb), sidebar);
212 gl_debug (DEBUG_UI, "END");
215 /*---------------------------------------------------------------------------*/
216 /* PRIVATE. View "selection state changed" callback. */
217 /*---------------------------------------------------------------------------*/
219 selection_changed_cb (glView *view,
220 glUISidebar *sidebar)
222 gl_debug (DEBUG_UI, "START");
224 g_return_if_fail (view && GL_IS_VIEW (view));
225 g_return_if_fail (sidebar && GL_IS_UI_SIDEBAR (sidebar));
227 gtk_container_remove (GTK_CONTAINER(sidebar), sidebar->child);
229 if (gl_view_is_selection_empty (view) || !gl_view_is_selection_atomic (view)) {
231 sidebar->child = gtk_widget_ref (sidebar->empty_child);
235 sidebar->child = gtk_widget_ref (gl_view_get_editor (view));
239 gtk_widget_show (sidebar->child);
241 gtk_container_add (GTK_CONTAINER(sidebar), sidebar->child);
243 gtk_box_pack_start (GTK_BOX(sidebar), sidebar->child, TRUE, TRUE, 0);
246 gl_debug (DEBUG_UI, "END");