Commit 4e8c3f72 authored by Arturo Espinosa's avatar Arturo Espinosa

Preliminary support for editing the shape of an object.



Preliminary support for editing the shape of an object.

Miguel
parent c15908cc
1998-09-07 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-cell-format.c (apply_font_format): Optimization, walk
the row list instead of calling repeatedly the sheet_row_get
routine.
1998-09-07 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.h: Color style is now a single color
......@@ -22,6 +28,7 @@
an arbitrary cell to the text as if it were typed by the user.
(sheet_fill_selection_with): Fill the selection with a string.
>>>>>>> 1.88
1998-09-04 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_key): Fix the way the
......
1998-09-07 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-cell-format.c (apply_font_format): Optimization, walk
the row list instead of calling repeatedly the sheet_row_get
routine.
1998-09-07 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.h: Color style is now a single color
......@@ -22,6 +28,7 @@
an arbitrary cell to the text as if it were typed by the user.
(sheet_fill_selection_with): Fill the selection with a string.
>>>>>>> 1.88
1998-09-04 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_key): Fix the way the
......
1998-09-07 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-cell-format.c (apply_font_format): Optimization, walk
the row list instead of calling repeatedly the sheet_row_get
routine.
1998-09-07 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.h: Color style is now a single color
......@@ -22,6 +28,7 @@
an arbitrary cell to the text as if it were typed by the user.
(sheet_fill_selection_with): Fill the selection with a string.
>>>>>>> 1.88
1998-09-04 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_key): Fix the way the
......
1998-09-07 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-cell-format.c (apply_font_format): Optimization, walk
the row list instead of calling repeatedly the sheet_row_get
routine.
1998-09-07 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.h: Color style is now a single color
......@@ -22,6 +28,7 @@
an arbitrary cell to the text as if it were typed by the user.
(sheet_fill_selection_with): Fill the selection with a string.
>>>>>>> 1.88
1998-09-04 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_key): Fix the way the
......
......@@ -614,12 +614,19 @@ apply_font_format (Style *style, Sheet *sheet, CellList *cells)
/* Now apply it to every row in the selection */
for (l = sheet->selections; l; l = l->next){
SheetSelection *ss = l->data;
int i;
for (i = ss->start_row; i <= ss->end_row; i++){
ColRowInfo *ri;
/* Special case, the whole spreadsheet */
if (ss->start_row == 0 && ss->end_row == SHEET_MAX_ROWS-1)
sheet_row_set_internal_height (sheet, &sheet->default_row_style, height);
ri = sheet_row_get (sheet, i);
for (l = sheet->rows_info; l; l = l->next){
ColRowInfo *ri = l->data;
if (ri->pos < ss->start_row)
break;
if (ri->pos > ss->end_row)
break;
sheet_row_set_internal_height (sheet, ri, height);
}
}
......
......@@ -614,12 +614,19 @@ apply_font_format (Style *style, Sheet *sheet, CellList *cells)
/* Now apply it to every row in the selection */
for (l = sheet->selections; l; l = l->next){
SheetSelection *ss = l->data;
int i;
for (i = ss->start_row; i <= ss->end_row; i++){
ColRowInfo *ri;
/* Special case, the whole spreadsheet */
if (ss->start_row == 0 && ss->end_row == SHEET_MAX_ROWS-1)
sheet_row_set_internal_height (sheet, &sheet->default_row_style, height);
ri = sheet_row_get (sheet, i);
for (l = sheet->rows_info; l; l = l->next){
ColRowInfo *ri = l->data;
if (ri->pos < ss->start_row)
break;
if (ri->pos > ss->end_row)
break;
sheet_row_set_internal_height (sheet, ri, height);
}
}
......
#include "pixmaps/align-center.xpm"
#include "pixmaps/align-left.xpm"
#include "pixmaps/align-right.xpm"
#include "pixmaps/rect.xpm"
#include "pixmaps/line.xpm"
#include "pixmaps/oval.xpm"
/* XPM */
static char *line_xpm[] = {
/* width height num_colors chars_per_pixel */
" 24 24 2 1",
/* colors */
". c #000000",
"# c None",
/* pixels */
"########################",
"########################",
"##.#####################",
"###.####################",
"####.###################",
"#####.##################",
"######.#################",
"#######.################",
"########.###############",
"#########.##############",
"##########.#############",
"###########.############",
"############.###########",
"#############.##########",
"##############.#########",
"###############.########",
"################.#######",
"#################.######",
"##################.#####",
"###################.####",
"####################.###",
"#####################.##",
"########################",
"########################"
};
/* XPM */
static char *oval_xpm[] = {
/* width height num_colors chars_per_pixel */
" 24 24 2 1",
/* colors */
". c #000000",
"# c None",
/* pixels */
"########################",
"########################",
"########################",
"########################",
"########################",
"#########......#########",
"#######..######..#######",
"#####..##########..#####",
"####.##############.####",
"####.##############.####",
"###.################.###",
"###.################.###",
"###.################.###",
"###.################.###",
"###.################.###",
"####.##############.####",
"####.##############.####",
"#####..##########..#####",
"#######..######..#######",
"#########......#########",
"########################",
"########################",
"########################",
"########################"
};
/* XPM */
static char *rect_xpm[] = {
/* width height num_colors chars_per_pixel */
" 24 24 2 1",
/* colors */
". c #000000",
"# c None",
/* pixels */
"########################",
"########################",
"########################",
"########################",
"###...................##",
"###.#################.##",
"###.#################.##",
"###.#################.##",
"###.#################.##",
"###.#################.##",
"###.#################.##",
"###.#################.##",
"###.#################.##",
"###.#################.##",
"###.#################.##",
"###.#################.##",
"###.#################.##",
"###...................##",
"########################",
"########################",
"########################",
"########################",
"########################",
"########################"
};
......@@ -425,12 +425,13 @@ sheet_view_construct (SheetView *sheet_view)
/* Create the object group inside the GnumericSheet */
root_group = GNOME_CANVAS_GROUP (
GNOME_CANVAS (sheet_view->sheet_view)->root);
sheet_view->object_group = gnome_canvas_item_new (
root_group,
gnome_canvas_group_get_type (),
"x", 0.0,
"y", 0.0,
NULL);
sheet_view->object_group = GNOME_CANVAS_GROUP (
gnome_canvas_item_new (
root_group,
gnome_canvas_group_get_type (),
"x", 0.0,
"y", 0.0,
NULL));
/* Attach the GnumericSheet */
gtk_table_attach (table, sheet_view->sheet_view,
......
......@@ -19,10 +19,16 @@ typedef struct {
/* Object group */
GnomeCanvasGroup *object_group;
/* Temporary object used during the creation of objects
/*
* Temporary object used during the creation of objects
* in the canvas
*/
void *temp_item;
/*
* Control points for the current item
*/
GList *control_points;
/* Scrolling information */
GtkWidget *vs, *hs; /* The scrollbars */
......
......@@ -252,7 +252,7 @@ sheet_object_realize (Sheet *sheet, SheetObject *object)
}
}
static void
static SheetObject *
create_object (Sheet *sheet, gdouble to_x, gdouble to_y)
{
SheetObject *o = NULL;
......@@ -290,6 +290,8 @@ create_object (Sheet *sheet, gdouble to_x, gdouble to_y)
}
sheet_object_realize (sheet, o);
return o;
}
static int
......@@ -309,9 +311,18 @@ sheet_motion_notify (GnumericSheet *gsheet, GdkEvent *event, Sheet *sheet)
static int
sheet_button_release (GnumericSheet *gsheet, GdkEventButton *event, Sheet *sheet)
{
SheetObject *o;
/* Do not propagate this event further */
gtk_signal_emit_stop_by_name (GTK_OBJECT (gsheet), "button_release_event");
if (gsheet->sheet_view->temp_item)
sheet_object_destroy (gsheet->sheet_view->temp_item);
o = create_object (sheet, event->x, event->y);
sheet_object_make_current (sheet, o);
sheet_finish_object_creation (sheet);
return 1;
......@@ -386,3 +397,163 @@ sheet_set_mode_type (Sheet *sheet, SheetModeType mode)
GTK_SIGNAL_FUNC (sheet_button_press), sheet);
}
}
static void
sheet_object_stop_editing (SheetObject *object)
{
Sheet *sheet = object->sheet;
GList *l;
for (l = sheet->sheet_views; l; l = l->next){
GList *items;
SheetView *sheet_view = l->data;
for (items = sheet_view->control_points; items; items = items->next){
GnomeCanvasItem *item = items->data;
gtk_object_destroy (GTK_OBJECT (item));
}
g_list_free (sheet_view->control_points);
sheet_view->control_points = NULL;
}
sheet->current_object = NULL;
}
/*
* This hooks to the event for the handlebox
*/
static int
object_event (GnomeCanvasItem *item, GdkEvent *event, SheetObject *object)
{
int idx;
double *points = object->points->coords;
double x1, y1, x2, y2;
static int last_x, last_y, dx, dy;
switch (event->type){
case GDK_BUTTON_RELEASE:
object->dragging = 0;
break;
case GDK_BUTTON_PRESS:
object->dragging = 1;
last_x = event->button.x;
last_y = event->button.y;
break;
case GDK_MOTION_NOTIFY:
if (!object->dragging)
return FALSE;
idx = GPOINTER_TO_INT (gtk_object_get_user_data (item));
printf ("HERE: %d\n", idx);
switch (idx){
case 0:
case 2:
case 5:
case 7:
/* borders */
dx = event->button.x - last_x;
dy = event->button.y - last_y;
break;
case 1:
case 6:
dx = 0;
dy = event->button.y - last_y;
break;
case 3:
case 4:
dy = 0;
dx = event->button.x - last_x;
break;
}
last_x = event->button.x;
last_y = event->button.y;
gnome_canvas_item_move (item, dx, dy);
break;
default:
return FALSE;
}
return TRUE;
}
static GnomeCanvasItem *
new_control_point (GnomeCanvasGroup *group, SheetObject *object, int idx, double x, double y)
{
GnomeCanvasItem *item;
item = gnome_canvas_item_new (
group,
gnome_canvas_rect_get_type (),
"x1", x - 2,
"y1", y - 2,
"x2", x + 2,
"y2", y + 2,
"outline_color", "black",
"fill_color", "black",
NULL);
gtk_signal_connect (GTK_OBJECT (item), "event",
GTK_SIGNAL_FUNC (object_event), object);
gtk_object_set_user_data (GTK_OBJECT (item), GINT_TO_POINTER (idx));
return item;
}
static void
sheet_object_start_editing (SheetObject *object)
{
Sheet *sheet = object->sheet;
double *points = object->points->coords;
GList *l;
int i;
for (l = sheet->sheet_views; l; l = l->next){
SheetView *sheet_view = l->data;
GnomeCanvasGroup *group = sheet_view->object_group;
GnomeCanvasItem *ul [8];
ul [0] = new_control_point (group, object, 0, points [0], points [1]);
ul [1] = new_control_point (group, object, 1, (points [0] + points [2]) / 2, points [1]);
ul [2] = new_control_point (group, object, 2, points [2], points [1]);
ul [3] = new_control_point (group, object, 3, points [0], (points [1] + points [3]) / 2);
ul [4] = new_control_point (group, object, 4, points [2], (points [1] + points [3]) / 2);
ul [5] = new_control_point (group, object, 5, points [0], points [3]);
ul [6] = new_control_point (group, object, 6, (points [0] + points [2]) / 2, points [3]);
ul [7] = new_control_point (group, object, 7, points [2], points [3]);
for (i = 0; i < 8; i++)
sheet_view->control_points = g_list_prepend (sheet_view->control_points, ul [i]);
}
}
void
sheet_object_make_draggable (SheetObject *object)
{
}
void
sheet_object_make_current (Sheet *sheet, SheetObject *object)
{
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (object != NULL);
g_return_if_fail (IS_SHEET_OBJECT (object));
if (sheet->current_object == object)
return;
if (sheet->current_object)
sheet_object_stop_editing (sheet->current_object);
sheet_object_make_draggable (object);
sheet_object_start_editing (object);
sheet->current_object = object;
}
......@@ -13,6 +13,7 @@ typedef struct {
Sheet *sheet;
GList *realized_list;
SheetObjectType type;
int dragging;
String *color;
int width;
......@@ -50,5 +51,8 @@ GnomeCanvasItem *sheet_view_object_realize (SheetView *sheet_view,
void sheet_view_object_unrealize (SheetView *sheet_view,
SheetObject *object);
void sheet_object_make_current (Sheet *sheet,
SheetObject *object);
#endif
......@@ -425,12 +425,13 @@ sheet_view_construct (SheetView *sheet_view)
/* Create the object group inside the GnumericSheet */
root_group = GNOME_CANVAS_GROUP (
GNOME_CANVAS (sheet_view->sheet_view)->root);
sheet_view->object_group = gnome_canvas_item_new (
root_group,
gnome_canvas_group_get_type (),
"x", 0.0,
"y", 0.0,
NULL);
sheet_view->object_group = GNOME_CANVAS_GROUP (
gnome_canvas_item_new (
root_group,
gnome_canvas_group_get_type (),
"x", 0.0,
"y", 0.0,
NULL));
/* Attach the GnumericSheet */
gtk_table_attach (table, sheet_view->sheet_view,
......
......@@ -19,10 +19,16 @@ typedef struct {
/* Object group */
GnomeCanvasGroup *object_group;
/* Temporary object used during the creation of objects
/*
* Temporary object used during the creation of objects
* in the canvas
*/
void *temp_item;
/*
* Control points for the current item
*/
GList *control_points;
/* Scrolling information */
GtkWidget *vs, *hs; /* The scrollbars */
......
......@@ -395,7 +395,6 @@ sheet_row_set_internal_height (Sheet *sheet, ColRowInfo *ri, int height)
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (ri != NULL);
g_return_if_fail (ri != &sheet->default_row_style);
pix = sheet->last_zoom_factor_used;
......
......@@ -102,6 +102,7 @@ typedef struct {
SheetModeType mode; /* Sheet mode */
GList *objects; /* List of objects in the spreadsheet */
GList *coords; /* During creation time: keeps click coordinates */
void *current_object;
/*
* When editing a cell: the cell (may be NULL) and
......
......@@ -355,15 +355,15 @@ static GnomeUIInfo workbook_toolbar [] = {
N_("Sets the cell alignment to the right"),
right_align_cmd, NULL, align_right),
GNOMEUIINFO_SEPARATOR,
GNOMEUIINFO_ITEM_STOCK (N_("Line"),
N_("Creates a line object"),
create_line_cmd, GNOME_STOCK_PIXMAP_JUMP_TO),
GNOMEUIINFO_ITEM_STOCK (N_("Rectangle"),
N_("Creates a rectangle object"),
create_rectangle_cmd, GNOME_STOCK_PIXMAP_JUMP_TO),
GNOMEUIINFO_ITEM_STOCK (N_("Ellipse"),
N_("Creates an ellipse object"),
create_ellipse_cmd, GNOME_STOCK_PIXMAP_JUMP_TO),
GNOMEUIINFO_ITEM_DATA (N_("Line"),
N_("Creates a line object"),
create_line_cmd, NULL, line_xpm),
GNOMEUIINFO_ITEM_DATA (N_("Rectangle"),
N_("Creates a rectangle object"),
create_rectangle_cmd, NULL, rect_xpm),
GNOMEUIINFO_ITEM_DATA (N_("Ellipse"),
N_("Creates an ellipse object"),
create_ellipse_cmd, NULL, oval_xpm),
GNOMEUIINFO_END
};
......
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