Commit c3468eb6 authored by Arturo Espinosa's avatar Arturo Espinosa

Drag and Drop editing actions work now:



Drag and Drop editing actions work now:

	- Copy cells by contorl-dragging the border of a selection
	- Move cells by dragging border of a selection
	- Do other operations by right-button-dragging the selection border

Miguel
parent c73132df
1998-08-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/item-cursor.c (item_cursor_do_drop): New function: Handles
the action from the cursor drag operation.
* src/gnumeric-util.c (run_popup_menu): New utility function to
popup menus created from an array of strings.
* src/sheet.c (sheet_selection_cut, sheet_selection_copy): They
now return whether it was possible to perform the operation.
1998-08-18 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_set_alignment): Provide a way to change the
......
1998-08-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/item-cursor.c (item_cursor_do_drop): New function: Handles
the action from the cursor drag operation.
* src/gnumeric-util.c (run_popup_menu): New utility function to
popup menus created from an array of strings.
* src/sheet.c (sheet_selection_cut, sheet_selection_copy): They
now return whether it was possible to perform the operation.
1998-08-18 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_set_alignment): Provide a way to change the
......
1998-08-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/item-cursor.c (item_cursor_do_drop): New function: Handles
the action from the cursor drag operation.
* src/gnumeric-util.c (run_popup_menu): New utility function to
popup menus created from an array of strings.
* src/sheet.c (sheet_selection_cut, sheet_selection_copy): They
now return whether it was possible to perform the operation.
1998-08-18 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_set_alignment): Provide a way to change the
......
1998-08-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/item-cursor.c (item_cursor_do_drop): New function: Handles
the action from the cursor drag operation.
* src/gnumeric-util.c (run_popup_menu): New utility function to
popup menus created from an array of strings.
* src/sheet.c (sheet_selection_cut, sheet_selection_copy): They
now return whether it was possible to perform the operation.
1998-08-18 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_set_alignment): Provide a way to change the
......
<section>Copying and moving cells</section>
There are two ways of moving and copying cells in Gnumeric:
<item>Using copy/cut/paste operations</item>
<item>Using the mouse to drag the selection</item>
<subsection>Using the mouse to drag the selection</subsection>
Dragging the border of a selection to a target area will move the
cells.
Dragging the border of a selection to a target area while holding the
control key down will perform a move.
If you use the right button for performing the drag, a menu with the
possible options appears when you release it.
......@@ -269,7 +269,7 @@ dialog_paste_special (void)
result = 0;
i = gtk_radio_group_get_selected (group_type);
printf ("Seleccion: %d\n", i);
switch (i){
case 0: /* all */
result = PASTE_ALL_TYPES;
......
......@@ -51,6 +51,55 @@ gtk_radio_button_select (GSList *group, int n)
GSList *l;
int len = g_slist_length (group);
l = g_slist_nth (group, n);
l = g_slist_nth (group, len - n);
gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (l->data));
}
static void
popup_menu_item_activated (GtkWidget *item, void *value)
{
int *dest = gtk_object_get_user_data (GTK_OBJECT (item));
*dest = GPOINTER_TO_INT (value);
gtk_main_quit ();
}
int
run_popup_menu (GdkEvent *event, char **strings)
{
GtkWidget *menu;
int i;
/* Create the popup menu */
menu = gtk_menu_new ();
for (i = 0;*strings; strings++, i++){
GtkWidget *item;
item = gtk_menu_item_new_with_label (_(*strings));
gtk_widget_show (item);
gtk_signal_connect (
GTK_OBJECT (item), "activate",
GTK_SIGNAL_FUNC (popup_menu_item_activated), GINT_TO_POINTER (i));
/* Pass a pointer where we want the result stored */
gtk_object_set_user_data (GTK_OBJECT (item), &i);
gtk_menu_append (GTK_MENU (menu), item);
}
i = -1;
/* Configure it: */
gtk_signal_connect (GTK_OBJECT (menu), "deactivate",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
/* popup the menu */
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
event->button.button, event->button.time);
gtk_main ();
gtk_widget_destroy (menu);
return i;
}
......@@ -3,6 +3,9 @@
void gnumeric_notice (char *str);
/* A simple routine for making a popup menu */
int run_popup_menu (GdkEvent *event, char **strings);
/* Utility routine as Gtk does not have any decent routine to do this */
int gtk_radio_group_get_selected (GSList *radio_group);
void gtk_radio_button_select (GSList *group, int n);
......
......@@ -51,6 +51,55 @@ gtk_radio_button_select (GSList *group, int n)
GSList *l;
int len = g_slist_length (group);
l = g_slist_nth (group, n);
l = g_slist_nth (group, len - n);
gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (l->data));
}
static void
popup_menu_item_activated (GtkWidget *item, void *value)
{
int *dest = gtk_object_get_user_data (GTK_OBJECT (item));
*dest = GPOINTER_TO_INT (value);
gtk_main_quit ();
}
int
run_popup_menu (GdkEvent *event, char **strings)
{
GtkWidget *menu;
int i;
/* Create the popup menu */
menu = gtk_menu_new ();
for (i = 0;*strings; strings++, i++){
GtkWidget *item;
item = gtk_menu_item_new_with_label (_(*strings));
gtk_widget_show (item);
gtk_signal_connect (
GTK_OBJECT (item), "activate",
GTK_SIGNAL_FUNC (popup_menu_item_activated), GINT_TO_POINTER (i));
/* Pass a pointer where we want the result stored */
gtk_object_set_user_data (GTK_OBJECT (item), &i);
gtk_menu_append (GTK_MENU (menu), item);
}
i = -1;
/* Configure it: */
gtk_signal_connect (GTK_OBJECT (menu), "deactivate",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
/* popup the menu */
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
event->button.button, event->button.time);
gtk_main ();
gtk_widget_destroy (menu);
return i;
}
......@@ -3,6 +3,9 @@
void gnumeric_notice (char *str);
/* A simple routine for making a popup menu */
int run_popup_menu (GdkEvent *event, char **strings);
/* Utility routine as Gtk does not have any decent routine to do this */
int gtk_radio_group_get_selected (GSList *radio_group);
void gtk_radio_button_select (GSList *group, int n);
......
......@@ -14,6 +14,7 @@
#include "item-cursor.h"
#include "item-debug.h"
#include "gnumeric-sheet.h"
#include "gnumeric-util.h"
static GnomeCanvasItem *item_cursor_parent_class;
......@@ -306,10 +307,6 @@ item_cursor_request_redraw (ItemCursor *item_cursor)
int x, y, w, h;
item_cursor_get_pixel_coords (item_cursor, &x, &y, &w, &h);
#if 0
printf ("Requesting redraw: %d %d %d %d\n",
x - 2, y - 2, x + w + 5, y + h + 5);
#endif
gnome_canvas_request_redraw (canvas, x - 2, y - 2, x + w + 5, y + h + 5);
}
......@@ -427,13 +424,107 @@ item_cursor_selection_event (GnomeCanvasItem *item, GdkEvent *event)
}
static gboolean
item_cursor_target_region_ok (ItemCursor *item_cursor)
{
/* FIXME: check the destination range and if any cell
* has values, ask for confirmation
*/
return TRUE;
}
typedef enum {
ACTION_NONE = -1,
ACTION_COPY_CELLS,
ACTION_MOVE_CELLS,
ACTION_COPY_FORMATS,
ACTION_COPY_VALUES,
ACTION_SHIFT_DOWN_AND_COPY,
ACTION_SHIFT_RIGHT_AND_COPY,
ACTION_SHIFT_DOWN_AND_MOVE,
ACTION_SHIFT_RIGHT_AND_MOVE
} ActionType;
static void
item_cursor_do_action (ItemCursor *item_cursor, ActionType action)
{
Sheet *sheet = item_cursor->sheet;
int col = item_cursor->start_col;
int row = item_cursor->start_row;
switch (action){
case ACTION_NONE:
return;
case ACTION_COPY_CELLS:
if (!item_cursor_target_region_ok (item_cursor))
return;
if (!sheet_selection_copy (sheet))
return;
sheet_selection_paste (sheet, col, row, PASTE_ALL_TYPES);
return;
case ACTION_MOVE_CELLS:
if (!item_cursor_target_region_ok (item_cursor))
return;
if (!sheet_selection_cut (sheet))
return;
sheet_selection_paste (sheet, col, row, PASTE_ALL_TYPES);
return;
case ACTION_COPY_FORMATS:
if (!item_cursor_target_region_ok (item_cursor))
return;
if (!sheet_selection_copy (sheet))
return;
sheet_selection_paste (sheet, col, row, PASTE_FORMATS);
return;
case ACTION_COPY_VALUES:
if (!item_cursor_target_region_ok (item_cursor))
return;
if (!sheet_selection_copy (sheet))
return;
sheet_selection_paste (sheet, col, row, PASTE_VALUES);
return;
case ACTION_SHIFT_DOWN_AND_COPY:
case ACTION_SHIFT_RIGHT_AND_COPY:
case ACTION_SHIFT_DOWN_AND_MOVE:
case ACTION_SHIFT_RIGHT_AND_MOVE:
g_warning ("Operation not yet implemeneted\n");
}
}
static char *drop_context_actions [] = {
N_("Copy"),
N_("Move"),
N_("Copy formats"),
N_("Copy values"),
N_("Shift cells down and copy"),
N_("Shift cells right and copy"),
N_("Shift cells down and move"),
N_("Shift cells right and move"),
NULL,
};
/*
* Invoked when the item has been dropped
*/
static void
item_cursor_do_drop (ItemCursor *item_cursor, GdkEvent *event)
{
ActionType action;
/* Find out what to do */
if (event->button.button == 3)
action = (ActionType) run_popup_menu (event, drop_context_actions);
else if (event->button.state & GDK_CONTROL_MASK)
action = ACTION_COPY_CELLS;
else
action = ACTION_MOVE_CELLS;
item_cursor_do_action (item_cursor, action);
}
static void
......
......@@ -13,6 +13,7 @@
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "item-debug.h"
#include "dialogs.h"
static GnomeCanvasItem *item_grid_parent_class;
......@@ -178,6 +179,7 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid,
if (!cell)
return;
printf ("Drawing %d %d: ", col, row);
/* The offsets where we start drawing the text */
x_offset = y_offset = 0;
......@@ -275,7 +277,7 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid,
pixels = 0;
if (!cell->entered_text)
return;
do {
char *text;
......
......@@ -1636,17 +1636,17 @@ sheet_clear_region (Sheet *sheet, int start_col, int start_row, int end_col, int
g_list_free (destroyable_cells);
}
void
gboolean
sheet_selection_copy (Sheet *sheet)
{
SheetSelection *ss;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (sheet->selections);
g_return_val_if_fail (sheet != NULL, FALSE);
g_return_val_if_fail (IS_SHEET (sheet), FALSE);
g_return_val_if_fail (sheet->selections, FALSE);
if (g_list_length (sheet->selections) != 1){
gnumeric_notice (_("Can not copy non-contiguous selections"));
return;
return FALSE;
}
ss = sheet->selections->data;
......@@ -1658,26 +1658,30 @@ sheet_selection_copy (Sheet *sheet)
sheet,
ss->start_col, ss->start_row,
ss->end_col, ss->end_row);
return TRUE;
}
void
gboolean
sheet_selection_cut (Sheet *sheet)
{
SheetSelection *ss;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (sheet->selections);
g_return_val_if_fail (sheet != NULL, FALSE);
g_return_val_if_fail (IS_SHEET (sheet), FALSE);
g_return_val_if_fail (sheet->selections, FALSE);
if (g_list_length (sheet->selections) != 1){
gnumeric_notice (_("Can not cut non-contiguous selections"));
return;
return FALSE;
}
ss = sheet->selections->data;
sheet_selection_copy (sheet);
sheet_clear_region (sheet, ss->start_col, ss->start_row, ss->end_col, ss->end_row);
return TRUE;
}
void
......
......@@ -121,8 +121,8 @@ void sheet_selection_append_range (Sheet *sheet,
CellList *sheet_selection_to_list (Sheet *sheet);
/* Cut/Copy/Paste on the workbook selection */
void sheet_selection_copy (Sheet *sheet);
void sheet_selection_cut (Sheet *sheet);
gboolean sheet_selection_copy (Sheet *sheet);
gboolean sheet_selection_cut (Sheet *sheet);
void sheet_selection_paste (Sheet *sheet,
int dest_col, int dest_row,
int paste_flags);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment