]> git.sur5r.net Git - glabels/blob - glabels2/src/ui-sidebar.c
2005-04-17 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / ui-sidebar.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  ui-sidebar.c:  Object property sidebar
5  *
6  *  Copyright (C) 2003  Jim Evins <evins@snaught.com>.
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include <config.h>
24
25 #include "ui-sidebar.h"
26
27 #include <glib/gi18n.h>
28 #include <libgnomeprint/gnome-font.h>
29
30 #include "ui-util.h"
31 #include "object-editor.h"
32 #include "stock.h"
33
34 #include "debug.h"
35
36 /*============================================================================*/
37 /* Private macros and constants.                                              */
38 /*============================================================================*/
39
40 #define DEFAULT_SIDEBAR_WIDTH 320
41
42 /*============================================================================*/
43 /* Private globals                                                            */
44 /*============================================================================*/
45
46 static GObjectClass *parent_class;
47
48 static gchar* doc_verbs [] = {
49         "/commands/PropertyEditor",
50
51         NULL
52 };
53
54 /*============================================================================*/
55 /* Local function prototypes                                                  */
56 /*============================================================================*/
57
58 static void     gl_ui_sidebar_class_init    (glUISidebarClass     *class);
59 static void     gl_ui_sidebar_instance_init (glUISidebar          *sidebar);
60 static void     gl_ui_sidebar_finalize      (GObject              *object);
61
62 static void     gl_ui_sidebar_construct     (glUISidebar          *sidebar,
63                                              BonoboUIComponent    *ui_component);
64
65 static void     selection_changed_cb        (glView               *view,
66                                              glUISidebar          *sidebar);
67
68
69 \f
70 /****************************************************************************/
71 /* Boilerplate Object stuff.                                                */
72 /****************************************************************************/
73 GType
74 gl_ui_sidebar_get_type (void)
75 {
76         static GType type = 0;
77
78         if (!type) {
79                 static const GTypeInfo info = {
80                         sizeof (glUISidebarClass),
81                         NULL,
82                         NULL,
83                         (GClassInitFunc) gl_ui_sidebar_class_init,
84                         NULL,
85                         NULL,
86                         sizeof (glUISidebar),
87                         0,
88                         (GInstanceInitFunc) gl_ui_sidebar_instance_init,
89                         NULL
90                 };
91
92                 type = g_type_register_static (GTK_TYPE_VBOX,
93                                                "glUISidebar", &info, 0);
94         }
95
96         return type;
97 }
98
99 static void
100 gl_ui_sidebar_class_init (glUISidebarClass *class)
101 {
102         GObjectClass   *object_class     = (GObjectClass *) class;
103
104         gl_debug (DEBUG_UI, "START");
105
106         parent_class = g_type_class_peek_parent (class);
107
108         object_class->finalize = gl_ui_sidebar_finalize;
109
110         gl_debug (DEBUG_UI, "END");
111 }
112
113 static void
114 gl_ui_sidebar_instance_init (glUISidebar *sidebar)
115 {
116         gl_debug (DEBUG_UI, "START");
117
118         sidebar->view = NULL;
119
120         gl_debug (DEBUG_UI, "END");
121 }
122
123 static void
124 gl_ui_sidebar_finalize (GObject *object)
125 {
126         glUISidebar *sidebar;
127
128         gl_debug (DEBUG_UI, "START");
129
130         g_return_if_fail (object != NULL);
131         g_return_if_fail (GL_IS_UI_SIDEBAR (object));
132
133         sidebar = GL_UI_SIDEBAR (object);
134
135         if (sidebar->view) {
136                 g_object_unref (G_OBJECT(sidebar->view));
137                 sidebar = NULL;
138         }
139
140         G_OBJECT_CLASS (parent_class)->finalize (object);
141
142         gl_debug (DEBUG_UI, "END");
143 }
144
145 /****************************************************************************/
146 /* Create a NEW sidebar.                                                    */
147 /****************************************************************************/
148 GObject *
149 gl_ui_sidebar_new (BonoboUIComponent *ui_component)
150 {
151         glUISidebar *sidebar;
152
153         gl_debug (DEBUG_UI, "START");
154
155         sidebar = g_object_new (gl_ui_sidebar_get_type (), NULL);
156
157         gtk_widget_set_size_request (GTK_WIDGET (sidebar), DEFAULT_SIDEBAR_WIDTH, -1);
158
159         gl_ui_sidebar_construct (sidebar, ui_component);
160
161         gl_debug (DEBUG_UI, "END");
162
163         return G_OBJECT(sidebar);
164 }
165
166 /******************************************************************************/
167 /* Initialize property toolbar.                                               */
168 /******************************************************************************/
169 static void
170 gl_ui_sidebar_construct (glUISidebar       *sidebar,
171                          BonoboUIComponent *ui_component)
172 {
173         gl_debug (DEBUG_UI, "START");
174
175         sidebar->ui_component = ui_component;
176
177         gl_ui_util_insert_widget (ui_component,
178                                   GTK_WIDGET (sidebar),
179                                   "/PropertySidebar/PropertyEditor");
180
181         sidebar->empty_child = gl_object_editor_new (GL_STOCK_PROPERTIES,
182                                                      _("Object properties"),
183                                                      GL_OBJECT_EDITOR_EMPTY,
184                                                      NULL);
185
186         sidebar->child = gtk_widget_ref (sidebar->empty_child);
187         gtk_widget_show (sidebar->child);
188         gtk_container_add (GTK_CONTAINER(sidebar), sidebar->child);
189
190         gl_ui_util_set_verb_list_sensitive (ui_component, doc_verbs, FALSE);
191
192         gl_debug (DEBUG_UI, "END");
193 }
194
195 /****************************************************************************/
196 /* Set view associated with sidebar.                                        */
197 /****************************************************************************/
198 void
199 gl_ui_sidebar_set_view (glUISidebar *sidebar,
200                         glView      *view)
201 {
202         gl_debug (DEBUG_UI, "START");
203
204         g_return_if_fail (view && GL_IS_VIEW (view));
205
206         gl_ui_util_set_verb_list_sensitive (sidebar->ui_component, doc_verbs, TRUE);
207
208         sidebar->view = GL_VIEW (g_object_ref (G_OBJECT (view)));
209
210         g_signal_connect (G_OBJECT(view), "selection_changed",
211                           G_CALLBACK(selection_changed_cb), sidebar);
212
213         gl_debug (DEBUG_UI, "END");
214 }
215
216 /*---------------------------------------------------------------------------*/
217 /* PRIVATE.  View "selection state changed" callback.                        */
218 /*---------------------------------------------------------------------------*/
219 static void 
220 selection_changed_cb (glView      *view,
221                       glUISidebar *sidebar)
222 {
223         gl_debug (DEBUG_UI, "START");
224
225         g_return_if_fail (view && GL_IS_VIEW (view));
226         g_return_if_fail (sidebar && GL_IS_UI_SIDEBAR (sidebar));
227
228         gtk_container_remove (GTK_CONTAINER(sidebar), sidebar->child);
229
230         if (gl_view_is_selection_empty (view) || !gl_view_is_selection_atomic (view)) {
231
232                 sidebar->child = gtk_widget_ref (sidebar->empty_child);
233                 
234         } else {
235
236                 sidebar->child = gtk_widget_ref (gl_view_get_editor (view));
237
238         }
239
240         gtk_widget_show (sidebar->child);
241 #if 0
242         gtk_container_add (GTK_CONTAINER(sidebar), sidebar->child);
243 #else
244         gtk_box_pack_start (GTK_BOX(sidebar), sidebar->child, TRUE, TRUE, 0);
245 #endif
246
247         gl_debug (DEBUG_UI, "END");
248 }
249