+/* -*- 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 <evins@snaught.com>.
+ * Copyright (C) 2001-2005 Jim Evins <evins@snaught.com>.
*
* 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
#include <gtk/gtkscrolledwindow.h>
#include <gtk/gtkselection.h>
#include <gtk/gtkinvisible.h>
-#include <gtk/gtkmenu.h>
-#include <gtk/gtkimagemenuitem.h>
-#include <gtk/gtkstock.h>
#include <gdk/gdkkeysyms.h>
#include <string.h>
#include <math.h>
#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"
enum {
SELECTION_CHANGED,
+ CONTEXT_MENU_ACTIVATE,
ZOOM_CHANGED,
POINTER_MOVED,
POINTER_EXIT,
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);
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),
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);
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. */
/*---------------------------------------------------------------------------*/
}
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;
}
-/*---------------------------------------------------------------------------*/
-/* 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. */
/*---------------------------------------------------------------------------*/