From a8ff7374b838357bf095f00079fa72004008603a Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Fri, 6 Sep 2002 05:09:59 +0000 Subject: [PATCH] Renamed menus module to ui. Added "selection_changed" signal to view. Added adjustments to sensitivity of menu items based on selection state. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@94 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/po/POTFILES.in | 4 +- glabels2/src/Makefile.am | 4 +- glabels2/src/mdi.c | 187 ++++++++---- glabels2/src/menus.h | 80 ----- glabels2/src/{menus.c => ui.c} | 118 +++++--- glabels2/src/ui.h | 82 +++++ glabels2/src/view.c | 526 ++++++++++++++++++--------------- 7 files changed, 586 insertions(+), 415 deletions(-) delete mode 100644 glabels2/src/menus.h rename glabels2/src/{menus.c => ui.c} (70%) create mode 100644 glabels2/src/ui.h diff --git a/glabels2/po/POTFILES.in b/glabels2/po/POTFILES.in index b8378228..0dd680ee 100644 --- a/glabels2/po/POTFILES.in +++ b/glabels2/po/POTFILES.in @@ -12,8 +12,8 @@ src/mdi-child.c src/mdi-child.h src/stock.c src/stock.h -src/menus.h -src/menus.c +src/ui.h +src/ui.c src/commands.h src/commands.c src/file.h diff --git a/glabels2/src/Makefile.am b/glabels2/src/Makefile.am index a9acaca8..8099522d 100644 --- a/glabels2/src/Makefile.am +++ b/glabels2/src/Makefile.am @@ -53,8 +53,8 @@ glabels_SOURCES = \ mdi-child.h \ stock.c \ stock.h \ - menus.h \ - menus.c \ + ui.h \ + ui.c \ commands.h \ commands.c \ file.h \ diff --git a/glabels2/src/mdi.c b/glabels2/src/mdi.c index 4882f4f4..db983d38 100644 --- a/glabels2/src/mdi.c +++ b/glabels2/src/mdi.c @@ -39,7 +39,7 @@ #include "mdi.h" #include "mdi-child.h" #include "glabels.h" -#include "menus.h" +#include "ui.h" #include "prefs.h" #include "recent.h" #include "file.h" @@ -99,6 +99,7 @@ static void gl_mdi_child_changed_cb (BonoboMDI *mdi, BonoboMDIChild *old_child); static void gl_mdi_child_state_changed_cb (glMDIChild *child); static void gl_mdi_set_active_window_undo_redo_verbs_sensitivity (BonoboMDI *mdi); +static void gl_mdi_set_active_window_selection_verbs_sensitivity (BonoboMDI *mdi); static void gl_mdi_view_menu_item_toggled_cb ( BonoboUIComponent *ui_component, @@ -168,7 +169,7 @@ gl_mdi_init (glMDI *mdi) bonobo_mdi_set_ui_template_file (BONOBO_MDI (mdi), GLABELS_UI_DIR "glabels-ui.xml", - gl_verbs); + gl_ui_verbs); bonobo_mdi_set_child_list_path (BONOBO_MDI (mdi), "/menu/Documents/"); @@ -220,7 +221,7 @@ gl_mdi_finalize (GObject *object) /*****************************************************************************/ -/* NEW mdi objecg. */ +/* NEW mdi object. */ /*****************************************************************************/ glMDI* gl_mdi_new (void) @@ -283,9 +284,9 @@ gl_mdi_app_created_cb (BonoboMDI *mdi, BonoboWindow *win) (gpointer)win); - gl_menus_set_verb_list_sensitive (ui_component, - gl_menus_no_docs_sensible_verbs, - FALSE); + gl_ui_set_verb_list_sensitive (ui_component, + gl_ui_no_docs_sensible_verbs, + FALSE); /* add a GeditRecentView object */ model = gl_recent_get_model (); @@ -383,38 +384,38 @@ gl_mdi_set_app_toolbar_style (BonoboWindow *win) bonobo_ui_component_freeze (ui_component, NULL); /* Updated view menu */ - gl_menus_set_verb_state (ui_component, - "/commands/ViewToolbar", - gl_prefs->toolbar_visible); - - gl_menus_set_verb_sensitive (ui_component, - "/commands/ToolbarSystem", - gl_prefs->toolbar_visible); - gl_menus_set_verb_sensitive (ui_component, - "/commands/ToolbarIcon", - gl_prefs->toolbar_visible); - gl_menus_set_verb_sensitive (ui_component, - "/commands/ToolbarIconText", - gl_prefs->toolbar_visible); - gl_menus_set_verb_sensitive (ui_component, - "/commands/ToolbarTooltips", - gl_prefs->toolbar_visible); - - gl_menus_set_verb_state (ui_component, - "/commands/ToolbarSystem", - gl_prefs->toolbar_buttons_style == GL_TOOLBAR_SYSTEM); - - gl_menus_set_verb_state (ui_component, - "/commands/ToolbarIcon", - gl_prefs->toolbar_buttons_style == GL_TOOLBAR_ICONS); - - gl_menus_set_verb_state (ui_component, - "/commands/ToolbarIconText", - gl_prefs->toolbar_buttons_style == GL_TOOLBAR_ICONS_AND_TEXT); - - gl_menus_set_verb_state (ui_component, - "/commands/ToolbarTooltips", - gl_prefs->toolbar_view_tooltips); + gl_ui_set_verb_state (ui_component, + "/commands/ViewToolbar", + gl_prefs->toolbar_visible); + + gl_ui_set_verb_sensitive (ui_component, + "/commands/ToolbarSystem", + gl_prefs->toolbar_visible); + gl_ui_set_verb_sensitive (ui_component, + "/commands/ToolbarIcon", + gl_prefs->toolbar_visible); + gl_ui_set_verb_sensitive (ui_component, + "/commands/ToolbarIconText", + gl_prefs->toolbar_visible); + gl_ui_set_verb_sensitive (ui_component, + "/commands/ToolbarTooltips", + gl_prefs->toolbar_visible); + + gl_ui_set_verb_state (ui_component, + "/commands/ToolbarSystem", + gl_prefs->toolbar_buttons_style == GL_TOOLBAR_SYSTEM); + + gl_ui_set_verb_state (ui_component, + "/commands/ToolbarIcon", + gl_prefs->toolbar_buttons_style == GL_TOOLBAR_ICONS); + + gl_ui_set_verb_state (ui_component, + "/commands/ToolbarIconText", + gl_prefs->toolbar_buttons_style == GL_TOOLBAR_ICONS_AND_TEXT); + + gl_ui_set_verb_state (ui_component, + "/commands/ToolbarTooltips", + gl_prefs->toolbar_view_tooltips); /* Actually update toolbar style */ @@ -532,6 +533,21 @@ gl_mdi_add_child_cb (BonoboMDI *mdi, BonoboMDIChild *child) return TRUE; } +/*---------------------------------------------------------------------------*/ +/* View selection state changed callback. */ +/*---------------------------------------------------------------------------*/ +static void +gl_mdi_view_selection_state_changed_cb (glView *view) +{ + gl_debug (DEBUG_MDI, "START"); + + if (bonobo_mdi_get_active_view (BONOBO_MDI (glabels_mdi)) != GTK_WIDGET (view)) + return; + + gl_mdi_set_active_window_selection_verbs_sensitivity (BONOBO_MDI (glabels_mdi)); + gl_debug (DEBUG_MDI, "END"); +} + /*---------------------------------------------------------------------------*/ /* Add view callback. */ /*---------------------------------------------------------------------------*/ @@ -539,6 +555,11 @@ static gint gl_mdi_add_view_cb (BonoboMDI *mdi, GtkWidget *view) { gl_debug (DEBUG_MDI, "START"); + + g_signal_connect (G_OBJECT (view), "selection_changed", + G_CALLBACK (gl_mdi_view_selection_state_changed_cb), + NULL); + gl_debug (DEBUG_MDI, "END"); return TRUE; } @@ -752,9 +773,10 @@ gl_mdi_set_active_window_verbs_sensitivity (BonoboMDI *mdi) { /* FIXME: it is too slooooooow! - Paolo */ - BonoboWindow* active_window = NULL; - BonoboMDIChild* active_child = NULL; - glLabel* doc = NULL; + BonoboWindow *active_window = NULL; + BonoboMDIChild *active_child = NULL; + glView *view = NULL; + glLabel *doc = NULL; BonoboUIComponent *ui_component; gl_debug (DEBUG_MDI, "START"); @@ -773,34 +795,44 @@ gl_mdi_set_active_window_verbs_sensitivity (BonoboMDI *mdi) if (active_child == NULL) { - gl_menus_set_verb_list_sensitive (ui_component, - gl_menus_no_docs_sensible_verbs, FALSE); + gl_ui_set_verb_list_sensitive (ui_component, + gl_ui_no_docs_sensible_verbs, + FALSE); goto end; } else { - gl_menus_set_verb_list_sensitive (ui_component, - gl_menus_all_sensible_verbs, TRUE); + gl_ui_set_verb_list_sensitive (ui_component, + gl_ui_all_sensible_verbs, + TRUE); } doc = GL_MDI_CHILD (active_child)->label; g_return_if_fail (doc != NULL); if (!gl_label_can_undo (doc)) - gl_menus_set_verb_sensitive (ui_component, - "/commands/EditUndo", FALSE); + gl_ui_set_verb_sensitive (ui_component, + "/commands/EditUndo", + FALSE); if (!gl_label_can_redo (doc)) - gl_menus_set_verb_sensitive (ui_component, - "/commands/EditRedo", FALSE); + gl_ui_set_verb_sensitive (ui_component, + "/commands/EditRedo", + FALSE); - if (!gl_label_is_modified (doc)) - { - gl_menus_set_verb_list_sensitive (ui_component, - gl_menus_not_modified_doc_sensible_verbs, - FALSE); - goto end; - } + gl_ui_set_verb_list_sensitive (ui_component, + gl_ui_not_modified_doc_sensible_verbs, + gl_label_is_modified (doc)); + + view = GL_VIEW (bonobo_mdi_get_active_view (mdi)); + g_return_if_fail (view != NULL); + + gl_ui_set_verb_list_sensitive (ui_component, + gl_ui_selection_sensible_verbs, + !gl_view_is_selection_empty (view)); + gl_ui_set_verb_list_sensitive (ui_component, + gl_ui_atomic_selection_sensible_verbs, + gl_view_is_selection_atomic (view)); end: bonobo_ui_component_thaw (ui_component, NULL); @@ -834,11 +866,46 @@ gl_mdi_set_active_window_undo_redo_verbs_sensitivity (BonoboMDI *mdi) bonobo_ui_component_freeze (ui_component, NULL); - gl_menus_set_verb_sensitive (ui_component, "/commands/EditUndo", - gl_label_can_undo (doc)); + gl_ui_set_verb_sensitive (ui_component, "/commands/EditUndo", + gl_label_can_undo (doc)); + + gl_ui_set_verb_sensitive (ui_component, "/commands/EditRedo", + gl_label_can_redo (doc)); + + bonobo_ui_component_thaw (ui_component, NULL); + + gl_debug (DEBUG_MDI, "END"); +} + +/*****************************************************************************/ +/* Set sensitivity of selection verbs in active window. */ +/*****************************************************************************/ +static void +gl_mdi_set_active_window_selection_verbs_sensitivity (BonoboMDI *mdi) +{ + BonoboWindow *active_window = NULL; + glView *view = NULL; + BonoboUIComponent *ui_component; + + gl_debug (DEBUG_MDI, "START"); + + active_window = bonobo_mdi_get_active_window (mdi); + g_return_if_fail (active_window != NULL); + + ui_component = bonobo_mdi_get_ui_component_from_window (active_window); + g_return_if_fail (ui_component != NULL); + + view = GL_VIEW (bonobo_mdi_get_active_view (mdi)); + g_return_if_fail (view != NULL); + + bonobo_ui_component_freeze (ui_component, NULL); - gl_menus_set_verb_sensitive (ui_component, "/commands/EditRedo", - gl_label_can_redo (doc)); + gl_ui_set_verb_list_sensitive (ui_component, + gl_ui_selection_sensible_verbs, + !gl_view_is_selection_empty (view)); + gl_ui_set_verb_list_sensitive (ui_component, + gl_ui_atomic_selection_sensible_verbs, + gl_view_is_selection_atomic (view)); bonobo_ui_component_thaw (ui_component, NULL); diff --git a/glabels2/src/menus.h b/glabels2/src/menus.h deleted file mode 100644 index 24a0541c..00000000 --- a/glabels2/src/menus.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * (GLABELS) Label and Business Card Creation program for GNOME - * - * menus.h: GLabels menus module header file - * - * Copyright (C) 2001-2002 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * This file is based on gedit-menus.h from gedit2: - * - * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence - * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi - * - */ -#ifndef __GL_MENU_H__ -#define __GL_MENU_H__ - -#include -#include -#include - -extern BonoboUIVerb gl_verbs []; -extern gchar* gl_menus_no_docs_sensible_verbs []; -extern gchar* gl_menus_untitled_doc_sensible_verbs []; -extern gchar* gl_menus_not_modified_doc_sensible_verbs []; - -#define gl_menus_all_sensible_verbs gl_menus_no_docs_sensible_verbs - -void gl_menus_set_verb_sensitive (BonoboUIComponent *ui_component, - gchar *cname, - gboolean sensitive); -void gl_menus_set_verb_list_sensitive (BonoboUIComponent *ui_component, - gchar **vlist, - gboolean sensitive); -void gl_menus_set_verb_state (BonoboUIComponent *ui_component, - gchar* cname, - gboolean state); - -/* convenience functions for plugins */ - -void gl_menus_add_menu_item (BonoboWindow *window, - const gchar *path, - const gchar *name, - const gchar *label, - const gchar *tooltip, - const gchar *stock_pixmap, - BonoboUIVerbFn cb); - -void gl_menus_remove_menu_item (BonoboWindow *window, - const gchar *path, - const gchar *name); - - -void gl_menus_add_menu_item_all (const gchar *path, - const gchar *name, - const gchar *label, - const gchar *tooltip, - const gchar *stock_pixmap, - BonoboUIVerbFn cb); - -void gl_menus_remove_menu_item_all (const gchar *path, - const gchar *name); - - -#endif /* __GL_MENU_H__ */ diff --git a/glabels2/src/menus.c b/glabels2/src/ui.c similarity index 70% rename from glabels2/src/menus.c rename to glabels2/src/ui.c index 68e673fe..61fad4d4 100644 --- a/glabels2/src/menus.c +++ b/glabels2/src/ui.c @@ -1,7 +1,7 @@ /* * (GLABELS) Label and Business Card Creation program for GNOME * - * menus.c: GLabels menus module + * ui.c: GLabels ui module * * Copyright (C) 2001-2002 Jim Evins . * @@ -29,12 +29,12 @@ */ #include -#include "menus.h" +#include "ui.h" #include "commands.h" #include "tools.h" #include "glabels.h" -BonoboUIVerb gl_verbs [] = { +BonoboUIVerb gl_ui_verbs [] = { BONOBO_UI_VERB ("FileNew", gl_cmd_file_new), BONOBO_UI_VERB ("FileOpen", gl_cmd_file_open), BONOBO_UI_VERB ("FileSave", gl_cmd_file_save), @@ -70,7 +70,7 @@ BonoboUIVerb gl_verbs [] = { BONOBO_UI_VERB_END }; -gchar* gl_menus_no_docs_sensible_verbs [] = { +gchar* gl_ui_no_docs_sensible_verbs [] = { "/commands/FileSave", "/commands/FileSaveAs", "/commands/FilePrint", @@ -103,51 +103,86 @@ gchar* gl_menus_no_docs_sensible_verbs [] = { NULL }; -gchar* gl_menus_not_modified_doc_sensible_verbs [] = { +gchar* gl_ui_not_modified_doc_sensible_verbs [] = { "/commands/FileSave", NULL }; +gchar* gl_ui_selection_sensible_verbs [] = { + "/commands/EditCut", + "/commands/EditCopy", + "/commands/EditDelete", + "/commands/EditUnSelectAll", + "/commands/ToolsRaiseObjects", + "/commands/ToolsLowerObjects", + + NULL +}; + +gchar* gl_ui_atomic_selection_sensible_verbs [] = { + "/commands/ToolsObjectProperties", + + NULL +}; + void -gl_menus_set_verb_sensitive (BonoboUIComponent *ui_component, gchar* cname, gboolean sensitive) +gl_ui_set_verb_sensitive (BonoboUIComponent *ui_component, + gchar *cname, + gboolean sensitive) { g_return_if_fail (cname != NULL); g_return_if_fail (BONOBO_IS_UI_COMPONENT (ui_component)); - bonobo_ui_component_set_prop ( - ui_component, cname, "sensitive", sensitive ? "1" : "0", NULL); + bonobo_ui_component_set_prop (ui_component, + cname, + "sensitive", + sensitive ? "1" : "0", + NULL); } void -gl_menus_set_verb_list_sensitive (BonoboUIComponent *ui_component, gchar** vlist, gboolean sensitive) +gl_ui_set_verb_list_sensitive (BonoboUIComponent *ui_component, + gchar **vlist, + gboolean sensitive) { g_return_if_fail (vlist != NULL); g_return_if_fail (BONOBO_IS_UI_COMPONENT (ui_component)); for ( ; *vlist; ++vlist) { - bonobo_ui_component_set_prop ( - ui_component, *vlist, "sensitive", sensitive ? "1" : "0", NULL); + bonobo_ui_component_set_prop (ui_component, + *vlist, + "sensitive", + sensitive ? "1" : "0", + NULL); } } void -gl_menus_set_verb_state (BonoboUIComponent *ui_component, gchar* cname, gboolean state) +gl_ui_set_verb_state (BonoboUIComponent *ui_component, + gchar *cname, + gboolean state) { g_return_if_fail (cname != NULL); g_return_if_fail (BONOBO_IS_UI_COMPONENT (ui_component)); - bonobo_ui_component_set_prop ( - ui_component, cname, "state", state ? "1" : "0", NULL); + bonobo_ui_component_set_prop (ui_component, + cname, + "state", + state ? "1" : "0", + NULL); } void -gl_menus_add_menu_item (BonoboWindow *window, const gchar *path, - const gchar *name, const gchar *label, - const gchar *tooltip, const gchar *stock_pixmap, - BonoboUIVerbFn cb) +gl_ui_add_menu_item (BonoboWindow *window, + const gchar *path, + const gchar *name, + const gchar *label, + const gchar *tooltip, + const gchar *stock_pixmap, + BonoboUIVerbFn cb) { BonoboUIComponent *ui_component; gchar *item_path; @@ -159,7 +194,8 @@ gl_menus_add_menu_item (BonoboWindow *window, const gchar *path, g_return_if_fail (cb != NULL); item_path = g_strconcat (path, name, NULL); - ui_component = bonobo_mdi_get_ui_component_from_window (BONOBO_WINDOW (window)); + ui_component = + bonobo_mdi_get_ui_component_from_window (BONOBO_WINDOW (window)); if (!bonobo_ui_component_path_exists (ui_component, item_path, NULL)) { gchar *xml; @@ -179,11 +215,15 @@ gl_menus_add_menu_item (BonoboWindow *window, const gchar *path, } - bonobo_ui_component_set_translate (ui_component, path, - xml, NULL); + bonobo_ui_component_set_translate (ui_component, + path, + xml, + NULL); - bonobo_ui_component_set_translate (ui_component, "/commands/", - cmd, NULL); + bonobo_ui_component_set_translate (ui_component, + "/commands/", + cmd, + NULL); bonobo_ui_component_add_verb (ui_component, name, cb, NULL); @@ -195,8 +235,9 @@ gl_menus_add_menu_item (BonoboWindow *window, const gchar *path, } void -gl_menus_remove_menu_item (BonoboWindow *window, const gchar *path, - const gchar *name) +gl_ui_remove_menu_item (BonoboWindow *window, + const gchar *path, + const gchar *name) { BonoboUIComponent *ui_component; gchar *item_path; @@ -206,7 +247,8 @@ gl_menus_remove_menu_item (BonoboWindow *window, const gchar *path, g_return_if_fail (name != NULL); item_path = g_strconcat (path, name, NULL); - ui_component = bonobo_mdi_get_ui_component_from_window (BONOBO_WINDOW (window)); + ui_component = + bonobo_mdi_get_ui_component_from_window (BONOBO_WINDOW (window)); if (bonobo_ui_component_path_exists (ui_component, item_path, NULL)) { gchar *cmd; @@ -223,10 +265,12 @@ gl_menus_remove_menu_item (BonoboWindow *window, const gchar *path, } void -gl_menus_add_menu_item_all (const gchar *path, const gchar *name, - const gchar *label, const gchar *tooltip, - const gchar *stock_pixmap, - BonoboUIVerbFn cb) +gl_ui_add_menu_item_all (const gchar *path, + const gchar *name, + const gchar *label, + const gchar *tooltip, + const gchar *stock_pixmap, + BonoboUIVerbFn cb) { GList* top_windows; @@ -238,15 +282,21 @@ gl_menus_add_menu_item_all (const gchar *path, const gchar *name, BonoboWindow* window = BONOBO_WINDOW (top_windows->data); - gl_menus_add_menu_item (window, path, name, label, tooltip, - stock_pixmap, cb); + gl_ui_add_menu_item (window, + path, + name, + label, + tooltip, + stock_pixmap, + cb); top_windows = g_list_next (top_windows); } } void -gl_menus_remove_menu_item_all (const gchar *path, const gchar *name) +gl_ui_remove_menu_item_all (const gchar *path, + const gchar *name) { GList* top_windows; @@ -258,7 +308,7 @@ gl_menus_remove_menu_item_all (const gchar *path, const gchar *name) BonoboWindow* window = BONOBO_WINDOW (top_windows->data); - gl_menus_remove_menu_item (window, path, name); + gl_ui_remove_menu_item (window, path, name); top_windows = g_list_next (top_windows); diff --git a/glabels2/src/ui.h b/glabels2/src/ui.h new file mode 100644 index 00000000..36ecad44 --- /dev/null +++ b/glabels2/src/ui.h @@ -0,0 +1,82 @@ +/* + * (GLABELS) Label and Business Card Creation program for GNOME + * + * ui.h: GLabels UI module header file + * + * Copyright (C) 2001-2002 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * This file is based on gedit-menus.h from gedit2: + * + * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence + * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi + * + */ +#ifndef __GL_UI_H__ +#define __GL_UI_H__ + +#include +#include +#include + +extern BonoboUIVerb gl_ui_verbs []; + +extern gchar *gl_ui_no_docs_sensible_verbs []; +extern gchar *gl_ui_not_modified_doc_sensible_verbs []; +extern gchar *gl_ui_selection_sensible_verbs []; +extern gchar *gl_ui_atomic_selection_sensible_verbs []; + +#define gl_ui_all_sensible_verbs gl_ui_no_docs_sensible_verbs + +void gl_ui_set_verb_sensitive (BonoboUIComponent *ui_component, + gchar *cname, + gboolean sensitive); +void gl_ui_set_verb_list_sensitive (BonoboUIComponent *ui_component, + gchar **vlist, + gboolean sensitive); +void gl_ui_set_verb_state (BonoboUIComponent *ui_component, + gchar* cname, + gboolean state); + +/* convenience functions for plugins */ + +void gl_ui_add_menu_item (BonoboWindow *window, + const gchar *path, + const gchar *name, + const gchar *label, + const gchar *tooltip, + const gchar *stock_pixmap, + BonoboUIVerbFn cb); + +void gl_ui_remove_menu_item (BonoboWindow *window, + const gchar *path, + const gchar *name); + + +void gl_ui_add_menu_item_all (const gchar *path, + const gchar *name, + const gchar *label, + const gchar *tooltip, + const gchar *stock_pixmap, + BonoboUIVerbFn cb); + +void gl_ui_remove_menu_item_all (const gchar *path, + const gchar *name); + + +#endif /* __GL_UI_H__ */ diff --git a/glabels2/src/view.c b/glabels2/src/view.c index 3fd1e740..f30e3360 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -38,18 +38,34 @@ #include "view-barcode.h" #include "xml-label.h" #include "color.h" +#include "marshal.h" #include "debug.h" +/*========================================================*/ +/* Private macros and constants. */ +/*========================================================*/ + #define SEL_LINE_COLOR GL_COLOR_A (0, 0, 255, 128) #define SEL_FILL_COLOR GL_COLOR_A (192, 192, 255, 128) +/*========================================================*/ +/* Private types. */ +/*========================================================*/ + +enum { + SELECTION_CHANGED, + LAST_SIGNAL +}; + /*===========================================*/ /* Private globals */ /*===========================================*/ static GtkContainerClass *parent_class; +static guint signals[LAST_SIGNAL] = {0}; + /* "CLIPBOARD" selection */ static GdkAtom clipboard_atom = GDK_NONE; @@ -65,68 +81,66 @@ static gdouble scales[] = { /* Local function prototypes */ /*===========================================*/ -static void gl_view_class_init (glViewClass *class); -static void gl_view_init (glView *view); -static void gl_view_finalize (GObject *object); - -static void gl_view_construct (glView *view); -static GtkWidget *gl_view_construct_canvas (glView *view); -static void gl_view_construct_selection (glView *view); - -static gdouble get_apropriate_scale (gdouble w, gdouble h); - -static void draw_rect_bg_fg (glView *view); -static void draw_rounded_rect_bg_fg (glView *view); -static void draw_round_bg_fg (glView *view); -static void draw_cd_bg_fg (glView *view); - -static int canvas_event (GnomeCanvas *canvas, - GdkEvent *event, - glView *view); -static int canvas_event_arrow_mode (GnomeCanvas *canvas, - GdkEvent *event, - glView *view); - -static void select_region (glView *view, - gdouble x1, - gdouble y1, - gdouble x2, - gdouble y2); -static void select_object (glViewObject *view_object); -static void unselect_object (glViewObject *view_object); -static gboolean object_at (glView *view, - gdouble x, gdouble y); -static gboolean object_selected (glViewObject *view_object); - -static int item_event_arrow_mode (GnomeCanvasItem *item, - GdkEvent *event, - glViewObject *view_object); - -static GtkWidget *new_selection_menu (glView *view); - -static void popup_selection_menu (glView *view, - glViewObject *view_object, - GdkEvent *event); - -static void move_selected_items (glView *view, - gdouble dx, gdouble dy); -static void move_item (GnomeCanvasItem *item, - gdouble dx, gdouble dy); - -static void selection_clear_cb (GtkWidget *widget, - GdkEventSelection *event, - gpointer data); - -static void selection_get_cb (GtkWidget *widget, - GtkSelectionData *selection_data, - guint info, - guint time, - gpointer data); - -static void selection_received_cb (GtkWidget *widget, - GtkSelectionData *selection_data, - guint time, - gpointer data); +static void gl_view_class_init (glViewClass *class); +static void gl_view_init (glView *view); +static void gl_view_finalize (GObject *object); + +static void gl_view_construct (glView *view); +static GtkWidget *gl_view_construct_canvas (glView *view); +static void gl_view_construct_selection (glView *view); + +static gdouble get_apropriate_scale (gdouble w, gdouble h); + +static void draw_rect_bg_fg (glView *view); +static void draw_rounded_rect_bg_fg (glView *view); +static void draw_round_bg_fg (glView *view); +static void draw_cd_bg_fg (glView *view); + +static void select_region (glView *view, + gdouble x1, + gdouble y1, + gdouble x2, + gdouble y2); +static void select_object (glViewObject *view_object); +static void unselect_object (glViewObject *view_object); +static gboolean object_at (glView *view, + gdouble x, gdouble y); +static gboolean is_object_selected (glViewObject *view_object); + +static void move_selection (glView *view, + gdouble dx, gdouble dy); + +static int canvas_event (GnomeCanvas *canvas, + GdkEvent *event, + glView *view); +static int canvas_event_arrow_mode (GnomeCanvas *canvas, + GdkEvent *event, + glView *view); + +static int item_event_arrow_mode (GnomeCanvasItem *item, + GdkEvent *event, + glViewObject *view_object); + +static GtkWidget *new_selection_menu (glView *view); + +static void popup_selection_menu (glView *view, + glViewObject *view_object, + GdkEvent *event); + +static void selection_clear_cb (GtkWidget *widget, + GdkEventSelection *event, + gpointer data); + +static void selection_get_cb (GtkWidget *widget, + GtkSelectionData *selection_data, + guint info, + guint time, + gpointer data); + +static void selection_received_cb (GtkWidget *widget, + GtkSelectionData *selection_data, + guint time, + gpointer data); /****************************************************************************/ /* Boilerplate Object stuff. */ @@ -168,6 +182,16 @@ gl_view_class_init (glViewClass *class) object_class->finalize = gl_view_finalize; + signals[SELECTION_CHANGED] = + g_signal_new ("selection_changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (glViewClass, selection_changed), + NULL, NULL, + gl_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + gl_debug (DEBUG_VIEW, "END"); } @@ -897,6 +921,8 @@ gl_view_select_object (glView *view, glViewObject *view_object) select_object (view_object); + g_signal_emit (G_OBJECT(view), signals[SELECTION_CHANGED], 0); + gl_debug (DEBUG_VIEW, "END"); } @@ -906,18 +932,25 @@ gl_view_select_object (glView *view, glViewObject *view_object) void gl_view_select_all (glView *view) { - GList *p; + GList *p, *p_next; gl_debug (DEBUG_VIEW, "START"); g_return_if_fail (GL_IS_VIEW (view)); - gl_view_unselect_all (view); + /* 1st unselect anything already selected. */ + for (p = view->selected_object_list; p != NULL; p = p_next) { + p_next = p->next; + unselect_object (GL_VIEW_OBJECT (p->data)); + } + /* Finally select all objects. */ for (p = view->object_list; p != NULL; p = p->next) { select_object (GL_VIEW_OBJECT (p->data)); } + g_signal_emit (G_OBJECT(view), signals[SELECTION_CHANGED], 0); + gl_debug (DEBUG_VIEW, "END"); } @@ -938,9 +971,147 @@ gl_view_unselect_all (glView *view) unselect_object (GL_VIEW_OBJECT (p->data)); } + g_signal_emit (G_OBJECT(view), signals[SELECTION_CHANGED], 0); + gl_debug (DEBUG_VIEW, "END"); } +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Select all objects within given rectangular region. */ +/*---------------------------------------------------------------------------*/ +static void +select_region (glView *view, + gdouble x1, + gdouble y1, + gdouble x2, + gdouble y2) +{ + GList *p; + glViewObject *view_object; + glLabelObject *object; + gdouble i_x1, i_y1, i_x2, i_y2, w, h; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW (view)); + g_return_if_fail ((x1 <= x2) && (y1 <= y2)); + + for (p = view->object_list; p != NULL; p = p->next) { + view_object = GL_VIEW_OBJECT(p->data); + if (!is_object_selected (view_object)) { + + object = gl_view_object_get_object (view_object); + + gl_label_object_get_position (object, &i_x1, &i_y1); + gl_label_object_get_size (object, &w, &h); + i_x2 = i_x1 + w; + i_y2 = i_y1 + h; + if ((i_x1 >= x1) && (i_x2 <= x2) && (i_y1 >= y1) + && (i_y2 <= y2)) { + select_object (view_object); + } + + } + } + + g_signal_emit (G_OBJECT(view), signals[SELECTION_CHANGED], 0); + + gl_debug (DEBUG_VIEW, "END"); +} + +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Select an object. */ +/*---------------------------------------------------------------------------*/ +static void +select_object (glViewObject *view_object) +{ + glView *view; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW_OBJECT (view_object)); + + view = gl_view_object_get_view (view_object); + + if (!is_object_selected (view_object)) { + view->selected_object_list = + g_list_prepend (view->selected_object_list, view_object); + } + gl_view_object_show_highlight (view_object); + gtk_widget_grab_focus (GTK_WIDGET (view->canvas)); + + gl_debug (DEBUG_VIEW, "END"); +} + +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Un-select object. */ +/*---------------------------------------------------------------------------*/ +static void +unselect_object (glViewObject *view_object) +{ + glView *view; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW_OBJECT (view_object)); + + view = gl_view_object_get_view (view_object); + + gl_view_object_hide_highlight (view_object); + + view->selected_object_list = + g_list_remove (view->selected_object_list, view_object); + + gl_debug (DEBUG_VIEW, "END"); +} + +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Return object at (x,y). */ +/*---------------------------------------------------------------------------*/ +static gboolean +object_at (glView *view, + gdouble x, + gdouble y) +{ + GnomeCanvasItem *item, *p_item; + GList *p; + + gl_debug (DEBUG_VIEW, ""); + + g_return_val_if_fail (GL_IS_VIEW (view), FALSE); + + item = gnome_canvas_get_item_at (GNOME_CANVAS (view->canvas), x, y); + + /* No item is at x, y */ + if (item == NULL) + return FALSE; + + /* ignore our background items */ + if (g_list_find (view->bg_item_list, item) != NULL) + return FALSE; + + return TRUE; +} + +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Is the object in our current selection? */ +/*---------------------------------------------------------------------------*/ +static gboolean +is_object_selected (glViewObject *view_object) +{ + glView *view; + + gl_debug (DEBUG_VIEW, ""); + + g_return_val_if_fail (GL_IS_VIEW_OBJECT (view_object), FALSE); + + view = gl_view_object_get_view (view_object); + if (g_list_find (view->selected_object_list, view_object) == NULL) { + return FALSE; + } + return TRUE; +} + /*****************************************************************************/ /* Is our current selection empty? */ /*****************************************************************************/ @@ -992,6 +1163,8 @@ gl_view_delete_selection (glView *view) g_object_unref (G_OBJECT (p->data)); } + g_signal_emit (G_OBJECT(view), signals[SELECTION_CHANGED], 0); + gl_debug (DEBUG_VIEW, "END"); } @@ -1166,6 +1339,31 @@ gl_view_paste (glView *view) gl_debug (DEBUG_VIEW, "END"); } +/*---------------------------------------------------------------------------*/ +/* PRIVATE. move selected objects */ +/*---------------------------------------------------------------------------*/ +static void +move_selection (glView *view, + gdouble dx, + gdouble dy) +{ + GList *p; + glLabelObject *object; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW (view)); + + for (p = view->selected_object_list; p != NULL; p = p->next) { + + object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data)); + gl_label_object_set_position_relative (object, dx, dy); + + } + + gl_debug (DEBUG_VIEW, "END"); +} + /*****************************************************************************/ /* Zoom in one "notch" */ /*****************************************************************************/ @@ -1435,25 +1633,23 @@ canvas_event_arrow_mode (GnomeCanvas *canvas, switch (event->key.keyval) { case GDK_Left: case GDK_KP_Left: - move_selected_items (view, - -1.0 / (view->scale), - 0.0); + move_selection (view, + -1.0 / (view->scale), 0.0); break; case GDK_Up: case GDK_KP_Up: - move_selected_items (view, 0.0, - -1.0 / (view->scale)); + move_selection (view, + 0.0, -1.0 / (view->scale)); break; case GDK_Right: case GDK_KP_Right: - move_selected_items (view, - 1.0 / (view->scale), - 0.0); + move_selection (view, + 1.0 / (view->scale), 0.0); break; case GDK_Down: case GDK_KP_Down: - move_selected_items (view, 0.0, - 1.0 / (view->scale)); + move_selection (view, + 0.0, 1.0 / (view->scale)); break; case GDK_Delete: case GDK_KP_Delete: @@ -1476,140 +1672,6 @@ canvas_event_arrow_mode (GnomeCanvas *canvas, } -/*---------------------------------------------------------------------------*/ -/* PRIVATE. Select all objects within given rectangular region. */ -/*---------------------------------------------------------------------------*/ -static void -select_region (glView *view, - gdouble x1, - gdouble y1, - gdouble x2, - gdouble y2) -{ - GList *p; - glViewObject *view_object; - glLabelObject *object; - gdouble i_x1, i_y1, i_x2, i_y2, w, h; - - gl_debug (DEBUG_VIEW, "START"); - - g_return_if_fail (GL_IS_VIEW (view)); - g_return_if_fail ((x1 <= x2) && (y1 <= y2)); - - for (p = view->object_list; p != NULL; p = p->next) { - view_object = GL_VIEW_OBJECT(p->data); - if (!object_selected (view_object)) { - - object = gl_view_object_get_object (view_object); - - gl_label_object_get_position (object, &i_x1, &i_y1); - gl_label_object_get_size (object, &w, &h); - i_x2 = i_x1 + w; - i_y2 = i_y1 + h; - if ((i_x1 >= x1) && (i_x2 <= x2) && (i_y1 >= y1) - && (i_y2 <= y2)) { - select_object (view_object); - } - - } - } - - gl_debug (DEBUG_VIEW, "END"); -} - -/*---------------------------------------------------------------------------*/ -/* PRIVATE. Select an object. */ -/*---------------------------------------------------------------------------*/ -static void -select_object (glViewObject *view_object) -{ - glView *view; - - gl_debug (DEBUG_VIEW, "START"); - - g_return_if_fail (GL_IS_VIEW_OBJECT (view_object)); - - view = gl_view_object_get_view (view_object); - - if (!object_selected (view_object)) { - view->selected_object_list = - g_list_prepend (view->selected_object_list, view_object); - } - gl_view_object_show_highlight (view_object); - gtk_widget_grab_focus (GTK_WIDGET (view->canvas)); - - gl_debug (DEBUG_VIEW, "END"); -} - -/*---------------------------------------------------------------------------*/ -/* PRIVATE. Un-select object. */ -/*---------------------------------------------------------------------------*/ -static void -unselect_object (glViewObject *view_object) -{ - glView *view; - - gl_debug (DEBUG_VIEW, "START"); - - g_return_if_fail (GL_IS_VIEW_OBJECT (view_object)); - - view = gl_view_object_get_view (view_object); - - gl_view_object_hide_highlight (view_object); - - view->selected_object_list = - g_list_remove (view->selected_object_list, view_object); - - gl_debug (DEBUG_VIEW, "END"); -} - -/*---------------------------------------------------------------------------*/ -/* PRIVATE. Return object at (x,y). */ -/*---------------------------------------------------------------------------*/ -static gboolean -object_at (glView *view, - gdouble x, - gdouble y) -{ - GnomeCanvasItem *item, *p_item; - GList *p; - - gl_debug (DEBUG_VIEW, ""); - - g_return_val_if_fail (GL_IS_VIEW (view), FALSE); - - item = gnome_canvas_get_item_at (GNOME_CANVAS (view->canvas), x, y); - - /* No item is at x, y */ - if (item == NULL) - return FALSE; - - /* ignore our background items */ - if (g_list_find (view->bg_item_list, item) != NULL) - return FALSE; - - return TRUE; -} - -/*---------------------------------------------------------------------------*/ -/* PRIVATE. Is the object in our current selection? */ -/*---------------------------------------------------------------------------*/ -static gboolean -object_selected (glViewObject *view_object) -{ - glView *view; - - gl_debug (DEBUG_VIEW, ""); - - g_return_val_if_fail (GL_IS_VIEW_OBJECT (view_object), FALSE); - - view = gl_view_object_get_view (view_object); - if (g_list_find (view->selected_object_list, view_object) == NULL) { - return FALSE; - } - return TRUE; -} - /*****************************************************************************/ /* Item event handler. */ /*****************************************************************************/ @@ -1667,20 +1729,29 @@ item_event_arrow_mode (GnomeCanvasItem *item, switch (event->button.button) { case 1: if (control_key_pressed) { - if (object_selected (view_object)) { + if (is_object_selected (view_object)) { /* Un-selecting a selected item */ unselect_object (view_object); + g_signal_emit (G_OBJECT(view), + signals[SELECTION_CHANGED], + 0); return TRUE; } else { /* Add to current selection */ select_object (view_object); + g_signal_emit (G_OBJECT(view), + signals[SELECTION_CHANGED], + 0); } } else { - if (!object_selected (view_object)) { + if (!is_object_selected (view_object)) { /* No control, key so remove any selections before adding */ gl_view_unselect_all (view); /* Add to current selection */ select_object (view_object); + g_signal_emit (G_OBJECT(view), + signals[SELECTION_CHANGED], + 0); } } /* Go into dragging mode while button remains pressed. */ @@ -1697,7 +1768,7 @@ item_event_arrow_mode (GnomeCanvasItem *item, return TRUE; case 3: - if (!object_selected (view_object)) { + if (!is_object_selected (view_object)) { if (!control_key_pressed) { /* No control, key so remove any selections before adding */ gl_view_unselect_all (view); @@ -1705,6 +1776,9 @@ item_event_arrow_mode (GnomeCanvasItem *item, } /* Add to current selection */ select_object (view_object); + g_signal_emit (G_OBJECT(view), + signals[SELECTION_CHANGED], + 0); /* bring up apropriate menu for selection. */ popup_selection_menu (view, view_object, event); return TRUE; @@ -1732,7 +1806,7 @@ item_event_arrow_mode (GnomeCanvasItem *item, /* Dragging mode, move selection */ new_x = item_x; new_y = item_y; - move_selected_items (view, (new_x - x), (new_y - y)); + move_selection (view, (new_x - x), (new_y - y)); x = new_x; y = new_y; return TRUE; @@ -1748,6 +1822,9 @@ item_event_arrow_mode (GnomeCanvasItem *item, gnome_canvas_item_ungrab (item, event->button.time); dragging = FALSE; select_object (view_object); + g_signal_emit (G_OBJECT(view), + signals[SELECTION_CHANGED], + 0); gl_view_object_show_dialog (view_object); return TRUE; @@ -1856,31 +1933,6 @@ popup_selection_menu (glView *view, gl_debug (DEBUG_VIEW, "END"); } -/*---------------------------------------------------------------------------*/ -/* PRIVATE. move selected items */ -/*---------------------------------------------------------------------------*/ -static void -move_selected_items (glView *view, - gdouble dx, - gdouble dy) -{ - GList *p; - glLabelObject *object; - - gl_debug (DEBUG_VIEW, "START"); - - g_return_if_fail (GL_IS_VIEW (view)); - - for (p = view->selected_object_list; p != NULL; p = p->next) { - - object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data)); - gl_label_object_set_position_relative (object, dx, dy); - - } - - gl_debug (DEBUG_VIEW, "END"); -} - /*---------------------------------------------------------------------------*/ /* PRIVATE. Handle "selection-clear" signal. */ /*---------------------------------------------------------------------------*/ -- 2.39.5