Commit 033de570 authored by Arturo Espinosa's avatar Arturo Espinosa

Editing of cell contents Canvas Item Type + getting the main GUI ready.



Editing of cell contents Canvas Item Type + getting the main GUI ready.

Miguel.
parent 32092d1b
......@@ -20,6 +20,8 @@ gnumeric_SOURCES = \
item-cursor.h \
item-debug.c \
item-debug.h \
item-edit.c \
item-edit.h \
item-grid.c \
item-grid.h \
main.c \
......
/*
* The Gnumeric Sheet widget.
*
* (C) 1998 The Free Software Foundation
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
*/
#include <config.h>
#include <gnome.h>
......@@ -8,10 +16,10 @@
/* Signals emited by the Gnumeric Sheet widget */
enum {
GNUMERIC_SHEET_LAST_SIGNAL
LAST_SIGNAL
};
static guint sheet_signals [GNUMERIC_SHEET_LAST_SIGNAL] = { 0 };
static guint sheet_signals [LAST_SIGNAL] = { 0 };
static GnomeCanvasClass *sheet_parent_class;
......@@ -28,7 +36,7 @@ gnumeric_sheet_destroy (GtkObject *object)
}
static GnumericSheet *
gnumeric_sheet_create (Sheet *sheet)
gnumeric_sheet_create (Sheet *sheet, GtkWidget *entry)
{
GnumericSheet *gsheet;
GnomeCanvas *canvas;
......@@ -44,6 +52,7 @@ gnumeric_sheet_create (Sheet *sheet)
gsheet->sheet = sheet;
gsheet->top_col = 0;
gsheet->top_row = 0;
gsheet->entry = entry;
return gsheet;
}
......@@ -93,6 +102,24 @@ gnumeric_sheet_move_cursor_vertical (GnumericSheet *sheet, int count)
new_top, item_cursor->end_row + count);
}
static void
start_editing_at_cursor (GnumericSheet *sheet, GtkWidget *entry)
{
GnomeCanvasItem *item;
GnomeCanvas *canvas = GNOME_CANVAS (sheet);
item = gnome_canvas_item_new (canvas, canvas->root,
item_edit_get_type (),
"ItemEdit::Sheet", sheet->sheet,
"ItemEdit::Grid", sheet->item_grid,
"ItemEdit::Col", 2,
"ItemEdit::Row", 2,
"ItemEdit::GtkEntry", entry,
NULL);
sheet->item_editor = ITEM_EDIT (item);
}
static gint
gnumeric_sheet_key (GtkWidget *widget, GdkEventKey *event)
{
......@@ -116,7 +143,13 @@ gnumeric_sheet_key (GtkWidget *widget, GdkEventKey *event)
break;
default:
return 0;
if (!sheet->item_editor){
Workbook *wb = sheet->sheet->parent_workbook;
gtk_window_set_focus (wb->toplevel, wb->ea_input);
start_editing_at_cursor (sheet, wb->ea_input);
gtk_widget_event (sheet->entry, event);
}
}
return 1;
}
......@@ -129,8 +162,9 @@ gnumeric_sheet_new (Sheet *sheet)
GnomeCanvas *gsheet_canvas;
GnomeCanvasGroup *gsheet_group;
GtkWidget *widget;
GtkWidget *entry = sheet->parent_workbook->ea_input;
gsheet = gnumeric_sheet_create (sheet);
gsheet = gnumeric_sheet_create (sheet, entry);
gnome_canvas_set_size (GNOME_CANVAS (gsheet), 300, 100);
/* handy shortcuts */
......
......@@ -4,6 +4,7 @@
#include "item-grid.h"
#include "item-cursor.h"
#include "item-bar.h"
#include "item-edit.h"
#define GNUMERIC_TYPE_SHEET (gnumeric_sheet_get_type ())
#define GNUMERIC_SHEET(obj) (GTK_CHECK_CAST((obj), GNUMERIC_TYPE_SHEET, GnumericSheet))
......@@ -13,6 +14,7 @@
typedef struct {
GnomeCanvas canvas;
GtkWidget *entry;
Sheet *sheet;
ColType top_col;
......@@ -21,6 +23,7 @@ typedef struct {
ItemGrid *item_grid;
ItemCursor *item_cursor;
ItemBar *item_bar_col;
ItemEdit *item_editor;
} GnumericSheet;
GtkType gnumeric_sheet_get_type (void);
......
/*
* The Gnumeric Sheet widget.
*
* (C) 1998 The Free Software Foundation
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
*/
#include <config.h>
#include <gnome.h>
......@@ -8,10 +16,10 @@
/* Signals emited by the Gnumeric Sheet widget */
enum {
GNUMERIC_SHEET_LAST_SIGNAL
LAST_SIGNAL
};
static guint sheet_signals [GNUMERIC_SHEET_LAST_SIGNAL] = { 0 };
static guint sheet_signals [LAST_SIGNAL] = { 0 };
static GnomeCanvasClass *sheet_parent_class;
......@@ -28,7 +36,7 @@ gnumeric_sheet_destroy (GtkObject *object)
}
static GnumericSheet *
gnumeric_sheet_create (Sheet *sheet)
gnumeric_sheet_create (Sheet *sheet, GtkWidget *entry)
{
GnumericSheet *gsheet;
GnomeCanvas *canvas;
......@@ -44,6 +52,7 @@ gnumeric_sheet_create (Sheet *sheet)
gsheet->sheet = sheet;
gsheet->top_col = 0;
gsheet->top_row = 0;
gsheet->entry = entry;
return gsheet;
}
......@@ -93,6 +102,24 @@ gnumeric_sheet_move_cursor_vertical (GnumericSheet *sheet, int count)
new_top, item_cursor->end_row + count);
}
static void
start_editing_at_cursor (GnumericSheet *sheet, GtkWidget *entry)
{
GnomeCanvasItem *item;
GnomeCanvas *canvas = GNOME_CANVAS (sheet);
item = gnome_canvas_item_new (canvas, canvas->root,
item_edit_get_type (),
"ItemEdit::Sheet", sheet->sheet,
"ItemEdit::Grid", sheet->item_grid,
"ItemEdit::Col", 2,
"ItemEdit::Row", 2,
"ItemEdit::GtkEntry", entry,
NULL);
sheet->item_editor = ITEM_EDIT (item);
}
static gint
gnumeric_sheet_key (GtkWidget *widget, GdkEventKey *event)
{
......@@ -116,7 +143,13 @@ gnumeric_sheet_key (GtkWidget *widget, GdkEventKey *event)
break;
default:
return 0;
if (!sheet->item_editor){
Workbook *wb = sheet->sheet->parent_workbook;
gtk_window_set_focus (wb->toplevel, wb->ea_input);
start_editing_at_cursor (sheet, wb->ea_input);
gtk_widget_event (sheet->entry, event);
}
}
return 1;
}
......@@ -129,8 +162,9 @@ gnumeric_sheet_new (Sheet *sheet)
GnomeCanvas *gsheet_canvas;
GnomeCanvasGroup *gsheet_group;
GtkWidget *widget;
GtkWidget *entry = sheet->parent_workbook->ea_input;
gsheet = gnumeric_sheet_create (sheet);
gsheet = gnumeric_sheet_create (sheet, entry);
gnome_canvas_set_size (GNOME_CANVAS (gsheet), 300, 100);
/* handy shortcuts */
......
......@@ -4,6 +4,7 @@
#include "item-grid.h"
#include "item-cursor.h"
#include "item-bar.h"
#include "item-edit.h"
#define GNUMERIC_TYPE_SHEET (gnumeric_sheet_get_type ())
#define GNUMERIC_SHEET(obj) (GTK_CHECK_CAST((obj), GNUMERIC_TYPE_SHEET, GnumericSheet))
......@@ -13,6 +14,7 @@
typedef struct {
GnomeCanvas canvas;
GtkWidget *entry;
Sheet *sheet;
ColType top_col;
......@@ -21,6 +23,7 @@ typedef struct {
ItemGrid *item_grid;
ItemCursor *item_cursor;
ItemBar *item_bar_col;
ItemEdit *item_editor;
} GnumericSheet;
GtkType gnumeric_sheet_get_type (void);
......
/*
* Implements the resizable guides for columns and rows
* in the Gnumeric Spreadsheet.
*
* (C) 1998 The Free Software Foundation
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
*/
#include <config.h>
#include <gnome.h>
......
/*
* The Cursor Canvas Item: Implements a rectangular cursor
*
* (C) 1998 The Free Software Foundation
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
*/
#include <config.h>
#include <gnome.h>
......@@ -65,6 +73,9 @@ item_cursor_reconfigure (GnomeCanvasItem *item)
{
}
/*
* Returns the bounding box cordinates for box delimited by the cursor
*/
static void
item_cursor_get_pixel_coords (ItemCursor *item_cursor, int *x, int *y, int *w, int *h)
{
......
#include <config.h>
#include <gnome.h>
#include "gnumeric.h"
#include "item-grid.h"
#include "item-edit.h"
#include "item-debug.h"
static GnomeCanvasItem *item_edit_parent_class;
/* The arguments we take */
enum {
ARG_0,
ARG_SHEET, /* The Sheet * argument */
ARG_ITEM_GRID, /* The ItemGrid * argument */
ARG_GTK_ENTRY, /* The GtkEntry * argument */
ARG_COL, /* The column where this should edit */
ARG_ROW, /* The row where this should edit */
};
/*
* Returns the cordinates for the editor bounding box
*/
static void
item_edit_get_pixel_coords (ItemEdit *item_edit, int *x, int *y, int *w, int *h)
{
ItemGrid *item_grid = item_edit->item_grid;
Sheet *sheet = item_edit->sheet;
*x = sheet_col_get_distance (sheet, item_grid->left_col, item_edit->col);
*y = sheet_row_get_distance (sheet, item_grid->top_row, item_edit->row);
*w = sheet_col_get_distance (sheet, item_edit->col, item_edit->col + item_edit->col_span);
*h = sheet_row_get_distance (sheet, item_edit->row, item_edit->row + 1);
}
static void
item_edit_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height)
{
GtkWidget *canvas = GTK_WIDGET (item->canvas);
ItemEdit *item_edit = ITEM_EDIT (item);
int xd, yd, wd, hd, dx, dy;
if (!item_edit->sheet)
return;
item_edit_get_pixel_coords (item_edit, &xd, &yd, &wd, &hd);
dx = xd - x;
dy = yd - y;
gdk_draw_rectangle (drawable, canvas->style->white_gc,
TRUE,
dx + 1, dy + 1, wd - 1, hd - 1);
}
static double
item_edit_point (GnomeCanvasItem *item, double c_x, double c_y, int cx, int cy,
GnomeCanvasItem **actual_item)
{
int x, y, w, h;
item_edit_get_pixel_coords (ITEM_EDIT (item), &x, &y, &w, &h);
*actual_item = NULL;
if ((cx < x) || (cy < y) || (cx > x+w) || (cy > y+w))
return 10000.0;
*actual_item = item;
return 0.0;
}
static void
item_edit_translate (GnomeCanvasItem *item, double dx, double dy)
{
printf ("item_cursor_translate %g, %g\n", dx, dy);
}
static int
item_edit_event (GnomeCanvasItem *item, GdkEvent *event)
{
printf ("Editor event!\n");
return 0;
}
static void
item_edit_reconfigure (GnomeCanvasItem *item)
{
int x, y, w, h;
item_edit_get_pixel_coords (ITEM_EDIT (item), &x, &y, &w, &h);
item->x1 = x;
item->y1 = y;
item->x2 = x + w;
item->y2 = y + h;
gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item);
}
/*
* Instance initialization
*/
static void
item_edit_init (ItemEdit *item_edit)
{
GnomeCanvasItem *item = GNOME_CANVAS_ITEM (item_edit);
item->x1 = 0;
item->y1 = 0;
item->x2 = 1;
item->y2 = 1;
item_edit->col_span = 1;
item_edit->sheet = 0;
}
static void
item_edit_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
GnomeCanvasItem *item;
ItemEdit *item_edit;
item = GNOME_CANVAS_ITEM (o);
item_edit = ITEM_EDIT (o);
switch (arg_id){
case ARG_SHEET:
item_edit->sheet = GTK_VALUE_POINTER (*arg);
break;
case ARG_ITEM_GRID:
item_edit->item_grid = GTK_VALUE_POINTER (*arg);
break;
case ARG_GTK_ENTRY:
item_edit->editor = GTK_VALUE_POINTER (*arg);
break;
case ARG_COL:
item_edit->col = GTK_VALUE_INT (*arg);
break;
case ARG_ROW:
item_edit->row = GTK_VALUE_INT (*arg);
break;
}
}
/*
* ItemEdit class initialization
*/
static void
item_edit_class_init (ItemEditClass *item_edit_class)
{
GtkObjectClass *object_class;
GnomeCanvasItemClass *item_class;
item_edit_parent_class = gtk_type_class (gnome_canvas_item_get_type());
object_class = (GtkObjectClass *) item_edit_class;
item_class = (GnomeCanvasItemClass *) item_edit_class;
gtk_object_add_arg_type ("ItemEdit::Sheet", GTK_TYPE_POINTER,
GTK_ARG_WRITABLE, ARG_SHEET);
gtk_object_add_arg_type ("ItemEdit::Grid", GTK_TYPE_POINTER,
GTK_ARG_WRITABLE, ARG_ITEM_GRID);
gtk_object_add_arg_type ("ItemEdit::GtkEntry", GTK_TYPE_POINTER,
GTK_ARG_WRITABLE, ARG_GTK_ENTRY);
gtk_object_add_arg_type ("ItemEdit::Col", GTK_TYPE_INT,
GTK_ARG_WRITABLE, ARG_COL);
gtk_object_add_arg_type ("ItemEdit::Row", GTK_TYPE_INT,
GTK_ARG_WRITABLE, ARG_ROW);
object_class->set_arg = item_edit_set_arg;
/* GnomeCanvasItem method overrides */
item_class->draw = item_edit_draw;
item_class->point = item_edit_point;
item_class->translate = item_edit_translate;
item_class->event = item_edit_event;
item_class->reconfigure = item_edit_reconfigure;
}
GtkType
item_edit_get_type (void)
{
static GtkType item_edit_type = 0;
if (!item_edit_type) {
GtkTypeInfo item_edit_info = {
"ItemEdit",
sizeof (ItemEdit),
sizeof (ItemEditClass),
(GtkClassInitFunc) item_edit_class_init,
(GtkObjectInitFunc) item_edit_init,
NULL, /* reserved_1 */
NULL, /* reserved_2 */
(GtkClassInitFunc) NULL
};
item_edit_type = gtk_type_unique (gnome_canvas_item_get_type (), &item_edit_info);
}
return item_edit_type;
}
#ifndef ITEM_EDIT_H
#define ITEM_EDIT_H
#define ITEM_EDIT(obj) (GTK_CHECK_CAST((obj), item_edit_get_type (), ItemEdit))
#define ITEM_EDIT_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), item_edit_get_type ()))
#define IS_ITEM_EDIT(o) (GTK_CHECK_TYPE((o), item_edit_get_type ()))
typedef struct {
GnomeCanvasItem canvas_item;
/* The editor which status we reflect on the spreadsheet */
GtkWidget *editor;
ItemGrid *item_grid;
Sheet *sheet;
/* Where are we */
int col, row, col_span;
int pixel_span;
} ItemEdit;
GtkType item_edit_get_type (void);
typedef struct {
GnomeCanvasItemClass parent_class;
} ItemEditClass;
#endif
/*
* The Grid Gnome Canvas Item: Implements the grid and
* spreadsheet information display.
*
* (C) 1998 The Free Software Foundation
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
*/
#include <config.h>
#include <gnome.h>
......
......@@ -8,6 +8,12 @@ struct Workbook;
typedef struct {
GtkWidget *toplevel;
GtkWidget *notebook;
GtkWidget *table;
/* Edit area */
GtkWidget *ea_status;
GtkWidget *ea_button_box;
GtkWidget *ea_input;
Style style;
GHashTable *sheets; /* keeps a list of the Sheets on this workbook */
......
......@@ -127,6 +127,7 @@ style_border_new (StyleBorderType left, StyleBorderType right,
border = g_new0 (StyleBorder, 1);
*border = key;
g_hash_table_insert (style_border_hash, border, border);
border->ref_count = 0;
}
border->ref_count++;
......
#include <gnome.h>
#include "gnumeric.h"
/* The locations within the main table in the workbook */
#define WB_EA_LINE 0
#define WB_EA_SHEETS 1
#define WB_COLS 1
static void
quit_cmd (void)
{
......@@ -18,6 +24,52 @@ static GnomeUIInfo workbook_menu [] = {
GNOMEUIINFO_END
};
static void
workbook_setup_sheets (Workbook *wb)
{
wb->notebook = gtk_notebook_new ();
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (wb->notebook), GTK_POS_BOTTOM);
gtk_table_attach (GTK_TABLE (wb->table), wb->notebook,
0, WB_COLS, WB_EA_SHEETS, WB_EA_SHEETS+1,
GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND,
0, 0);
}
static void
workbook_setup_edit_area (Workbook *wb)
{
GtkWidget *ok_button, *cancel_button, *box, *box2;
GtkWidget *pix;
wb->ea_status = gtk_entry_new ();
wb->ea_input = gtk_entry_new ();
ok_button = gtk_button_new ();
cancel_button = gtk_button_new ();
box = gtk_hbox_new (0, 0);
box2 = gtk_hbox_new (0, 0);
gtk_widget_set_usize (wb->ea_status, 100, 0);
/* Ok */
pix = gnome_stock_pixmap_widget_new (wb->toplevel, GNOME_STOCK_BUTTON_OK);
gtk_container_add (GTK_CONTAINER (ok_button), pix);
/* Cancel */
pix = gnome_stock_pixmap_widget_new (wb->toplevel, GNOME_STOCK_BUTTON_CANCEL);
gtk_container_add (GTK_CONTAINER (cancel_button), pix);
gtk_box_pack_start (GTK_BOX (box2), wb->ea_status, 0, 0, 0);
gtk_box_pack_start (GTK_BOX (box), ok_button, 0, 0, 0);
gtk_box_pack_start (GTK_BOX (box), cancel_button, 0, 0, 0);
gtk_box_pack_start (GTK_BOX (box2), box, 0, 0, 0);
gtk_box_pack_end (GTK_BOX (box2), wb->ea_input, 1, 1, 0);
gtk_table_attach (GTK_TABLE (wb->table), box2,
0, 1, 0, 1,
GTK_FILL | GTK_EXPAND, 0, 0, 0);
}
/*
* Sets up the workbook.
* Right now it is adding some decorations to the window,
......@@ -31,12 +83,14 @@ workbook_new (void)
wb = g_new0 (Workbook, 1);
wb->toplevel = gnome_app_new ("Gnumeric", "Gnumeric");
wb->sheets = g_hash_table_new (g_str_hash, g_str_equal);
wb->notebook = gtk_notebook_new ();
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (wb->notebook), GTK_POS_BOTTOM);
gnome_app_set_contents (GNOME_APP (wb->toplevel), wb->notebook);
wb->table = gtk_table_new (0, 0, 0);
workbook_setup_edit_area (wb);
workbook_setup_sheets (wb);
gnome_app_set_contents (GNOME_APP (wb->toplevel), wb->table);
gnome_app_create_menus (GNOME_APP (wb->toplevel), workbook_menu);
gtk_widget_show_all (wb->notebook);
gtk_widget_show_all (wb->table);
return wb;
}
......@@ -96,13 +150,14 @@ workbook_attach_sheet (Workbook *wb, Sheet *sheet)
gtk_widget_show_all (t);
gtk_notebook_append_page (GTK_NOTEBOOK (wb->notebook),
t, gtk_label_new (sheet->name));
gtk_widget_grab_focus (GTK_WIDGET (sheet->toplevel));
}
Workbook *
workbook_new_with_sheets (int sheet_count)
{
GtkWidget *focus;
Workbook *wb;
Sheet *first_sheet = 0;