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