From cfdd17795f804b342a1551d517a44ae60f47e917 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 15 May 2005 00:12:15 +0000 Subject: [PATCH] 2005-05-14 Jim Evins * src/Makefile.am: Removed obsolete macros. * src/marshal.list: Added marshalling template to support new view signal: "context_menu_activate." * src/view.h: * src/view.c: (gl_view_class_init), (gl_view_construct), (canvas_event_arrow_mode): - Removed hardcoded context menus and added new signal "context_menu_activate" to push this up to the uimanager. - Removed merge properties and print dialogs so that they can be managed with the window by the uimanager. * src/merge-properties-dialog.h: * src/merge-properties-dialog.c: (gl_merge_properties_dialog_new), (gl_merge_properties_dialog_construct): Changed calling convention of gl_merge_properties_dialog_new() to use glLabel and GtkWindow instead of view to make more consistent with other dialogs. * src/print-dialog.h: * src/print-dialog.c: (gl_print_dialog_new), (gl_print_dialog_construct): Removed last artifact of libbonoboui. * src/ui-commands.c: (gl_ui_cmd_file_print), (gl_ui_cmd_objects_merge_properties), (gl_ui_cmd_help_about): Reconciled style for launching dialogs. * src/ui.c: (gl_ui_new): Added context menus to ui manager. * src/view-object.c: (item_event_arrow_mode): No longer try to select objects with right-click. * src/window.h: * src/window.c: (gl_window_init), (gl_window_set_label), (context_menu_activate_cb): Context menus and all dialogs are now managed in a consistent way in window by the ui manager. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@532 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/ChangeLog | 36 +++ glabels2/src/Makefile.am | 5 - glabels2/src/marshal.list | 1 + glabels2/src/merge-properties-dialog.c | 26 +- glabels2/src/merge-properties-dialog.h | 8 +- glabels2/src/print-dialog.c | 8 +- glabels2/src/print-dialog.h | 6 +- glabels2/src/ui-commands.c | 41 +++- glabels2/src/ui.c | 38 +++ glabels2/src/view-object.c | 15 +- glabels2/src/view.c | 318 ++----------------------- glabels2/src/view.h | 28 +-- glabels2/src/window.c | 45 +++- glabels2/src/window.h | 31 ++- 14 files changed, 231 insertions(+), 375 deletions(-) diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index e6644679..eaf630da 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,39 @@ +2005-05-14 Jim Evins + + * src/Makefile.am: + Removed obsolete macros. + * src/marshal.list: + Added marshalling template to support new view signal: "context_menu_activate." + * src/view.h: + * src/view.c: (gl_view_class_init), (gl_view_construct), + (canvas_event_arrow_mode): + - Removed hardcoded context menus and added new signal "context_menu_activate" + to push this up to the uimanager. + - Removed merge properties and print dialogs so that they can be managed with + the window by the uimanager. + * src/merge-properties-dialog.h: + * src/merge-properties-dialog.c: (gl_merge_properties_dialog_new), + (gl_merge_properties_dialog_construct): + Changed calling convention of gl_merge_properties_dialog_new() to use + glLabel and GtkWindow instead of view to make more consistent with other + dialogs. + * src/print-dialog.h: + * src/print-dialog.c: (gl_print_dialog_new), + (gl_print_dialog_construct): + Removed last artifact of libbonoboui. + * src/ui-commands.c: (gl_ui_cmd_file_print), + (gl_ui_cmd_objects_merge_properties), (gl_ui_cmd_help_about): + Reconciled style for launching dialogs. + * src/ui.c: (gl_ui_new): + Added context menus to ui manager. + * src/view-object.c: (item_event_arrow_mode): + No longer try to select objects with right-click. + * src/window.h: + * src/window.c: (gl_window_init), (gl_window_set_label), + (context_menu_activate_cb): + Context menus and all dialogs are now managed in a consistent way in window + by the ui manager. + 2005-05-11 Jim Evins * src/window.h: diff --git a/glabels2/src/Makefile.am b/glabels2/src/Makefile.am index 5833c8ee..fb9d6e9d 100644 --- a/glabels2/src/Makefile.am +++ b/glabels2/src/Makefile.am @@ -4,10 +4,6 @@ SUBDIRS= pixmaps stock-pixmaps mygal recent-files bin_PROGRAMS = glabels glabels-batch -uidir = $(datadir)/glabels/ui/ -gladedir = $(datadir)/glabels/glade/ - - INCLUDES = \ -I$(top_srcdir) \ -I$(top_builddir) \ @@ -18,7 +14,6 @@ INCLUDES = \ -DDATADIR=\""$(datadir)"\" \ -DLIBDIR=\""$(libdir)"\" \ -DGLABELS_LOCALEDIR=\""$(datadir)/locale"\" \ - -DGLABELS_UI_DIR=\""$(datadir)/glabels/ui/"\" \ -DGLABELS_GLADE_DIR=\""$(datadir)/glabels/glade/"\" \ $(DISABLE_DEPRECATED_CFLAGS) diff --git a/glabels2/src/marshal.list b/glabels2/src/marshal.list index 44979604..019f5a6e 100644 --- a/glabels2/src/marshal.list +++ b/glabels2/src/marshal.list @@ -2,6 +2,7 @@ VOID:VOID VOID:BOOLEAN VOID:INT VOID:INT,INT +VOID:INT,UINT VOID:INT,DOUBLE VOID:DOUBLE VOID:DOUBLE,DOUBLE diff --git a/glabels2/src/merge-properties-dialog.c b/glabels2/src/merge-properties-dialog.c index 0a90d8f1..04c92905 100644 --- a/glabels2/src/merge-properties-dialog.c +++ b/glabels2/src/merge-properties-dialog.c @@ -1,3 +1,5 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + /* * (GLABELS) Label and Business Card Creation program for GNOME * @@ -33,7 +35,7 @@ #include #include -#include "view.h" +#include "label.h" #include "merge.h" #include "util.h" @@ -47,7 +49,6 @@ struct _glMergePropertiesDialogPrivate { GladeXML *gui; - glView *view; glLabel *label; glMerge *merge; @@ -92,7 +93,8 @@ static void gl_merge_properties_dialog_class_init (glMergePropertiesDialogClass static void gl_merge_properties_dialog_init (glMergePropertiesDialog *dlg); static void gl_merge_properties_dialog_finalize (GObject *object); static void gl_merge_properties_dialog_construct (glMergePropertiesDialog *dialog, - glView *view); + glLabel *label, + GtkWindow *window); static void type_changed_cb (GtkWidget *widget, glMergePropertiesDialog *dialog); @@ -209,7 +211,8 @@ gl_merge_properties_dialog_finalize (GObject *object) /* NEW merge properties dialog. */ /*****************************************************************************/ GtkWidget* -gl_merge_properties_dialog_new (glView *view) +gl_merge_properties_dialog_new (glLabel *label, + GtkWindow *window) { GtkWidget *dialog; @@ -218,7 +221,7 @@ gl_merge_properties_dialog_new (glView *view) dialog = GTK_WIDGET (g_object_new (GL_TYPE_MERGE_PROPERTIES_DIALOG, NULL)); gl_merge_properties_dialog_construct (GL_MERGE_PROPERTIES_DIALOG (dialog), - view); + label, window); gl_debug (DEBUG_MERGE, "END"); @@ -230,7 +233,8 @@ gl_merge_properties_dialog_new (glView *view) /*--------------------------------------------------------------------------*/ static void gl_merge_properties_dialog_construct (glMergePropertiesDialog *dialog, - glView *view) + glLabel *label, + GtkWindow *window) { gchar *description; glMergeSrcType src_type; @@ -252,6 +256,11 @@ gl_merge_properties_dialog_construct (glMergePropertiesDialog *dialog, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); + if (window) { + gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(window)); + gtk_window_set_destroy_with_parent (GTK_WINDOW(dialog), TRUE); + } + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); g_signal_connect(G_OBJECT (dialog), "response", @@ -275,8 +284,7 @@ gl_merge_properties_dialog_construct (glMergePropertiesDialog *dialog, gl_util_combo_box_add_text_model (GTK_COMBO_BOX (dialog->priv->type_combo)); - dialog->priv->view = view; - dialog->priv->label = view->label; + dialog->priv->label = label; dialog->priv->merge = gl_label_get_merge (dialog->priv->label); description = gl_merge_get_description (dialog->priv->merge); @@ -284,7 +292,7 @@ gl_merge_properties_dialog_construct (glMergePropertiesDialog *dialog, src = gl_merge_get_src (dialog->priv->merge); /* --- Window title --- */ - name = gl_label_get_short_name (view->label); + name = gl_label_get_short_name (label); title = g_strdup_printf ("%s %s", name, _("Merge Properties")); gtk_window_set_title (GTK_WINDOW (dialog), title); g_free (name); diff --git a/glabels2/src/merge-properties-dialog.h b/glabels2/src/merge-properties-dialog.h index eb5a7a9b..3fcc28a5 100644 --- a/glabels2/src/merge-properties-dialog.h +++ b/glabels2/src/merge-properties-dialog.h @@ -1,3 +1,5 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + /* * (GLABELS) Label and Business Card Creation program for GNOME * @@ -23,7 +25,8 @@ #define __MERGE_PROPERTIES_DIALOG_H__ #include -#include "view.h" +#include +#include "label.h" G_BEGIN_DECLS @@ -55,7 +58,8 @@ struct _glMergePropertiesDialogClass GType gl_merge_properties_dialog_get_type (void) G_GNUC_CONST; -GtkWidget *gl_merge_properties_dialog_new (glView *view); +GtkWidget *gl_merge_properties_dialog_new (glLabel *label, + GtkWindow *window); G_END_DECLS diff --git a/glabels2/src/print-dialog.c b/glabels2/src/print-dialog.c index a1240c96..f0a5edbb 100644 --- a/glabels2/src/print-dialog.c +++ b/glabels2/src/print-dialog.c @@ -1,3 +1,5 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + /* * (GLABELS) Label and Business Card Creation program for GNOME * @@ -88,7 +90,7 @@ static void gl_print_dialog_finalize (GObject *object); static void gl_print_dialog_construct (glPrintDialog *dialog, glLabel *label, - BonoboWindow *win); + GtkWindow *win); static GtkWidget *job_page_new (glPrintDialog *dialog, glLabel *label); @@ -235,7 +237,7 @@ gl_print_dialog_finalize (GObject *object) /*****************************************************************************/ GtkWidget * gl_print_dialog_new (glLabel *label, - BonoboWindow *win) + GtkWindow *win) { GtkWidget *dialog; @@ -254,7 +256,7 @@ gl_print_dialog_new (glLabel *label, static void gl_print_dialog_construct (glPrintDialog *dialog, glLabel *label, - BonoboWindow *win) + GtkWindow *win) { GtkWidget *notebook, *page; gchar *name, *title; diff --git a/glabels2/src/print-dialog.h b/glabels2/src/print-dialog.h index efbce897..5f909503 100644 --- a/glabels2/src/print-dialog.h +++ b/glabels2/src/print-dialog.h @@ -1,3 +1,5 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + /* * (GLABELS) Label and Business Card Creation program for GNOME * @@ -22,7 +24,7 @@ #ifndef __PRINT_DIALOG_H__ #define __PRINT_DIALOG_H__ -#include +#include #include "hig.h" #include "view.h" @@ -58,7 +60,7 @@ struct _glPrintDialogClass GType gl_print_dialog_get_type (void) G_GNUC_CONST; GtkWidget *gl_print_dialog_new (glLabel *label, - BonoboWindow *win); + GtkWindow *win); void gl_print_dialog_force_outline_flag (glPrintDialog *dialog); diff --git a/glabels2/src/ui-commands.c b/glabels2/src/ui-commands.c index ef528ebc..6a9802ed 100644 --- a/glabels2/src/ui-commands.c +++ b/glabels2/src/ui-commands.c @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/** +/* * (GLABELS) Label and Business Card Creation program for GNOME * * ui-commands.c: GLabels UI commands module @@ -194,18 +194,24 @@ gl_ui_cmd_file_print (GtkAction *action, g_return_if_fail (action && GTK_IS_ACTION(action)); g_return_if_fail (window && GL_IS_WINDOW(window)); - if (GL_VIEW(window->view)->print_dialog) { + if (window->print_dialog) { - gtk_window_present (GTK_WINDOW(GL_VIEW(window->view)->print_dialog)); + gtk_window_present (GTK_WINDOW(window->print_dialog)); + gtk_window_set_transient_for (GTK_WINDOW (window->print_dialog), + GTK_WINDOW (window)); } else { - GL_VIEW(window->view)->print_dialog = + window->print_dialog = g_object_ref ( gl_print_dialog_new (GL_VIEW(window->view)->label, - BONOBO_WINDOW(window)) ); + GTK_WINDOW(window)) ); + + g_signal_connect (G_OBJECT(window->print_dialog), "destroy", + G_CALLBACK (gtk_widget_destroyed), + &window->print_dialog); - gtk_widget_show (GL_VIEW(window->view)->print_dialog); + gtk_widget_show (GTK_WIDGET (window->print_dialog)); } gl_debug (DEBUG_COMMANDS, "END"); @@ -1006,8 +1012,25 @@ gl_ui_cmd_objects_merge_properties (GtkAction *action, g_return_if_fail (action && GTK_IS_ACTION(action)); g_return_if_fail (window && GL_IS_WINDOW(window)); - if (window->view != NULL) { - gl_view_edit_merge_props (GL_VIEW(window->view)); + if (window->merge_dialog) { + + gtk_window_present (GTK_WINDOW(window->merge_dialog)); + gtk_window_set_transient_for (GTK_WINDOW (window->merge_dialog), + GTK_WINDOW (window)); + + } else { + + window->merge_dialog = + g_object_ref ( + gl_merge_properties_dialog_new (GL_VIEW(window->view)->label, + GTK_WINDOW(window)) ); + + g_signal_connect (G_OBJECT(window->merge_dialog), "destroy", + G_CALLBACK (gtk_widget_destroyed), + &window->merge_dialog); + + gtk_widget_show (GTK_WIDGET (window->merge_dialog)); + } gl_debug (DEBUG_COMMANDS, "END"); @@ -1111,9 +1134,9 @@ gl_ui_cmd_help_about (GtkAction *action, if (about != NULL) { + gtk_window_present (GTK_WINDOW (about)); gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (window)); - gtk_window_present (GTK_WINDOW (about)); } else { diff --git a/glabels2/src/ui.c b/glabels2/src/ui.c index 53727197..30d4d763 100644 --- a/glabels2/src/ui.c +++ b/glabels2/src/ui.c @@ -105,6 +105,9 @@ static GtkActionEntry entries[] = { { "ObjectsAlignVertMenu", NULL, N_("Align _Vertical") }, { "HelpMenu", NULL, N_("_Help") }, + /* Popup entries. */ + { "ContextMenu", NULL, N_("Context Menu") }, + { "EmptySelectionContextMenu", NULL, N_("Context Menu") }, /* File action entries. */ { "FileNew", @@ -628,6 +631,40 @@ static const gchar *ui_info = " " " " "" +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +"" +" " +" " +" " +"" ""; @@ -751,6 +788,7 @@ gl_ui_new (glWindow *window) gtk_ui_manager_insert_action_group (ui, actions, 0); gtk_window_add_accel_group (GTK_WINDOW (window), gtk_ui_manager_get_accel_group (ui)); + gl_debug (DEBUG_UI, "Creating ui from string"); if (!gtk_ui_manager_add_ui_from_string (ui, ui_info, strlen (ui_info), &error)) { g_message ("building menus failed: %s", error->message); g_error_free (error); diff --git a/glabels2/src/view-object.c b/glabels2/src/view-object.c index 95b41b7b..a8efeb04 100644 --- a/glabels2/src/view-object.c +++ b/glabels2/src/view-object.c @@ -1,3 +1,5 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + /* * (GLABELS) Label and Business Card Creation program for GNOME * @@ -584,19 +586,6 @@ item_event_arrow_mode (GnomeCanvasItem *item, dragging = TRUE; return TRUE; - case 3: - if (!gl_view_is_object_selected (view, view_object)) { - if (!control_key_pressed) { - /* No control, key so remove any selections before adding */ - gl_view_unselect_all (view); - } - } - /* Add to current selection */ - gl_view_select_object (view, view_object); - /* bring up apropriate menu for selection. */ - gl_view_popup_menu (view, event); - return TRUE; - default: return FALSE; } diff --git a/glabels2/src/view.c b/glabels2/src/view.c index ec7b8541..9f72d79e 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -1,9 +1,11 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + /* * (GLABELS) Label and Business Card Creation program for GNOME * * view.c: GLabels View module * - * Copyright (C) 2001-2002 Jim Evins . + * Copyright (C) 2001-2005 Jim Evins . * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,9 +30,6 @@ #include #include #include -#include -#include -#include #include #include #include @@ -44,8 +43,6 @@ #include "view-barcode.h" #include "xml-label.h" #include "color.h" -#include "stock.h" -#include "merge-properties-dialog.h" #include "prefs.h" #include "marshal.h" @@ -79,6 +76,7 @@ enum { SELECTION_CHANGED, + CONTEXT_MENU_ACTIVATE, ZOOM_CHANGED, POINTER_MOVED, POINTER_EXIT, @@ -199,10 +197,6 @@ static int canvas_event_arrow_mode (GnomeCanvas *canvas, GdkEvent *event, glView *view); -static void construct_selection_menu (glView *view); - -static void construct_empty_selection_menu (glView *view); - static void selection_clear_cb (GtkWidget *widget, GdkEventSelection *event, gpointer data); @@ -268,6 +262,16 @@ gl_view_class_init (glViewClass *class) G_TYPE_NONE, 0); + signals[CONTEXT_MENU_ACTIVATE] = + g_signal_new ("context_menu_activate", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (glViewClass, context_menu_activate), + NULL, NULL, + gl_marshal_VOID__INT_UINT, + G_TYPE_NONE, + 2, G_TYPE_INT, G_TYPE_UINT); + signals[ZOOM_CHANGED] = g_signal_new ("zoom_changed", G_OBJECT_CLASS_TYPE (object_class), @@ -391,9 +395,6 @@ gl_view_construct (glView *view) gl_view_construct_selection (view); - construct_selection_menu (view); - construct_empty_selection_menu (view); - gl_view_set_default_font_family (view, gl_prefs->default_font_family); gl_view_set_default_font_size (view, gl_prefs->default_font_size); gl_view_set_default_font_weight (view, gl_prefs->default_font_weight); @@ -3286,29 +3287,6 @@ gl_view_is_zoom_min (glView *view) return view->zoom <= zooms[N_ZOOMS-1]; } -/*****************************************************************************/ -/* Launch merge properties dialog. */ -/*****************************************************************************/ -void -gl_view_edit_merge_props (glView *view) -{ - gl_debug (DEBUG_VIEW, ""); - - g_return_if_fail (view && GL_IS_VIEW (view)); - - if (view->merge_props_dialog != NULL) { - gtk_window_present (GTK_WINDOW(view->merge_props_dialog)); - return; - } - - view->merge_props_dialog = gl_merge_properties_dialog_new (view); - gtk_window_present (GTK_WINDOW (view->merge_props_dialog)); - - g_signal_connect (G_OBJECT(view->merge_props_dialog), "destroy", - G_CALLBACK (gtk_widget_destroyed), - &view->merge_props_dialog); -} - /*---------------------------------------------------------------------------*/ /* PRIVATE. Canvas event handler. */ /*---------------------------------------------------------------------------*/ @@ -3456,14 +3434,10 @@ canvas_event_arrow_mode (GnomeCanvas *canvas, } return FALSE; case 3: - gnome_canvas_window_to_world (canvas, - event->button.x, - event->button.y, &x, &y); - - if (!object_at (view, x, y)) { - /* bring up apropriate menu for selection. */ - gl_view_popup_menu (view, event); - } + /* activate context menu. */ + g_signal_emit (G_OBJECT (view), + signals[CONTEXT_MENU_ACTIVATE], 0, + event->button.button, event->button.time); return FALSE; default: return FALSE; @@ -3559,262 +3533,6 @@ canvas_event_arrow_mode (GnomeCanvas *canvas, } -/*---------------------------------------------------------------------------*/ -/* PRIVATE. create menu for selections. */ -/*---------------------------------------------------------------------------*/ -void -construct_selection_menu (glView *view) -{ - GtkWidget *menu, *menuitem, *submenu; - - gl_debug (DEBUG_VIEW, "START"); - - g_return_if_fail (view && GL_IS_VIEW (view)); - - menu = gtk_menu_new (); - - /* - * Submenu: Order - */ - menuitem = gtk_menu_item_new_with_mnemonic (_("_Order")); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - gtk_widget_show (menuitem); - submenu = gtk_menu_new (); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu); - - menuitem = gtk_image_menu_item_new_from_stock (GL_STOCK_ORDER_TOP, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_raise_selection), view); - - menuitem = gtk_image_menu_item_new_from_stock (GL_STOCK_ORDER_BOTTOM, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_lower_selection), view); - - /* - * Submenu: Rotate/Flip - */ - menuitem = gtk_menu_item_new_with_mnemonic (_("_Rotate/Flip")); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - gtk_widget_show (menuitem); - submenu = gtk_menu_new (); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu); - - menuitem = gtk_image_menu_item_new_from_stock (GL_STOCK_ROTATE_LEFT, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_rotate_selection_left), view); - - menuitem = gtk_image_menu_item_new_from_stock (GL_STOCK_ROTATE_RIGHT, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_rotate_selection_right), view); - - menuitem = gtk_image_menu_item_new_from_stock (GL_STOCK_FLIP_HORIZ, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_flip_selection_horiz), view); - - menuitem = gtk_image_menu_item_new_from_stock (GL_STOCK_FLIP_VERT, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_flip_selection_vert), view); - - /* - * Submenu: Align Horizontally - */ - menuitem = gtk_menu_item_new_with_mnemonic (_("Align _Horizontally")); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - gtk_widget_show (menuitem); - submenu = gtk_menu_new (); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu); - - menuitem = gtk_image_menu_item_new_from_stock (GL_STOCK_ALIGN_LEFT, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_align_selection_left), view); - view->multi_selection_items = - g_list_prepend (view->multi_selection_items, menuitem); - - menuitem = gtk_image_menu_item_new_from_stock (GL_STOCK_ALIGN_HCENTER, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_align_selection_hcenter), view); - view->multi_selection_items = - g_list_prepend (view->multi_selection_items, menuitem); - - menuitem = gtk_image_menu_item_new_from_stock (GL_STOCK_ALIGN_RIGHT, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_align_selection_right), view); - view->multi_selection_items = - g_list_prepend (view->multi_selection_items, menuitem); - - menuitem = gtk_image_menu_item_new_from_stock (GL_STOCK_CENTER_HORIZ, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_center_selection_horiz), view); - - /* - * Submenu: Align Vertically - */ - menuitem = gtk_menu_item_new_with_mnemonic (_("Align _Vertically")); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - gtk_widget_show (menuitem); - submenu = gtk_menu_new (); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu); - - menuitem = gtk_image_menu_item_new_from_stock (GL_STOCK_ALIGN_TOP, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_align_selection_top), view); - view->multi_selection_items = - g_list_prepend (view->multi_selection_items, menuitem); - - menuitem = gtk_image_menu_item_new_from_stock (GL_STOCK_ALIGN_VCENTER, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_align_selection_vcenter), view); - view->multi_selection_items = - g_list_prepend (view->multi_selection_items, menuitem); - - menuitem = gtk_image_menu_item_new_from_stock (GL_STOCK_ALIGN_BOTTOM, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_align_selection_bottom), view); - view->multi_selection_items = - g_list_prepend (view->multi_selection_items, menuitem); - - menuitem = gtk_image_menu_item_new_from_stock (GL_STOCK_CENTER_VERT, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_center_selection_vert), view); - - /* - * Separator ------------------------- - */ - menuitem = gtk_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - gtk_widget_show (menuitem); - - menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_CUT, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_cut), view); - - menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_copy), view); - - menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_PASTE, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_paste), view); - - menuitem = gtk_menu_item_new_with_mnemonic (_("_Delete")); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_delete_selection), view); - - - view->selection_menu = menu; - - gl_debug (DEBUG_VIEW, "END"); -} - -/*---------------------------------------------------------------------------*/ -/* PRIVATE. create menu for empty selections. */ -/*---------------------------------------------------------------------------*/ -void -construct_empty_selection_menu (glView *view) -{ - GtkWidget *menu, *menuitem, *submenu; - - gl_debug (DEBUG_VIEW, "START"); - - g_return_if_fail (view && GL_IS_VIEW (view)); - - menu = gtk_menu_new (); - - menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_PASTE, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - gtk_widget_show (menuitem); - g_signal_connect_swapped (G_OBJECT (menuitem), "activate", - G_CALLBACK (gl_view_paste), view); - - - view->empty_selection_menu = menu; - - gl_debug (DEBUG_VIEW, "END"); -} - -/****************************************************************************/ -/* popup menu. */ -/****************************************************************************/ -void -gl_view_popup_menu (glView *view, - GdkEvent *event) -{ - GtkMenu *menu; - GList *p; - - gl_debug (DEBUG_VIEW, "START"); - - g_return_if_fail (view && GL_IS_VIEW (view)); - - if (gl_view_is_selection_empty (view)) { - - if (view->empty_selection_menu != NULL) { - gtk_menu_popup (GTK_MENU (view->empty_selection_menu), - NULL, NULL, NULL, NULL, - event->button.button, - event->button.time); - } - - } else { - - for (p=view->atomic_selection_items; p!=NULL; p=p->next) { - gtk_widget_set_sensitive (GTK_WIDGET(p->data), - gl_view_is_selection_atomic(view)); - } - - for (p=view->multi_selection_items; p!=NULL; p=p->next) { - gtk_widget_set_sensitive (GTK_WIDGET(p->data), - !gl_view_is_selection_atomic(view)); - } - - if (view->selection_menu != NULL) { - gtk_menu_popup (GTK_MENU (view->selection_menu), - NULL, NULL, NULL, NULL, - event->button.button, - event->button.time); - } - - } - - gl_debug (DEBUG_VIEW, "END"); -} - /*---------------------------------------------------------------------------*/ /* PRIVATE. Handle "selection-clear" signal. */ /*---------------------------------------------------------------------------*/ diff --git a/glabels2/src/view.h b/glabels2/src/view.h index d4a453b4..28c6d436 100644 --- a/glabels2/src/view.h +++ b/glabels2/src/view.h @@ -1,9 +1,11 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + /* * (GLABELS) Label and Business Card Creation program for GNOME * * view.h: GLabels View module header file * - * Copyright (C) 2001-2002 Jim Evins . + * Copyright (C) 2001-2005 Jim Evins . * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -77,18 +79,6 @@ struct _glView { glLabel *selection_data; GtkWidget *invisible; - /* Menus */ - GList *atomic_selection_items; - GList *multi_selection_items; - GtkWidget *selection_menu; - GtkWidget *empty_selection_menu; - - /* Merge Properties Dialog */ - GtkWidget *merge_props_dialog; - - /* Print Dialog */ - GtkWidget *print_dialog; - /* Default object text properties */ gchar *default_font_family; gdouble default_font_size; @@ -113,6 +103,12 @@ struct _glViewClass { void (*selection_changed) (glView *view, gpointer user_data); + /* Signal to launch a context menu */ + void (*context_menu_activate) (glView *view, + gint button, + guint32 activate_time, + gpointer user_data); + /* Signals to support a status bar */ void (*zoom_changed) (glView *view, gdouble zoom, @@ -275,12 +271,6 @@ gboolean gl_view_is_zoom_max (glView *view); gboolean gl_view_is_zoom_min (glView *view); -void gl_view_popup_menu (glView *view, - GdkEvent *event); - -void gl_view_edit_merge_props (glView *view); - - void gl_view_set_default_font_family (glView *view, const gchar *font_family); diff --git a/glabels2/src/window.c b/glabels2/src/window.c index d3754865..6e98056a 100644 --- a/glabels2/src/window.c +++ b/glabels2/src/window.c @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/** +/* * (GLABELS) Label and Business Card Creation program for GNOME * * window.c: a gLabels app window @@ -79,6 +79,11 @@ static gboolean window_delete_event_cb (glWindow *window, static void selection_changed_cb (glView *view, glWindow *window); +static void context_menu_activate_cb (glView *view, + gint button, + guint32 activate_time, + glWindow *window); + static void zoom_changed_cb (glView *view, gdouble zoom, glWindow *window); @@ -214,6 +219,12 @@ gl_window_init (glWindow *window) window->menu_tips_context_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (window->status_bar), "menu_tips"); + window->print_dialog = NULL; + window->merge_dialog = NULL; + window->context_menu = GTK_MENU (gtk_ui_manager_get_widget (ui, "/ContextMenu")); + window->empty_selection_context_menu = + GTK_MENU (gtk_ui_manager_get_widget (ui, "/EmptySelectionContextMenu")); + window->view = NULL; window_list = g_list_append (window_list, window); @@ -398,6 +409,9 @@ gl_window_set_label (glWindow *window, g_signal_connect (G_OBJECT(window->view), "selection_changed", G_CALLBACK(selection_changed_cb), window); + g_signal_connect (G_OBJECT(window->view), "context_menu_activate", + G_CALLBACK(context_menu_activate_cb), window); + g_signal_connect (G_OBJECT(window->view), "zoom_changed", G_CALLBACK(zoom_changed_cb), window); @@ -494,6 +508,35 @@ selection_changed_cb (glView *view, gl_debug (DEBUG_WINDOW, "END"); } +/*---------------------------------------------------------------------------*/ +/* PRIVATE. View "context menu activate" callback. */ +/*---------------------------------------------------------------------------*/ +static void +context_menu_activate_cb (glView *view, + gint button, + guint32 activate_time, + glWindow *window) +{ + gl_debug (DEBUG_WINDOW, "START"); + + g_return_if_fail (view && GL_IS_VIEW (view)); + g_return_if_fail (window && GL_IS_WINDOW (window)); + + if (gl_view_is_selection_empty (view)) { + + gtk_menu_popup (GTK_MENU (window->empty_selection_context_menu), + NULL, NULL, NULL, NULL, button, activate_time); + + } else { + + gtk_menu_popup (GTK_MENU (window->context_menu), + NULL, NULL, NULL, NULL, button, activate_time); + + } + + gl_debug (DEBUG_WINDOW, "END"); +} + /*---------------------------------------------------------------------------*/ /* PRIVATE. View "zoom state changed" callback. */ /*---------------------------------------------------------------------------*/ diff --git a/glabels2/src/window.h b/glabels2/src/window.h index 502b1d6c..287155d1 100644 --- a/glabels2/src/window.h +++ b/glabels2/src/window.h @@ -27,12 +27,14 @@ #include #include +#include #include "view.h" #include "label.h" - #include "ui-property-bar.h" #include "ui-sidebar.h" +#include "print-dialog.h" +#include "merge-properties-dialog.h" G_BEGIN_DECLS @@ -52,22 +54,27 @@ typedef struct _glWindowClass glWindowClass; struct _glWindow { GtkWindow parent_widget; - GtkUIManager *ui; + GtkUIManager *ui; + + GtkWidget *view; - GtkWidget *view; + GtkWidget *hbox; - GtkWidget *hbox; + glUIPropertyBar *property_bar; + glUISidebar *sidebar; - glUIPropertyBar *property_bar; - glUISidebar *sidebar; + GtkWidget *status_bar; + GtkWidget *cursor_info; + GtkWidget *cursor_info_frame; + GtkWidget *zoom_info; + GtkWidget *zoom_info_frame; - GtkWidget *status_bar; - GtkWidget *cursor_info; - GtkWidget *cursor_info_frame; - GtkWidget *zoom_info; - GtkWidget *zoom_info_frame; + guint menu_tips_context_id; - guint menu_tips_context_id; + glPrintDialog *print_dialog; + glMergePropertiesDialog *merge_dialog; + GtkMenu *context_menu; + GtkMenu *empty_selection_context_menu; }; struct _glWindowClass { -- 2.39.5