]> git.sur5r.net Git - glabels/blob - src/ui-sidebar.c
Imported Upstream version 2.2.8
[glabels] / 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                                                            NULL,
154                                                            GL_OBJECT_EDITOR_EMPTY,
155                                                            NULL);
156
157         sidebar->priv->child = gtk_widget_ref (sidebar->priv->empty_child);
158         gtk_widget_show (sidebar->priv->child);
159         gtk_container_add (GTK_CONTAINER(sidebar), sidebar->priv->child);
160
161         gtk_widget_set_sensitive (GTK_WIDGET (sidebar), FALSE);
162
163         gl_debug (DEBUG_UI, "END");
164 }
165
166 /****************************************************************************/
167 /* Set view associated with sidebar.                                        */
168 /****************************************************************************/
169 void
170 gl_ui_sidebar_set_view (glUISidebar *sidebar,
171                         glView      *view)
172 {
173         gl_debug (DEBUG_UI, "START");
174
175         g_return_if_fail (view && GL_IS_VIEW (view));
176
177         gtk_widget_set_sensitive (GTK_WIDGET (sidebar), TRUE);
178
179         sidebar->priv->view = GL_VIEW (g_object_ref (G_OBJECT (view)));
180
181         g_signal_connect (G_OBJECT(view), "selection_changed",
182                           G_CALLBACK(selection_changed_cb), sidebar);
183
184         gl_debug (DEBUG_UI, "END");
185 }
186
187 /*---------------------------------------------------------------------------*/
188 /* PRIVATE.  View "selection state changed" callback.                        */
189 /*---------------------------------------------------------------------------*/
190 static void 
191 selection_changed_cb (glView      *view,
192                       glUISidebar *sidebar)
193 {
194         gl_debug (DEBUG_UI, "START");
195
196         g_return_if_fail (view && GL_IS_VIEW (view));
197         g_return_if_fail (sidebar && GL_IS_UI_SIDEBAR (sidebar));
198
199         gtk_container_remove (GTK_CONTAINER(sidebar), sidebar->priv->child);
200
201         if (gl_view_is_selection_empty (view) || !gl_view_is_selection_atomic (view)) {
202
203                 sidebar->priv->child = gtk_widget_ref (sidebar->priv->empty_child);
204                 
205         } else {
206
207                 sidebar->priv->child = gtk_widget_ref (gl_view_get_editor (view));
208
209         }
210
211         gtk_widget_show (sidebar->priv->child);
212
213         gtk_box_pack_start (GTK_BOX(sidebar), sidebar->priv->child, TRUE, TRUE, 0);
214
215         gl_debug (DEBUG_UI, "END");
216 }
217