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