]> git.sur5r.net Git - glabels/blob - glabels2/src/ui-sidebar.c
2007-09-14 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / ui-sidebar.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
3 /**
4  *  (GLABELS) Label and Business Card Creation program for GNOME
5  *
6  *  ui-sidebar.c:  Object property sidebar
7  *
8  *  Copyright (C) 2003  Jim Evins <evins@snaught.com>.
9  *
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.
14  *
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.
19  *
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
23  */
24
25 #include <config.h>
26
27 #include "ui-sidebar.h"
28
29 #include <glib/gi18n.h>
30
31 #include "ui-util.h"
32 #include "object-editor.h"
33 #include "stock.h"
34
35 #include "debug.h"
36
37 /*===========================================================================*/
38 /* Private macros and constants.                                             */
39 /*===========================================================================*/
40
41 #define DEFAULT_SIDEBAR_WIDTH 340
42
43 /*===========================================================================*/
44 /* Private data types                                                        */
45 /*===========================================================================*/
46
47 struct _glUISidebarPrivate {
48
49         glView              *view;
50
51         GtkWidget           *child;
52         GtkWidget           *empty_child;
53 };
54
55 /*===========================================================================*/
56 /* Private globals                                                           */
57 /*===========================================================================*/
58
59
60 /*===========================================================================*/
61 /* Local function prototypes                                                 */
62 /*===========================================================================*/
63
64 static void     gl_ui_sidebar_finalize      (GObject              *object);
65
66 static void     gl_ui_sidebar_construct     (glUISidebar          *sidebar);
67
68 static void     selection_changed_cb        (glView               *view,
69                                              glUISidebar          *sidebar);
70
71
72 \f
73 /****************************************************************************/
74 /* Boilerplate Object stuff.                                                */
75 /****************************************************************************/
76 G_DEFINE_TYPE (glUISidebar, gl_ui_sidebar, GTK_TYPE_VBOX);
77
78 static void
79 gl_ui_sidebar_class_init (glUISidebarClass *class)
80 {
81         GObjectClass   *object_class     = G_OBJECT_CLASS (class);
82
83         gl_debug (DEBUG_UI, "START");
84
85         gl_ui_sidebar_parent_class = g_type_class_peek_parent (class);
86
87         object_class->finalize = gl_ui_sidebar_finalize;
88
89         gl_debug (DEBUG_UI, "END");
90 }
91
92 static void
93 gl_ui_sidebar_init (glUISidebar *sidebar)
94 {
95         gl_debug (DEBUG_UI, "START");
96
97         sidebar->priv = g_new0 (glUISidebarPrivate, 1);
98
99         gl_debug (DEBUG_UI, "END");
100 }
101
102 static void
103 gl_ui_sidebar_finalize (GObject *object)
104 {
105         glUISidebar *sidebar = GL_UI_SIDEBAR (object);
106
107         gl_debug (DEBUG_UI, "START");
108
109         g_return_if_fail (object != NULL);
110         g_return_if_fail (GL_IS_UI_SIDEBAR (object));
111
112         if (sidebar->priv->view) {
113                 g_object_unref (G_OBJECT(sidebar->priv->view));
114         }
115         g_free (sidebar->priv);
116
117         G_OBJECT_CLASS (gl_ui_sidebar_parent_class)->finalize (object);
118
119         gl_debug (DEBUG_UI, "END");
120 }
121
122 /****************************************************************************/
123 /* Create a NEW sidebar.                                                    */
124 /****************************************************************************/
125 GtkWidget *
126 gl_ui_sidebar_new (void)
127 {
128         glUISidebar *sidebar;
129
130         gl_debug (DEBUG_UI, "START");
131
132         sidebar = g_object_new (gl_ui_sidebar_get_type (), NULL);
133
134         gtk_widget_set_size_request (GTK_WIDGET (sidebar), DEFAULT_SIDEBAR_WIDTH, -1);
135
136         gl_ui_sidebar_construct (sidebar);
137
138         gl_debug (DEBUG_UI, "END");
139
140         return GTK_WIDGET(sidebar);
141 }
142
143 /******************************************************************************/
144 /* Initialize property toolbar.                                               */
145 /******************************************************************************/
146 static void
147 gl_ui_sidebar_construct (glUISidebar       *sidebar)
148 {
149         gl_debug (DEBUG_UI, "START");
150
151         sidebar->priv->empty_child = gl_object_editor_new (GL_STOCK_PROPERTIES,
152                                                            _("Object properties"),
153                                                            GL_OBJECT_EDITOR_EMPTY,
154                                                            NULL);
155
156         sidebar->priv->child = gtk_widget_ref (sidebar->priv->empty_child);
157         gtk_widget_show (sidebar->priv->child);
158         gtk_container_add (GTK_CONTAINER(sidebar), sidebar->priv->child);
159
160         gtk_widget_set_sensitive (GTK_WIDGET (sidebar), FALSE);
161
162         gl_debug (DEBUG_UI, "END");
163 }
164
165 /****************************************************************************/
166 /* Set view associated with sidebar.                                        */
167 /****************************************************************************/
168 void
169 gl_ui_sidebar_set_view (glUISidebar *sidebar,
170                         glView      *view)
171 {
172         gl_debug (DEBUG_UI, "START");
173
174         g_return_if_fail (view && GL_IS_VIEW (view));
175
176         gtk_widget_set_sensitive (GTK_WIDGET (sidebar), TRUE);
177
178         sidebar->priv->view = GL_VIEW (g_object_ref (G_OBJECT (view)));
179
180         g_signal_connect (G_OBJECT(view), "selection_changed",
181                           G_CALLBACK(selection_changed_cb), sidebar);
182
183         gl_debug (DEBUG_UI, "END");
184 }
185
186 /*---------------------------------------------------------------------------*/
187 /* PRIVATE.  View "selection state changed" callback.                        */
188 /*---------------------------------------------------------------------------*/
189 static void 
190 selection_changed_cb (glView      *view,
191                       glUISidebar *sidebar)
192 {
193         gl_debug (DEBUG_UI, "START");
194
195         g_return_if_fail (view && GL_IS_VIEW (view));
196         g_return_if_fail (sidebar && GL_IS_UI_SIDEBAR (sidebar));
197
198         gtk_container_remove (GTK_CONTAINER(sidebar), sidebar->priv->child);
199
200         if (gl_view_is_selection_empty (view) || !gl_view_is_selection_atomic (view)) {
201
202                 sidebar->priv->child = gtk_widget_ref (sidebar->priv->empty_child);
203                 
204         } else {
205
206                 sidebar->priv->child = gtk_widget_ref (gl_view_get_editor (view));
207
208         }
209
210         gtk_widget_show (sidebar->priv->child);
211
212         gtk_box_pack_start (GTK_BOX(sidebar), sidebar->priv->child, TRUE, TRUE, 0);
213
214         gl_debug (DEBUG_UI, "END");
215 }
216