2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * window.c: a gLabels app window
6 * Copyright (C) 2002 Jim Evins <evins@snaught.com>.
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.
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.
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
28 #include "xml-label.h"
32 /*============================================================================*/
33 /* Private macros and constants. */
34 /*============================================================================*/
36 #define DEFAULT_WINDOW_WIDTH 500
37 #define DEFAULT_WINDOW_HEIGHT 375
39 #define CURSOR_INFO_WIDTH 150
40 #define ZOOM_INFO_WIDTH 50
42 /*============================================================================*/
44 /*============================================================================*/
45 static BonoboWindowClass *parent_class;
47 static GList *window_list = NULL;
50 /*============================================================================*/
51 /* Local function prototypes */
52 /*============================================================================*/
54 static void gl_window_class_init (glWindowClass *class);
55 static void gl_window_init (glWindow *window);
56 static void gl_window_finalize (GObject *object);
57 static void gl_window_destroy (GtkObject *gtk_object);
59 static void set_window_title (glWindow *window,
62 static gboolean window_delete_event_cb (glWindow *window,
66 static void selection_changed_cb (glView *view,
69 static void zoom_changed_cb (glView *view,
73 static void name_changed_cb (glLabel *label,
76 static void modified_changed_cb (glLabel *label,
80 /****************************************************************************/
81 /* Boilerplate Object stuff. */
82 /****************************************************************************/
84 gl_window_get_type (void)
86 static guint window_type = 0;
89 GTypeInfo window_info = {
90 sizeof (glWindowClass),
93 (GClassInitFunc) gl_window_class_init,
98 (GInstanceInitFunc) gl_window_init,
102 g_type_register_static (bonobo_window_get_type (),
111 gl_window_class_init (glWindowClass *class)
113 GObjectClass *object_class = (GObjectClass *) class;
114 GtkObjectClass *gtk_object_class = (GtkObjectClass *) class;
116 gl_debug (DEBUG_WINDOW, "START");
118 parent_class = g_type_class_peek_parent (class);
120 object_class->finalize = gl_window_finalize;
122 gtk_object_class->destroy = gl_window_destroy;
124 gl_debug (DEBUG_WINDOW, "END");
128 gl_window_init (glWindow *window)
130 BonoboUIContainer *ui_container;
131 BonoboUIComponent *ui_component;
133 gl_debug (DEBUG_WINDOW, "START");
135 ui_container = bonobo_window_get_ui_container(BONOBO_WINDOW(window));
136 ui_component = bonobo_ui_component_new_default ();
137 bonobo_ui_component_set_container (ui_component,
138 BONOBO_OBJREF (ui_container),
141 window->cursor_info = gtk_label_new (NULL);
142 gtk_widget_set_size_request (window->cursor_info, CURSOR_INFO_WIDTH, -1);
143 window->cursor_info_frame = gtk_frame_new (NULL);
144 gtk_frame_set_shadow_type (GTK_FRAME(window->cursor_info_frame), GTK_SHADOW_IN);
145 gtk_container_add (GTK_CONTAINER(window->cursor_info_frame), window->cursor_info);
146 gtk_widget_show_all (window->cursor_info_frame);
148 window->zoom_info = gtk_label_new (NULL);
149 gtk_widget_set_size_request (window->zoom_info, ZOOM_INFO_WIDTH, -1);
150 window->zoom_info_frame = gtk_frame_new (NULL);
151 gtk_frame_set_shadow_type (GTK_FRAME(window->zoom_info_frame), GTK_SHADOW_IN);
152 gtk_container_add (GTK_CONTAINER(window->zoom_info_frame), window->zoom_info);
153 gtk_widget_show_all (window->zoom_info_frame);
155 gl_ui_init (ui_component,
156 BONOBO_WINDOW (window),
157 window->cursor_info_frame,
158 window->zoom_info_frame);
160 gtk_window_set_default_size (GTK_WINDOW (window),
161 DEFAULT_WINDOW_WIDTH,
162 DEFAULT_WINDOW_HEIGHT);
164 g_signal_connect (G_OBJECT(window), "delete-event",
165 G_CALLBACK(window_delete_event_cb), NULL);
167 window->uic = ui_component;
170 window_list = g_list_append (window_list, window);
172 gl_debug (DEBUG_WINDOW, "END");
176 gl_window_finalize (GObject *object)
180 gl_debug (DEBUG_WINDOW, "START");
182 g_return_if_fail (object != NULL);
183 g_return_if_fail (GL_IS_WINDOW (object));
185 window = GL_WINDOW (object);
187 G_OBJECT_CLASS (parent_class)->finalize (object);
189 gl_debug (DEBUG_WINDOW, "END");
193 gl_window_destroy (GtkObject *gtk_object)
197 gl_debug (DEBUG_WINDOW, "START");
199 g_return_if_fail (gtk_object != NULL);
200 g_return_if_fail (GL_IS_WINDOW (gtk_object));
202 window = GL_WINDOW (gtk_object);
203 window_list = g_list_remove (window_list, window);
205 if (GTK_OBJECT_CLASS (parent_class)->destroy) {
206 GTK_OBJECT_CLASS (parent_class)->destroy (gtk_object);
209 gl_debug (DEBUG_WINDOW, "END");
213 /****************************************************************************/
214 /* Create an app window. */
215 /****************************************************************************/
221 gl_debug (DEBUG_WINDOW, "START");
223 window = g_object_new (gl_window_get_type (),
224 "win_name", "glabels",
225 "title", _("(none) - glabels"),
228 gl_debug (DEBUG_WINDOW, "window=%p", window);
229 gl_debug (DEBUG_WINDOW, "view=%p", window->view);
231 gl_debug (DEBUG_WINDOW, "END");
233 return GTK_WIDGET(window);
236 /****************************************************************************/
237 /* Create an app window from a label. */
238 /****************************************************************************/
240 gl_window_new_from_label (glLabel *label)
244 gl_debug (DEBUG_WINDOW, "START");
246 window = GL_WINDOW (gl_window_new ());
248 gl_window_set_label (window, label);
250 gl_debug (DEBUG_WINDOW, "END");
252 return GTK_WIDGET(window);
255 /****************************************************************************/
256 /* Create an app window from a file. */
257 /****************************************************************************/
259 gl_window_new_from_file (const gchar *filename)
264 glXMLLabelStatus status;
266 gl_debug (DEBUG_WINDOW, "START");
268 window = GL_WINDOW (gl_window_new ());
270 abs_filename = gl_util_make_absolute (filename);
271 label = gl_xml_label_open (filename, &status);
272 g_free (abs_filename);
274 gl_window_set_label (window, label);
276 gl_debug (DEBUG_WINDOW, "END");
278 return GTK_WIDGET(window);
281 /****************************************************************************/
282 /* Is window empty? */
283 /****************************************************************************/
285 gl_window_is_empty (glWindow *window)
287 g_return_val_if_fail (GL_IS_WINDOW (window), FALSE);
289 gl_debug (DEBUG_WINDOW, "return %d", (window->view == NULL) );
290 return ( window->view == NULL );
293 /****************************************************************************/
294 /* Create view from label and place in window. */
295 /****************************************************************************/
297 gl_window_set_label (glWindow *window,
302 gl_debug (DEBUG_WINDOW, "START");
304 g_return_if_fail (GL_IS_WINDOW (window));
305 g_return_if_fail (GL_IS_LABEL (label));
307 gl_label_clear_modified (label);
309 set_window_title (window, label);
311 if ( window->view != NULL ) {
312 gtk_widget_destroy (window->view);
316 window->view = gl_view_new (label);
317 bonobo_window_set_contents (BONOBO_WINDOW(window), window->view);
319 gtk_widget_show_all (window->view);
321 gl_ui_update_all (window->uic, GL_VIEW(window->view));
323 string = g_strdup_printf ("%3.0f%%",
324 100.0*gl_view_get_zoom (GL_VIEW(window->view)));
325 gtk_label_set_text (GTK_LABEL(window->zoom_info), string);
328 g_signal_connect (G_OBJECT(window->view), "selection_changed",
329 G_CALLBACK(selection_changed_cb), window);
331 g_signal_connect (G_OBJECT(window->view), "zoom_changed",
332 G_CALLBACK(zoom_changed_cb), window);
334 g_signal_connect (G_OBJECT(label), "name_changed",
335 G_CALLBACK(name_changed_cb), window);
337 g_signal_connect (G_OBJECT(label), "modified_changed",
338 G_CALLBACK(modified_changed_cb), window);
340 gl_debug (DEBUG_WINDOW, "END");
343 /****************************************************************************/
344 /* Return list of app windows. */
345 /****************************************************************************/
347 gl_window_get_window_list (void)
349 gl_debug (DEBUG_WINDOW, "");
353 /*---------------------------------------------------------------------------*/
354 /* PRIVATE. Set window title based on name and state of label. */
355 /*---------------------------------------------------------------------------*/
357 set_window_title (glWindow *window,
362 gl_debug (DEBUG_WINDOW, "START");
364 g_return_if_fail (window && GL_IS_WINDOW (window));
365 g_return_if_fail (label && GL_IS_LABEL (label));
367 name = gl_label_get_short_name (label);
368 g_return_if_fail (name != NULL);
370 if (gl_label_is_modified (label)) {
371 title = g_strdup_printf ("%s %s - glabels",
372 name, _("(modified)"));
374 title = g_strdup_printf ("%s - glabels", name);
377 gtk_window_set_title (GTK_WINDOW(window), title);
382 gl_debug (DEBUG_WINDOW, "END");
385 /*-------------------------------------------------------------------------*/
386 /* PRIVATE. Window "delete-event" callback. */
387 /*-------------------------------------------------------------------------*/
389 window_delete_event_cb (glWindow *window,
393 gl_debug (DEBUG_WINDOW, "START");
395 g_return_val_if_fail (window && GL_IS_WINDOW (window), TRUE);
397 gl_file_close (window);
399 gl_debug (DEBUG_WINDOW, "END");
404 /*---------------------------------------------------------------------------*/
405 /* PRIVATE. View "selection state changed" callback. */
406 /*---------------------------------------------------------------------------*/
408 selection_changed_cb (glView *view,
411 gl_debug (DEBUG_WINDOW, "START");
413 g_return_if_fail (view && GL_IS_VIEW (view));
414 g_return_if_fail (window && GL_IS_WINDOW (window));
416 gl_ui_update_selection_verbs (window->uic, view);
418 gl_debug (DEBUG_WINDOW, "END");
421 /*---------------------------------------------------------------------------*/
422 /* PRIVATE. View "zoom state changed" callback. */
423 /*---------------------------------------------------------------------------*/
425 zoom_changed_cb (glView *view,
431 gl_debug (DEBUG_WINDOW, "START");
433 g_return_if_fail (view && GL_IS_VIEW (view));
434 g_return_if_fail (window && GL_IS_WINDOW (window));
436 string = g_strdup_printf ("%3.0f%%", 100.0*zoom);
437 gtk_label_set_text (GTK_LABEL(window->zoom_info), string);
440 gl_debug (DEBUG_WINDOW, "END");
443 /*---------------------------------------------------------------------------*/
444 /* PRIVATE. Label "name changed" callback. */
445 /*---------------------------------------------------------------------------*/
447 name_changed_cb (glLabel *label,
450 gl_debug (DEBUG_WINDOW, "START");
452 g_return_if_fail (label && GL_IS_LABEL (label));
453 g_return_if_fail (window && GL_IS_WINDOW (window));
455 set_window_title (window, label);
457 gl_debug (DEBUG_WINDOW, "END");
460 /*---------------------------------------------------------------------------*/
461 /* PRIVATE. Label "modified state changed" callback. */
462 /*---------------------------------------------------------------------------*/
464 modified_changed_cb (glLabel *label,
467 gl_debug (DEBUG_WINDOW, "START");
469 g_return_if_fail (label && GL_IS_LABEL (label));
470 g_return_if_fail (window && GL_IS_WINDOW (window));
472 set_window_title (window, label);
474 gl_ui_update_modified_verbs (window->uic, label);
476 gl_debug (DEBUG_WINDOW, "END");