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
mdi-child.h \
stock.c \
stock.h \
- menus.h \
- menus.c \
+ ui.h \
+ ui.c \
commands.h \
commands.c \
file.h \
#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"
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,
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/");
/*****************************************************************************/
-/* NEW mdi objecg. */
+/* NEW mdi object. */
/*****************************************************************************/
glMDI*
gl_mdi_new (void)
(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 ();
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 */
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. */
/*---------------------------------------------------------------------------*/
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;
}
{
/* 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");
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);
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);
+++ /dev/null
-/*
- * (GLABELS) Label and Business Card Creation program for GNOME
- *
- * menus.c: GLabels menus module
- *
- * Copyright (C) 2001-2002 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
- * 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.c from gedit2:
- *
- * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
- * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
- *
- */
-#include <config.h>
-
-#include "menus.h"
-#include "commands.h"
-#include "tools.h"
-#include "glabels.h"
-
-BonoboUIVerb gl_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),
- BONOBO_UI_VERB ("FileSaveAs", gl_cmd_file_save_as),
- BONOBO_UI_VERB ("FilePrint", gl_cmd_file_print),
- BONOBO_UI_VERB ("FileClose", gl_cmd_file_close),
- BONOBO_UI_VERB ("FileCloseAll", gl_cmd_file_close_all),
- BONOBO_UI_VERB ("FileExit", gl_cmd_file_exit),
- BONOBO_UI_VERB ("EditCut", gl_cmd_edit_cut),
- BONOBO_UI_VERB ("EditCopy", gl_cmd_edit_copy),
- BONOBO_UI_VERB ("EditPaste", gl_cmd_edit_paste),
- BONOBO_UI_VERB ("EditDelete", gl_cmd_edit_delete),
- BONOBO_UI_VERB ("EditSelectAll", gl_cmd_edit_select_all),
- BONOBO_UI_VERB ("EditUnSelectAll", gl_cmd_edit_unselect_all),
- BONOBO_UI_VERB ("ToolsArrow", gl_tools_arrow),
- BONOBO_UI_VERB ("ToolsText", gl_tools_text),
- BONOBO_UI_VERB ("ToolsBox", gl_tools_box),
- BONOBO_UI_VERB ("ToolsLine", gl_tools_line),
- BONOBO_UI_VERB ("ToolsEllipse", gl_tools_ellipse),
- BONOBO_UI_VERB ("ToolsImage", gl_tools_image),
- BONOBO_UI_VERB ("ToolsBarcode", gl_tools_barcode),
- BONOBO_UI_VERB ("ToolsZoomIn", gl_tools_zoomin),
- BONOBO_UI_VERB ("ToolsZoomOut", gl_tools_zoomout),
- BONOBO_UI_VERB ("ToolsZoom1to1", gl_tools_zoom1to1),
- BONOBO_UI_VERB ("ToolsMergeProperties", gl_tools_merge_properties),
- BONOBO_UI_VERB ("ToolsObjectProperties", gl_tools_object_properties),
- BONOBO_UI_VERB ("ToolsRaiseObjects", gl_tools_raise_objects),
- BONOBO_UI_VERB ("ToolsLowerObjects", gl_tools_lower_objects),
- BONOBO_UI_VERB ("SettingsPreferences", gl_cmd_settings_preferences),
- BONOBO_UI_VERB ("HelpContents", gl_cmd_help_contents),
- BONOBO_UI_VERB ("About", gl_cmd_help_about),
-
- BONOBO_UI_VERB_END
-};
-
-gchar* gl_menus_no_docs_sensible_verbs [] = {
- "/commands/FileSave",
- "/commands/FileSaveAs",
- "/commands/FilePrint",
- "/commands/FilePrintPreview",
- "/commands/FileClose",
- "/commands/FileCloseAll",
- "/commands/EditUndo",
- "/commands/EditRedo",
- "/commands/EditCut",
- "/commands/EditCopy",
- "/commands/EditPaste",
- "/commands/EditDelete",
- "/commands/EditSelectAll",
- "/commands/EditUnSelectAll",
- "/commands/ToolsArrow",
- "/commands/ToolsText",
- "/commands/ToolsLine",
- "/commands/ToolsBox",
- "/commands/ToolsEllipse",
- "/commands/ToolsImage",
- "/commands/ToolsBarcode",
- "/commands/ToolsZoomIn",
- "/commands/ToolsZoomOut",
- "/commands/ToolsZoom1to1",
- "/commands/ToolsMergeProperties",
- "/commands/ToolsObjectProperties",
- "/commands/ToolsRaiseObjects",
- "/commands/ToolsLowerObjects",
-
- NULL
-};
-
-gchar* gl_menus_not_modified_doc_sensible_verbs [] = {
- "/commands/FileSave",
-
- NULL
-};
-
-
-void
-gl_menus_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);
-}
-
-void
-gl_menus_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);
- }
-}
-
-void
-gl_menus_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);
-}
-
-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)
-{
- BonoboUIComponent *ui_component;
- gchar *item_path;
- gchar *cmd;
-
- g_return_if_fail (window != NULL);
- g_return_if_fail (path != NULL);
- g_return_if_fail (label != NULL);
- 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));
- if (!bonobo_ui_component_path_exists (ui_component, item_path, NULL)) {
- gchar *xml;
-
- xml = g_strdup_printf ("<menuitem name=\"%s\" verb=\"\""
- " _label=\"%s\""
- " _tip=\"%s\" hident=\"0\" />", name,
- label, tooltip);
-
-
- if (stock_pixmap != NULL) {
- cmd = g_strdup_printf ("<cmd name=\"%s\""
- " pixtype=\"stock\" pixname=\"%s\" />",
- name, stock_pixmap);
- }
- else {
- cmd = g_strdup_printf ("<cmd name=\"%s\" />", name);
- }
-
-
- bonobo_ui_component_set_translate (ui_component, path,
- xml, NULL);
-
- bonobo_ui_component_set_translate (ui_component, "/commands/",
- cmd, NULL);
-
- bonobo_ui_component_add_verb (ui_component, name, cb, NULL);
-
- g_free (xml);
- g_free (cmd);
- }
-
- g_free (item_path);
-}
-
-void
-gl_menus_remove_menu_item (BonoboWindow *window, const gchar *path,
- const gchar *name)
-{
- BonoboUIComponent *ui_component;
- gchar *item_path;
-
- g_return_if_fail (window != NULL);
- g_return_if_fail (path != NULL);
- 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));
-
- if (bonobo_ui_component_path_exists (ui_component, item_path, NULL)) {
- gchar *cmd;
-
- cmd = g_strdup_printf ("/commands/%s", name);
-
- bonobo_ui_component_rm (ui_component, item_path, NULL);
- bonobo_ui_component_rm (ui_component, cmd, NULL);
-
- g_free (cmd);
- }
-
- g_free (item_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)
-{
- GList* top_windows;
-
- top_windows = glabels_get_top_windows ();
- g_return_if_fail (top_windows != NULL);
-
- while (top_windows)
- {
- BonoboWindow* window = BONOBO_WINDOW (top_windows->data);
-
-
- gl_menus_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)
-{
- GList* top_windows;
-
- top_windows = glabels_get_top_windows ();
- g_return_if_fail (top_windows != NULL);
-
- while (top_windows)
- {
- BonoboWindow* window = BONOBO_WINDOW (top_windows->data);
-
-
- gl_menus_remove_menu_item (window, path, name);
-
-
- top_windows = g_list_next (top_windows);
- }
-}
+++ /dev/null
-/*
- * (GLABELS) Label and Business Card Creation program for GNOME
- *
- * menus.h: GLabels menus module header file
- *
- * Copyright (C) 2001-2002 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
- * 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 <bonobo/bonobo-ui-component.h>
-#include <bonobo/bonobo-ui-engine.h>
-#include <bonobo/bonobo-window.h>
-
-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__ */
--- /dev/null
+/*
+ * (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ * ui.c: GLabels ui module
+ *
+ * Copyright (C) 2001-2002 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
+ * 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.c from gedit2:
+ *
+ * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
+ * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
+ *
+ */
+#include <config.h>
+
+#include "ui.h"
+#include "commands.h"
+#include "tools.h"
+#include "glabels.h"
+
+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),
+ BONOBO_UI_VERB ("FileSaveAs", gl_cmd_file_save_as),
+ BONOBO_UI_VERB ("FilePrint", gl_cmd_file_print),
+ BONOBO_UI_VERB ("FileClose", gl_cmd_file_close),
+ BONOBO_UI_VERB ("FileCloseAll", gl_cmd_file_close_all),
+ BONOBO_UI_VERB ("FileExit", gl_cmd_file_exit),
+ BONOBO_UI_VERB ("EditCut", gl_cmd_edit_cut),
+ BONOBO_UI_VERB ("EditCopy", gl_cmd_edit_copy),
+ BONOBO_UI_VERB ("EditPaste", gl_cmd_edit_paste),
+ BONOBO_UI_VERB ("EditDelete", gl_cmd_edit_delete),
+ BONOBO_UI_VERB ("EditSelectAll", gl_cmd_edit_select_all),
+ BONOBO_UI_VERB ("EditUnSelectAll", gl_cmd_edit_unselect_all),
+ BONOBO_UI_VERB ("ToolsArrow", gl_tools_arrow),
+ BONOBO_UI_VERB ("ToolsText", gl_tools_text),
+ BONOBO_UI_VERB ("ToolsBox", gl_tools_box),
+ BONOBO_UI_VERB ("ToolsLine", gl_tools_line),
+ BONOBO_UI_VERB ("ToolsEllipse", gl_tools_ellipse),
+ BONOBO_UI_VERB ("ToolsImage", gl_tools_image),
+ BONOBO_UI_VERB ("ToolsBarcode", gl_tools_barcode),
+ BONOBO_UI_VERB ("ToolsZoomIn", gl_tools_zoomin),
+ BONOBO_UI_VERB ("ToolsZoomOut", gl_tools_zoomout),
+ BONOBO_UI_VERB ("ToolsZoom1to1", gl_tools_zoom1to1),
+ BONOBO_UI_VERB ("ToolsMergeProperties", gl_tools_merge_properties),
+ BONOBO_UI_VERB ("ToolsObjectProperties", gl_tools_object_properties),
+ BONOBO_UI_VERB ("ToolsRaiseObjects", gl_tools_raise_objects),
+ BONOBO_UI_VERB ("ToolsLowerObjects", gl_tools_lower_objects),
+ BONOBO_UI_VERB ("SettingsPreferences", gl_cmd_settings_preferences),
+ BONOBO_UI_VERB ("HelpContents", gl_cmd_help_contents),
+ BONOBO_UI_VERB ("About", gl_cmd_help_about),
+
+ BONOBO_UI_VERB_END
+};
+
+gchar* gl_ui_no_docs_sensible_verbs [] = {
+ "/commands/FileSave",
+ "/commands/FileSaveAs",
+ "/commands/FilePrint",
+ "/commands/FilePrintPreview",
+ "/commands/FileClose",
+ "/commands/FileCloseAll",
+ "/commands/EditUndo",
+ "/commands/EditRedo",
+ "/commands/EditCut",
+ "/commands/EditCopy",
+ "/commands/EditPaste",
+ "/commands/EditDelete",
+ "/commands/EditSelectAll",
+ "/commands/EditUnSelectAll",
+ "/commands/ToolsArrow",
+ "/commands/ToolsText",
+ "/commands/ToolsLine",
+ "/commands/ToolsBox",
+ "/commands/ToolsEllipse",
+ "/commands/ToolsImage",
+ "/commands/ToolsBarcode",
+ "/commands/ToolsZoomIn",
+ "/commands/ToolsZoomOut",
+ "/commands/ToolsZoom1to1",
+ "/commands/ToolsMergeProperties",
+ "/commands/ToolsObjectProperties",
+ "/commands/ToolsRaiseObjects",
+ "/commands/ToolsLowerObjects",
+
+ NULL
+};
+
+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_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);
+}
+
+void
+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);
+ }
+}
+
+void
+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);
+}
+
+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)
+{
+ BonoboUIComponent *ui_component;
+ gchar *item_path;
+ gchar *cmd;
+
+ g_return_if_fail (window != NULL);
+ g_return_if_fail (path != NULL);
+ g_return_if_fail (label != NULL);
+ 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));
+ if (!bonobo_ui_component_path_exists (ui_component, item_path, NULL)) {
+ gchar *xml;
+
+ xml = g_strdup_printf ("<menuitem name=\"%s\" verb=\"\""
+ " _label=\"%s\""
+ " _tip=\"%s\" hident=\"0\" />", name,
+ label, tooltip);
+
+
+ if (stock_pixmap != NULL) {
+ cmd = g_strdup_printf ("<cmd name=\"%s\""
+ " pixtype=\"stock\" pixname=\"%s\" />",
+ name, stock_pixmap);
+ }
+ else {
+ cmd = g_strdup_printf ("<cmd name=\"%s\" />", name);
+ }
+
+
+ bonobo_ui_component_set_translate (ui_component,
+ path,
+ xml,
+ NULL);
+
+ bonobo_ui_component_set_translate (ui_component,
+ "/commands/",
+ cmd,
+ NULL);
+
+ bonobo_ui_component_add_verb (ui_component, name, cb, NULL);
+
+ g_free (xml);
+ g_free (cmd);
+ }
+
+ g_free (item_path);
+}
+
+void
+gl_ui_remove_menu_item (BonoboWindow *window,
+ const gchar *path,
+ const gchar *name)
+{
+ BonoboUIComponent *ui_component;
+ gchar *item_path;
+
+ g_return_if_fail (window != NULL);
+ g_return_if_fail (path != NULL);
+ 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));
+
+ if (bonobo_ui_component_path_exists (ui_component, item_path, NULL)) {
+ gchar *cmd;
+
+ cmd = g_strdup_printf ("/commands/%s", name);
+
+ bonobo_ui_component_rm (ui_component, item_path, NULL);
+ bonobo_ui_component_rm (ui_component, cmd, NULL);
+
+ g_free (cmd);
+ }
+
+ g_free (item_path);
+}
+
+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)
+{
+ GList* top_windows;
+
+ top_windows = glabels_get_top_windows ();
+ g_return_if_fail (top_windows != NULL);
+
+ while (top_windows)
+ {
+ BonoboWindow* window = BONOBO_WINDOW (top_windows->data);
+
+
+ gl_ui_add_menu_item (window,
+ path,
+ name,
+ label,
+ tooltip,
+ stock_pixmap,
+ cb);
+
+ top_windows = g_list_next (top_windows);
+ }
+}
+
+void
+gl_ui_remove_menu_item_all (const gchar *path,
+ const gchar *name)
+{
+ GList* top_windows;
+
+ top_windows = glabels_get_top_windows ();
+ g_return_if_fail (top_windows != NULL);
+
+ while (top_windows)
+ {
+ BonoboWindow* window = BONOBO_WINDOW (top_windows->data);
+
+
+ gl_ui_remove_menu_item (window, path, name);
+
+
+ top_windows = g_list_next (top_windows);
+ }
+}
--- /dev/null
+/*
+ * (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ * ui.h: GLabels UI module header file
+ *
+ * Copyright (C) 2001-2002 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
+ * 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 <bonobo/bonobo-ui-component.h>
+#include <bonobo/bonobo-ui-engine.h>
+#include <bonobo/bonobo-window.h>
+
+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__ */
#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;
/* 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);
\f
/****************************************************************************/
/* Boilerplate Object stuff. */
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");
}
select_object (view_object);
+ g_signal_emit (G_OBJECT(view), signals[SELECTION_CHANGED], 0);
+
gl_debug (DEBUG_VIEW, "END");
}
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");
}
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? */
/*****************************************************************************/
g_object_unref (G_OBJECT (p->data));
}
+ g_signal_emit (G_OBJECT(view), signals[SELECTION_CHANGED], 0);
+
gl_debug (DEBUG_VIEW, "END");
}
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" */
/*****************************************************************************/
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:
}
-/*---------------------------------------------------------------------------*/
-/* 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. */
/*****************************************************************************/
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. */
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);
}
/* 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;
/* 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;
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;
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. */
/*---------------------------------------------------------------------------*/