]> git.sur5r.net Git - glabels/blob - src/window.c
Provides barcode even if invalid for correct sizing
[glabels] / src / window.c
1 /*
2  *  window.c
3  *  Copyright (C) 2002-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
7  *  gLabels is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  gLabels is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <config.h>
22
23 #include "window.h"
24
25 #include <glib/gi18n.h>
26 #include <gtk/gtk.h>
27
28 #include "ui.h"
29 #include "ui-commands.h"
30 #include "file-util.h"
31 #include "xml-label.h"
32 #include "prefs.h"
33 #include "file.h"
34 #include "units-util.h"
35
36 #include "debug.h"
37
38
39 /*===========================================================================*/
40 /* Private macros and constants.                                             */
41 /*===========================================================================*/
42
43 #define DEFAULT_WINDOW_WIDTH  788
44 #define DEFAULT_WINDOW_HEIGHT 600
45
46 #define CURSOR_INFO_WIDTH     150
47 #define ZOOM_INFO_WIDTH        50
48
49
50 /*===========================================================================*/
51 /* Private globals                                                           */
52 /*===========================================================================*/
53
54 static GList *window_list = NULL;
55
56
57 /*===========================================================================*/
58 /* Local function prototypes                                                 */
59 /*===========================================================================*/
60
61 static void     gl_window_finalize     (GObject       *object);
62 static void     gl_window_destroy      (GtkObject     *gtk_object);
63
64 static void     set_window_title       (glWindow *window,
65                                         glLabel  *label);
66
67 static gboolean window_delete_event_cb (glWindow      *window,
68                                         GdkEvent      *event,
69                                         gpointer       user_data);
70
71 static void     selection_changed_cb   (glLabel       *label,
72                                         glWindow      *window);
73
74 static void   context_menu_activate_cb (glView       *view,
75                                         gint          button,
76                                         guint32       activate_time,
77                                         glWindow     *window);
78
79 static void     zoom_changed_cb        (glView        *view,
80                                         gdouble        zoom,
81                                         glWindow      *window);
82
83 static void     pointer_moved_cb       (glView        *view,
84                                         gdouble        x,
85                                         gdouble        y,
86                                         glWindow      *window);
87
88 static void     pointer_exit_cb        (glView        *view,
89                                         glWindow      *window);
90
91 static void     name_changed_cb        (glLabel       *label,
92                                         glWindow      *window);
93
94 static void     modified_changed_cb    (glLabel       *label,
95                                         glWindow      *window);
96
97 static void     clipboard_changed_cb   (GtkClipboard  *clipboard,
98                                         GdkEvent      *event,
99                                         glWindow      *window);
100
101 static void     focus_widget_changed_cb(GtkWindow     *gtk_window,
102                                         GtkWidget     *widget,
103                                         glWindow      *window);
104
105 static void     set_copy_paste_sensitivity  (glWindow      *window,
106                                              GtkWidget     *focus_widget);
107
108 static void     label_changed_cb       (glLabel       *label,
109                                         glWindow      *window);
110
111
112 /****************************************************************************/
113 /* Boilerplate Object stuff.                                                */
114 /****************************************************************************/
115 G_DEFINE_TYPE (glWindow, gl_window, GTK_TYPE_WINDOW);
116
117
118 static void
119 gl_window_class_init (glWindowClass *class)
120 {
121         GObjectClass   *object_class     = G_OBJECT_CLASS (class);
122         GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (class);
123
124         gl_debug (DEBUG_WINDOW, "START");
125
126         gl_window_parent_class = g_type_class_peek_parent (class);
127
128         object_class->finalize = gl_window_finalize;
129
130         gtk_object_class->destroy = gl_window_destroy;
131
132         gl_debug (DEBUG_WINDOW, "END");
133 }
134
135
136 static void
137 gl_window_init (glWindow *window)
138 {
139         GtkWidget        *vbox1;
140         GtkUIManager     *ui;
141         GtkWidget        *status_hbox;
142
143         gl_debug (DEBUG_WINDOW, "START");
144
145         vbox1 = gtk_vbox_new (FALSE, 0);
146         gtk_container_add (GTK_CONTAINER (window), vbox1);
147
148         window->ui = ui = gl_ui_new (window);
149         gtk_box_pack_start (GTK_BOX (vbox1),
150                             gtk_ui_manager_get_widget (ui, "/MenuBar"),
151                             FALSE, FALSE, 0);
152         gtk_box_pack_start (GTK_BOX (vbox1),
153                             gtk_ui_manager_get_widget (ui, "/MainToolBar"),
154                             FALSE, FALSE, 0);
155         gtk_box_pack_start (GTK_BOX (vbox1),
156                             gtk_ui_manager_get_widget (ui, "/DrawingToolBar"),
157                             FALSE, FALSE, 0);
158
159         window->hbox = gtk_hbox_new (FALSE, 0);
160         gtk_box_pack_start (GTK_BOX (vbox1), window->hbox, TRUE, TRUE, 0);
161
162         window->sidebar = GL_UI_SIDEBAR (gl_ui_sidebar_new ());
163         gtk_box_pack_end (GTK_BOX (window->hbox), GTK_WIDGET (window->sidebar), FALSE, FALSE, 0);
164
165         window->property_bar = GL_UI_PROPERTY_BAR (gl_ui_property_bar_new ());
166         gtk_box_pack_start (GTK_BOX (vbox1), GTK_WIDGET (window->property_bar), FALSE, FALSE, 0);
167
168         status_hbox = gtk_hbox_new (FALSE, 0);
169         gtk_box_pack_start (GTK_BOX (vbox1), status_hbox, FALSE, FALSE, 0);
170
171         window->status_bar = gtk_statusbar_new ();
172         gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (window->status_bar), FALSE);
173         gtk_box_pack_start (GTK_BOX (status_hbox),
174                             window->status_bar,
175                             TRUE, TRUE, 0);
176         window->zoom_info = gtk_label_new (NULL);
177         gtk_widget_set_size_request (window->zoom_info, ZOOM_INFO_WIDTH, -1);
178         window->zoom_info_frame = gtk_frame_new (NULL);
179         gtk_frame_set_shadow_type (GTK_FRAME(window->zoom_info_frame), GTK_SHADOW_IN);
180         gtk_container_add (GTK_CONTAINER(window->zoom_info_frame), window->zoom_info);
181         gtk_widget_show_all (window->zoom_info_frame);
182         gtk_box_pack_end (GTK_BOX (status_hbox),
183                           window->zoom_info_frame,
184                           FALSE, FALSE, 0);
185
186         window->cursor_info = gtk_label_new (NULL);
187         gtk_widget_set_size_request (window->cursor_info, CURSOR_INFO_WIDTH, -1);
188         window->cursor_info_frame = gtk_frame_new (NULL);
189         gtk_frame_set_shadow_type (GTK_FRAME(window->cursor_info_frame), GTK_SHADOW_IN);
190         gtk_container_add (GTK_CONTAINER(window->cursor_info_frame), window->cursor_info);
191         gtk_widget_show_all (window->cursor_info_frame);
192         gtk_box_pack_end (GTK_BOX (status_hbox),
193                           window->cursor_info_frame,
194                           FALSE, FALSE, 0);
195
196         gtk_window_set_default_size (GTK_WINDOW (window),
197                                      DEFAULT_WINDOW_WIDTH,
198                                      DEFAULT_WINDOW_HEIGHT);
199
200         g_signal_connect (G_OBJECT(window), "delete-event",
201                           G_CALLBACK(window_delete_event_cb), NULL);
202         
203         window->menu_tips_context_id =
204                 gtk_statusbar_get_context_id (GTK_STATUSBAR (window->status_bar), "menu_tips");
205
206         window->print_settings = NULL;
207         window->merge_dialog = NULL;
208         window->context_menu = GTK_MENU (gtk_ui_manager_get_widget (ui, "/ContextMenu"));
209         window->empty_selection_context_menu =
210                 GTK_MENU (gtk_ui_manager_get_widget (ui, "/EmptySelectionContextMenu"));
211
212         window->view = NULL;
213
214         window_list = g_list_append (window_list, window);
215
216         gl_debug (DEBUG_WINDOW, "END");
217 }
218
219
220 static void
221 gl_window_finalize (GObject *object)
222 {
223         gl_debug (DEBUG_WINDOW, "START");
224
225         g_return_if_fail (object != NULL);
226         g_return_if_fail (GL_IS_WINDOW (object));
227
228         G_OBJECT_CLASS (gl_window_parent_class)->finalize (object);
229
230         gl_debug (DEBUG_WINDOW, "END");
231 }
232
233
234 static void
235 gl_window_destroy (GtkObject *gtk_object)
236 {
237         glWindow          *window;
238         GtkClipboard      *clipboard;
239
240         gl_debug (DEBUG_WINDOW, "START");
241
242         g_return_if_fail (gtk_object != NULL);
243         g_return_if_fail (GL_IS_WINDOW (gtk_object));
244
245         window = GL_WINDOW (gtk_object);
246         window_list = g_list_remove (window_list, window);
247
248         if (window->ui) {
249                 gl_ui_unref(window->ui);
250                 window->ui = NULL;
251         }
252
253         if (window->label)
254         {
255                 clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
256                                                       GDK_SELECTION_CLIPBOARD);
257
258                 g_signal_handlers_disconnect_by_func (G_OBJECT (clipboard),
259                                                       G_CALLBACK (clipboard_changed_cb),
260                                                       window);
261
262                 g_object_unref (window->label);
263         }
264
265         if (GTK_OBJECT_CLASS (gl_window_parent_class)->destroy) {
266                 GTK_OBJECT_CLASS (gl_window_parent_class)->destroy (gtk_object);
267         }
268
269         gl_debug (DEBUG_WINDOW, "END");
270 }
271
272
273 /****************************************************************************/
274 /** Create a glabels window.                                                */
275 /****************************************************************************/
276 GtkWidget *
277 gl_window_new (void)
278 {
279         glWindow *window;
280
281         gl_debug (DEBUG_WINDOW, "START");
282
283         window = g_object_new (GL_TYPE_WINDOW,
284                                "title",    _("(none) - gLabels"),
285                                NULL);
286
287         gl_debug (DEBUG_WINDOW, "window=%p", window);
288         gl_debug (DEBUG_WINDOW, "view=%p", window->view);
289
290         gl_debug (DEBUG_WINDOW, "END");
291
292         return GTK_WIDGET(window);
293 }
294
295
296 /****************************************************************************/
297 /** Create a glabels window from a label.                                   */
298 /****************************************************************************/
299 GtkWidget*
300 gl_window_new_from_label (glLabel *label)
301 {
302         glWindow *window;
303
304         gl_debug (DEBUG_WINDOW, "START");
305
306         window = GL_WINDOW (gl_window_new ());
307
308         gl_window_set_label (window, label);
309
310         gl_debug (DEBUG_WINDOW, "END");
311
312         return GTK_WIDGET(window);
313 }
314
315
316 /****************************************************************************/
317 /** Create a glabels window from a glabels file.                            */
318 /****************************************************************************/
319 GtkWidget*
320 gl_window_new_from_file (const gchar *filename)
321 {
322         glWindow         *window;
323         glLabel          *label;
324         gchar            *abs_filename;
325         glXMLLabelStatus  status;
326
327         gl_debug (DEBUG_WINDOW, "START");
328
329         window = GL_WINDOW (gl_window_new ());
330
331         abs_filename = gl_file_util_make_absolute (filename);
332         label = gl_xml_label_open (abs_filename, &status);
333         g_free (abs_filename);
334
335         gl_window_set_label (window, label);
336
337         gl_debug (DEBUG_WINDOW, "END");
338
339         return GTK_WIDGET(window);
340 }
341
342
343 /****************************************************************************/
344 /** Is window empty?                                                        */
345 /****************************************************************************/
346 gboolean
347 gl_window_is_empty (glWindow    *window)
348 {
349         g_return_val_if_fail (GL_IS_WINDOW (window), FALSE);
350
351         gl_debug (DEBUG_WINDOW, "return %d", (window->view == NULL) );
352         return ( window->view == NULL );
353 }
354
355
356 /****************************************************************************/
357 /** Create view from label and place in window.                             */
358 /****************************************************************************/
359 void
360 gl_window_set_label (glWindow    *window,
361                      glLabel     *label)
362 {
363         gchar             *string;
364         GtkClipboard      *clipboard;
365         GtkWidget         *focus_widget;
366
367         gl_debug (DEBUG_WINDOW, "START");
368
369         g_return_if_fail (GL_IS_WINDOW (window));
370         g_return_if_fail (GL_IS_LABEL (label));
371
372         window->label = g_object_ref (label);
373
374         gl_label_clear_modified (label);
375
376         set_window_title (window, label);
377
378         if ( window->view != NULL ) {
379                 gtk_widget_destroy (window->view);
380                 window->view = NULL;
381         }
382
383         window->view = gl_view_new (label);
384         gtk_box_pack_start (GTK_BOX (window->hbox), window->view, TRUE, TRUE, 0);
385
386         gtk_widget_show_all (window->view);
387
388         gl_view_zoom_to_fit (GL_VIEW(window->view));
389
390         if (gl_prefs_model_get_grid_visible (gl_prefs)) {
391                 gl_view_show_grid (GL_VIEW(window->view));
392         } else {
393                 gl_view_hide_grid (GL_VIEW(window->view));
394         }
395
396         if (gl_prefs_model_get_markup_visible (gl_prefs)) {
397                 gl_view_show_markup (GL_VIEW(window->view));
398         } else {
399                 gl_view_hide_markup (GL_VIEW(window->view));
400         }
401
402         gl_ui_update_all (window->ui, GL_VIEW(window->view));
403
404         gl_ui_property_bar_set_label (window->property_bar, window->label);
405         gl_ui_sidebar_set_label (window->sidebar, window->label);
406
407         string = g_strdup_printf ("%3.0f%%",
408                                   100.0*gl_view_get_zoom (GL_VIEW(window->view)));
409         gtk_label_set_text (GTK_LABEL(window->zoom_info), string);
410         g_free (string);
411
412
413         clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
414                                               GDK_SELECTION_CLIPBOARD);
415
416
417         g_signal_connect (G_OBJECT(window->label), "selection_changed",
418                           G_CALLBACK(selection_changed_cb), window);
419
420         g_signal_connect (G_OBJECT(window->view), "context_menu_activate",
421                           G_CALLBACK(context_menu_activate_cb), window);
422
423         g_signal_connect (G_OBJECT(window->view), "zoom_changed",
424                           G_CALLBACK(zoom_changed_cb), window);
425
426         g_signal_connect (G_OBJECT(window->view), "pointer_moved",
427                           G_CALLBACK(pointer_moved_cb), window);
428
429         g_signal_connect (G_OBJECT(window->view), "pointer_exit",
430                           G_CALLBACK(pointer_exit_cb), window);
431
432         g_signal_connect (G_OBJECT(label), "name_changed",
433                           G_CALLBACK(name_changed_cb), window);
434
435         g_signal_connect (G_OBJECT(label), "modified_changed",
436                           G_CALLBACK(modified_changed_cb), window);
437
438         g_signal_connect (G_OBJECT(clipboard), "owner_change",
439                           G_CALLBACK(clipboard_changed_cb), window);
440
441         g_signal_connect (G_OBJECT(window), "set_focus",
442                           G_CALLBACK(focus_widget_changed_cb), window);
443
444         /* Initialize "Paste" sensitivity. */
445         focus_widget = gtk_window_get_focus (GTK_WINDOW (window));
446         set_copy_paste_sensitivity (window, focus_widget);
447
448         g_signal_connect (G_OBJECT(label), "changed",
449                           G_CALLBACK(label_changed_cb), window);
450
451         gl_debug (DEBUG_WINDOW, "END");
452 }
453
454
455 /****************************************************************************/
456 /** Return list of glabels windows.                                         */
457 /****************************************************************************/
458 const GList *
459 gl_window_get_window_list (void)
460 {
461         gl_debug (DEBUG_WINDOW, "");
462         return window_list;
463 }
464
465
466 /*---------------------------------------------------------------------------*/
467 /** PRIVATE.  Set window title based on name and state of label.             */
468 /*---------------------------------------------------------------------------*/
469 static void 
470 set_window_title (glWindow *window,
471                   glLabel  *label)
472 {
473         gchar *name, *title;
474
475         gl_debug (DEBUG_WINDOW, "START");
476
477         g_return_if_fail (window && GL_IS_WINDOW (window));
478         g_return_if_fail (label && GL_IS_LABEL (label));
479
480         name = gl_label_get_short_name (label);
481         g_return_if_fail (name != NULL);
482
483         if (gl_label_is_modified (label)) {
484                 title = g_strdup_printf ("%s %s - gLabels",
485                                          name, _("(modified)"));
486         } else {
487                 title = g_strdup_printf ("%s - gLabels", name);
488         }
489
490         gtk_window_set_title (GTK_WINDOW(window), title);
491
492         g_free (name);
493         g_free (title);
494
495         gl_debug (DEBUG_WINDOW, "END");
496 }
497
498
499 /*-------------------------------------------------------------------------*/
500 /** PRIVATE.  Window "delete-event" callback.                              */
501 /*-------------------------------------------------------------------------*/
502 static gboolean
503 window_delete_event_cb (glWindow      *window,
504                         GdkEvent      *event,
505                         gpointer       user_data)
506 {
507         gl_debug (DEBUG_WINDOW, "START");
508
509         g_return_val_if_fail (window && GL_IS_WINDOW (window), TRUE);
510
511         gl_file_close (window);
512
513         gl_debug (DEBUG_WINDOW, "END");
514
515         return TRUE;
516 }
517
518
519 /*---------------------------------------------------------------------------*/
520 /** PRIVATE.  View "selection state changed" callback.                       */
521 /*---------------------------------------------------------------------------*/
522 static void 
523 selection_changed_cb (glLabel  *label,
524                       glWindow *window)
525 {
526         gl_debug (DEBUG_WINDOW, "START");
527
528         g_return_if_fail (label && GL_IS_LABEL (label));
529         g_return_if_fail (window && GL_IS_WINDOW (window));
530
531         gl_ui_update_selection_verbs (window->ui, GL_VIEW (window->view), TRUE);
532
533         gl_debug (DEBUG_WINDOW, "END");
534 }
535
536
537 /*---------------------------------------------------------------------------*/
538 /** PRIVATE.  View "context menu activate" callback.                         */
539 /*---------------------------------------------------------------------------*/
540 static void
541 context_menu_activate_cb (glView       *view,
542                           gint          button,
543                           guint32       activate_time,
544                           glWindow     *window)
545 {
546         gl_debug (DEBUG_WINDOW, "START");
547
548         g_return_if_fail (view && GL_IS_VIEW (view));
549         g_return_if_fail (window && GL_IS_WINDOW (window));
550
551         if (gl_label_is_selection_empty (view->label)) {
552
553                 gtk_menu_popup (GTK_MENU (window->empty_selection_context_menu),
554                                 NULL, NULL, NULL, NULL, button, activate_time);
555
556         } else {
557
558                 gtk_menu_popup (GTK_MENU (window->context_menu),
559                                 NULL, NULL, NULL, NULL, button, activate_time);
560
561         }
562
563         gl_debug (DEBUG_WINDOW, "END");
564 }
565
566
567 /*---------------------------------------------------------------------------*/
568 /** PRIVATE.  View "zoom state changed" callback.                            */
569 /*---------------------------------------------------------------------------*/
570 static void 
571 zoom_changed_cb (glView   *view,
572                  gdouble   zoom,
573                  glWindow *window)
574 {
575         gchar *string;
576
577         gl_debug (DEBUG_WINDOW, "START");
578
579         g_return_if_fail (view && GL_IS_VIEW (view));
580         g_return_if_fail (window && GL_IS_WINDOW (window));
581
582         string = g_strdup_printf ("%3.0f%%", 100.0*zoom);
583         gtk_label_set_text (GTK_LABEL(window->zoom_info), string);
584         g_free (string);
585
586         gl_ui_update_zoom_verbs (window->ui, view);
587
588         gl_debug (DEBUG_WINDOW, "END");
589 }
590
591
592 /*---------------------------------------------------------------------------*/
593 /** PRIVATE.  View "pointer moved" callback.                                 */
594 /*---------------------------------------------------------------------------*/
595 static void
596 pointer_moved_cb (glView   *view,
597                   gdouble   x,
598                   gdouble   y,
599                   glWindow *window)
600 {
601         gchar    *string;
602         lglUnits  units;
603         gdouble   units_per_point;
604         gint      units_precision;
605
606         gl_debug (DEBUG_WINDOW, "START");
607
608         g_return_if_fail (view && GL_IS_VIEW (view));
609         g_return_if_fail (window && GL_IS_WINDOW (window));
610
611         units = gl_prefs_model_get_units (gl_prefs);
612         units_per_point = lgl_units_get_units_per_point (units);
613         units_precision = gl_units_util_get_precision (units);
614
615         string = g_strdup_printf ("%.*f, %.*f",
616                                   units_precision, x*units_per_point,
617                                   units_precision, y*units_per_point);
618         gtk_label_set_text (GTK_LABEL(window->cursor_info), string);
619         g_free (string);
620
621         gl_debug (DEBUG_WINDOW, "END");
622 }
623
624
625 /*---------------------------------------------------------------------------*/
626 /** PRIVATE.  View "pointer exit" callback.                                  */
627 /*---------------------------------------------------------------------------*/
628 static void
629 pointer_exit_cb (glView   *view,
630                  glWindow *window)
631 {
632         gl_debug (DEBUG_WINDOW, "START");
633
634         g_return_if_fail (view && GL_IS_VIEW (view));
635         g_return_if_fail (window && GL_IS_WINDOW (window));
636
637         gtk_label_set_text (GTK_LABEL(window->cursor_info), "");
638
639         gl_debug (DEBUG_WINDOW, "END");
640 }
641
642
643 /*---------------------------------------------------------------------------*/
644 /** PRIVATE.  Label "name changed" callback.                                 */
645 /*---------------------------------------------------------------------------*/
646 static void 
647 name_changed_cb (glLabel  *label,
648                  glWindow *window)
649 {
650         gl_debug (DEBUG_WINDOW, "START");
651
652         g_return_if_fail (label && GL_IS_LABEL (label));
653         g_return_if_fail (window && GL_IS_WINDOW (window));
654
655         set_window_title (window, label);
656
657         gl_debug (DEBUG_WINDOW, "END");
658 }
659
660
661 /*---------------------------------------------------------------------------*/
662 /** PRIVATE.  Label "modified state changed" callback.                       */
663 /*---------------------------------------------------------------------------*/
664 static void 
665 modified_changed_cb (glLabel  *label,
666                      glWindow *window)
667 {
668         gl_debug (DEBUG_WINDOW, "START");
669
670         g_return_if_fail (label && GL_IS_LABEL (label));
671         g_return_if_fail (window && GL_IS_WINDOW (window));
672
673         set_window_title (window, label);
674
675         gl_ui_update_modified_verbs (window->ui, label);
676
677         gl_debug (DEBUG_WINDOW, "END");
678 }
679
680
681 /*---------------------------------------------------------------------------*/
682 /** PRIVATE.  Label "changed" callback.                                      */
683 /*---------------------------------------------------------------------------*/
684 static void
685 label_changed_cb (glLabel  *label,
686                   glWindow *window)
687 {
688         gl_debug (DEBUG_WINDOW, "START");
689
690         g_return_if_fail (label && GL_IS_LABEL (label));
691         g_return_if_fail (window && GL_IS_WINDOW (window));
692
693         gl_ui_update_undo_redo_verbs (window->ui, label);
694
695         gl_debug (DEBUG_WINDOW, "END");
696 }
697
698
699
700 /*---------------------------------------------------------------------------*/
701 /** PRIVATE.  Clipboard "owner change" callback.                             */
702 /*---------------------------------------------------------------------------*/
703 static void
704 clipboard_changed_cb (GtkClipboard *clipboard,
705                       GdkEvent     *event,
706                       glWindow     *window)
707 {
708         GtkWidget    *focus_widget;
709
710         gl_debug (DEBUG_WINDOW, "START");
711
712         g_return_if_fail (window && GL_IS_WINDOW (window));
713
714         focus_widget = gtk_window_get_focus (GTK_WINDOW (window));
715         set_copy_paste_sensitivity (window, focus_widget);
716
717         gl_debug (DEBUG_WINDOW, "END");
718 }
719
720
721 /*---------------------------------------------------------------------------*/
722 /** PRIVATE.  Window "set-focus" callback.                                   */
723 /*---------------------------------------------------------------------------*/
724 static void
725 focus_widget_changed_cb (GtkWindow *gtk_window,
726                          GtkWidget *widget,
727                          glWindow  *window)
728 {
729         gl_debug (DEBUG_WINDOW, "START");
730
731         g_return_if_fail (window && GL_IS_WINDOW (window));
732
733         if (widget)
734         {
735                 gl_debug (DEBUG_WINDOW, "SET-FOCUS %x %s\n",
736                           widget,
737                           G_OBJECT_TYPE_NAME (widget));
738
739                 set_copy_paste_sensitivity (window, widget);
740         }
741
742         gl_debug (DEBUG_WINDOW, "END");
743 }
744
745
746 /*---------------------------------------------------------------------------*/
747 /** PRIVATE.  Set paste sensitivity.                                         */
748 /*---------------------------------------------------------------------------*/
749 static void
750 set_copy_paste_sensitivity (glWindow  *window,
751                             GtkWidget *focus_widget)
752 {
753         gl_debug (DEBUG_WINDOW, "START");
754
755         g_return_if_fail (window && GL_IS_WINDOW (window));
756
757         if ( focus_widget == GL_VIEW(window->view)->canvas )
758         {
759                 gl_ui_update_selection_verbs (window->ui, GL_VIEW (window->view), TRUE);
760
761                 gl_ui_update_paste_verbs (window->ui, gl_label_can_paste (window->label));
762         }
763         else
764         {
765                 gl_ui_update_selection_verbs (window->ui, GL_VIEW (window->view), FALSE);
766                 gl_ui_update_paste_verbs (window->ui, FALSE);
767         }
768
769         gl_debug (DEBUG_WINDOW, "END");
770 }
771
772
773 /*
774  * Local Variables:       -- emacs
775  * mode: C                -- emacs
776  * c-basic-offset: 8      -- emacs
777  * tab-width: 8           -- emacs
778  * indent-tabs-mode: nil  -- emacs
779  * End:                   -- emacs
780  */