/* SciGraphica - Scientific graphics and data manipulation * Copyright (C) 2001 Adrian E. Feiguin * * 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #include "sg_worksheet_menu.h" #include "sg.h" #include "sg_dialogs.h" #include "sg_clipboard.h" #include "sg_convert_dialog.h" static gpointer sg_menu_append_rows (SGplugin *plugin); static gpointer sg_menu_append_cols (SGplugin *plugin); static gpointer sg_menu_insert_rows (SGplugin *plugin); static gpointer sg_menu_insert_cols (SGplugin *plugin); static gpointer sg_menu_remove_rows (SGplugin *plugin); static gpointer sg_menu_remove_cols (SGplugin *plugin); static gpointer sg_menu_begin (SGplugin *plugin); static gpointer sg_menu_end (SGplugin *plugin); static gpointer sg_menu_reset (SGplugin *plugin); static gpointer sg_menu_cut (SGplugin *plugin); static gpointer sg_menu_copy (SGplugin *plugin); static gpointer sg_menu_paste (SGplugin *plugin); static gpointer sg_menu_clear (SGplugin *plugin); static gpointer sg_menu_clear_all (SGplugin *plugin); static gpointer sg_menu_col_properties (SGplugin *plugin); static gpointer sg_menu_set_values (SGplugin *plugin); static gpointer sg_menu_mask (SGplugin *plugin); static gpointer sg_menu_export (SGplugin *plugin); static gpointer sg_menu_import (SGplugin *plugin); static gpointer sg_menu_ascii (SGplugin *plugin); static gpointer sg_menu_convert (SGplugin *plugin); static gpointer sg_menu_convert_xyz (SGplugin *plugin); void sg_worksheet_menu_show(GtkWidget *widget, GdkEventButton *event) { GList *w; SGworksheet *worksheet = NULL; GtkWidget *data; GdkModifierType mods; w = worksheets; while(w){ worksheet = (SGworksheet *)w->data; data = worksheet->sheet; if(data && data == widget) break; w = w->next; } active_worksheet = worksheet; gdk_window_get_pointer(widget->window, NULL, NULL, &mods); if(!(mods & GDK_BUTTON3_MASK)) return; gtk_menu_popup(GTK_MENU(worksheet_menu), NULL, NULL, NULL, NULL, event->button, event->time); } void sg_worksheet_build_menu() { /* EDIT MENU */ sg_plugin_group_new("Worksheet:Edit:"); sg_plugin_new_c("Cut","Worksheet:Edit:", sg_menu_cut); sg_plugin_new_c("Copy","Worksheet:Edit:", sg_menu_copy); sg_plugin_new_c("Paste","Worksheet:Edit:", sg_menu_paste); sg_plugin_new_c("Clear","Worksheet:Edit:", sg_menu_clear); sg_plugin_new_c("Set as Begin","Worksheet:Edit:", sg_menu_begin); sg_plugin_new_c("Set as End","Worksheet:Edit:", sg_menu_begin); sg_plugin_new_c("Reset to full range","Worksheet:Edit:", sg_menu_reset); sg_plugin_new_c("Clear worksheet","Worksheet:Edit:", sg_menu_clear_all); sg_plugin_group_new("Worksheet:Edit:Convert:"); sg_plugin_new_c("Regular matrix","Worksheet:Edit:Convert:", sg_menu_convert); sg_plugin_new_c("XYZ matrix","Worksheet:Edit:Convert:", sg_menu_convert_xyz); /* COLUMN MENU */ sg_plugin_group_new("Worksheet:Column:"); sg_plugin_new_c("Add new columns","Worksheet:Column:", sg_menu_append_cols); sg_plugin_new_c("Insert columns","Worksheet:Column:", sg_menu_insert_cols); sg_plugin_new_c("Remove columns","Worksheet:Column:", sg_menu_remove_cols); sg_plugin_new_c("Properties","Worksheet:Column:", sg_menu_col_properties); /* ROW MENU */ sg_plugin_group_new("Worksheet:Row:"); sg_plugin_new_c("Add new rows","Worksheet:Row:", sg_menu_append_rows); sg_plugin_new_c("Insert rows","Worksheet:Row:", sg_menu_insert_rows); sg_plugin_new_c("Remove rows","Worksheet:Row:", sg_menu_remove_rows); /* ANALYSIS MENU */ sg_plugin_group_new("Worksheet:Analysis:"); sg_plugin_new_c("Set column values","Worksheet:Analysis:", sg_menu_set_values); sg_plugin_new_c("Mask data","Worksheet:Analysis:", sg_menu_mask); /* FILE MENU */ sg_plugin_group_new("Worksheet:Import:"); sg_plugin_group_new("Worksheet:Export:"); sg_plugin_new_c("File","Worksheet:Export:", sg_menu_export); sg_plugin_new_c("ASCII file","Worksheet:Import:", sg_menu_import); /* sg_plugin_new_c("ASCII Import Options","Worksheet:Import:", sg_menu_ascii);*/ } static gpointer sg_menu_append_rows(SGplugin *plugin) { sg_append_dialog(active_worksheet, GTK_ORIENTATION_VERTICAL); return NULL; } static gpointer sg_menu_append_cols(SGplugin *plugin) { sg_append_dialog(active_worksheet, GTK_ORIENTATION_HORIZONTAL); return NULL; } static gpointer sg_menu_insert_rows(SGplugin *plugin) { GtkSheet *sheet; GtkSheetRange range; gint nrows; sheet = GTK_SHEET(active_worksheet->sheet); range = sheet->range; nrows = range.rowi - range.row0 + 1; if(sheet->state != GTK_SHEET_ROW_SELECTED) return NULL; sg_worksheet_insert_rows(active_worksheet, sheet->range.row0, sheet->range.rowi - sheet->range.row0 + 1); return NULL; } static gpointer sg_menu_insert_cols(SGplugin *plugin) { GtkSheet *sheet; sheet = GTK_SHEET(active_worksheet->sheet); if(sheet->state == GTK_SHEET_COLUMN_SELECTED){ sg_worksheet_insert_columns(active_worksheet, sheet->range.col0, sheet->range.coli - sheet->range.col0 + 1); } return NULL; } static gpointer sg_menu_remove_rows(SGplugin *plugin) { GtkSheet *sheet; GtkSheetRange range; gint nrows; sheet = GTK_SHEET(active_worksheet->sheet); if(sheet->maxrow < 2) return NULL; range = sheet->range; nrows = range.rowi - range.row0 + 1; if(sheet->state != GTK_SHEET_ROW_SELECTED) return NULL; sg_worksheet_delete_rows(active_worksheet, sheet->range.row0, nrows); return NULL; } static gpointer sg_menu_remove_cols(SGplugin *plugin) { GtkSheet *sheet; GtkSheetRange range; gint ncols; sheet = GTK_SHEET(active_worksheet->sheet); if(sheet->maxcol < 2) return NULL; range = sheet->range; ncols = range.coli - range.col0 + 1; if(sheet->state == GTK_SHEET_COLUMN_SELECTED) sg_worksheet_delete_columns(active_worksheet, sheet->range.col0, ncols); return NULL; } static gpointer sg_menu_begin(SGplugin *plugin) { GtkSheet *sheet; sheet = GTK_SHEET(active_worksheet->sheet); sg_worksheet_set_begin(active_worksheet, sheet->range.row0); return NULL; } static gpointer sg_menu_end(SGplugin *plugin) { GtkSheet *sheet; sheet = GTK_SHEET(active_worksheet->sheet); sg_worksheet_set_end(active_worksheet, sheet->range.row0); return NULL; } static gpointer sg_menu_reset(SGplugin *plugin) { sg_worksheet_reset(active_worksheet); return NULL; } static gpointer sg_menu_cut(SGplugin *plugin) { sg_clipboard_copy(active_worksheet,TRUE); return NULL; } static gpointer sg_menu_copy(SGplugin *plugin) { sg_clipboard_copy(active_worksheet,FALSE); return NULL; } static gpointer sg_menu_paste(SGplugin *plugin) { sg_clipboard_paste(active_worksheet); return NULL; } static gpointer sg_menu_clear(SGplugin *plugin) { GtkSheet *sheet; sheet = GTK_SHEET(active_worksheet->sheet); gtk_sheet_range_clear(sheet, &sheet->range); return NULL; } static gpointer sg_menu_clear_all(SGplugin *plugin) { GtkSheet *sheet; sheet = GTK_SHEET(active_worksheet->sheet); gtk_sheet_range_clear(sheet, NULL); return NULL; } static gpointer sg_menu_col_properties(SGplugin *plugin) { GtkSheet *sheet; sheet = GTK_SHEET(active_worksheet->sheet); if(sheet->state == GTK_SHEET_COLUMN_SELECTED) sg_column_dialog(active_worksheet, sheet->range.col0); return NULL; } static gpointer sg_menu_set_values(SGplugin *plugin) { GtkSheet *sheet; sheet = GTK_SHEET(active_worksheet->sheet); if(sheet->state == GTK_SHEET_COLUMN_SELECTED) sg_formula_dialog(active_worksheet, sheet->range.col0); return NULL; } static gpointer sg_menu_mask(SGplugin *plugin) { GtkSheet *sheet; sheet = GTK_SHEET(active_worksheet->sheet); if(sheet->state == GTK_SHEET_COLUMN_SELECTED) sg_formula_dialog(active_worksheet, sheet->range.col0); return NULL; } static gpointer sg_menu_export(SGplugin *plugin) { sg_worksheet_export(); return NULL; } static gpointer sg_menu_import(SGplugin *plugin) { sg_worksheet_import(); return NULL; } static gpointer sg_menu_ascii(SGplugin *plugin) { sg_import_dialog(NULL,NULL); return NULL; } static gpointer sg_menu_convert_xyz(SGplugin *plugin) { sg_convert_dialog(); return NULL; } static gpointer sg_menu_convert(SGplugin *plugin) { sg_worksheet_to_matrix(active_worksheet); return NULL; }