Commit 02fbd7f8 authored by Arturo Espinosa's avatar Arturo Espinosa

Lots of stuff.



Lots of stuff.

Mouse resizing columns and rows is fully working.  Other random
internal goodies, the engine is nicer, the code is nicer, the stuff is
starting to make sense, etc.

It is nice to `see' what it does right now.

Miguel.
parent 3cad2420
1998-07-11 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c (style_duplicate): New function. Does style
duplication.
* src/sheet.c (sheet_new): Simple hook signals to test the code.
* src/item-bar.c (item_bar_class_init): Added signals:
size_changed and selection_changed.
(item_bar_event): Add support for resizing columns and rows.
1998-07-10 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c: New file. Implement the style manager for the
......
1998-07-11 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c (style_duplicate): New function. Does style
duplication.
* src/sheet.c (sheet_new): Simple hook signals to test the code.
* src/item-bar.c (item_bar_class_init): Added signals:
size_changed and selection_changed.
(item_bar_event): Add support for resizing columns and rows.
1998-07-10 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c: New file. Implement the style manager for the
......
1998-07-11 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c (style_duplicate): New function. Does style
duplication.
* src/sheet.c (sheet_new): Simple hook signals to test the code.
* src/item-bar.c (item_bar_class_init): Added signals:
size_changed and selection_changed.
(item_bar_event): Add support for resizing columns and rows.
1998-07-10 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c: New file. Implement the style manager for the
......
1998-07-11 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c (style_duplicate): New function. Does style
duplication.
* src/sheet.c (sheet_new): Simple hook signals to test the code.
* src/item-bar.c (item_bar_class_init): Added signals:
size_changed and selection_changed.
(item_bar_event): Add support for resizing columns and rows.
1998-07-10 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c: New file. Implement the style manager for the
......
......@@ -5,12 +5,28 @@
#include "item-bar.h"
#include "item-debug.h"
/* Marshal forward declarations */
static void item_bar_size_marshal (GtkObject *,
GtkSignalFunc,
gpointer,
GtkArg *);
static void item_bar_selection_marshal (GtkObject *,
GtkSignalFunc,
gpointer,
GtkArg *);
/* The signal signatures */
typedef void (*ItemBarSignal1) (GtkObject *, gint arg1, gpointer data);
typedef void (*ItemBarSignal2) (GtkObject *, gint arg1, gint arg2, gpointer data);
/* The signals we emit */
enum {
ITEM_BAR_COLUMN_CLICKED,
ITEM_BAR_LAST_SIGNAL
SELECTION_CHANGED,
SIZE_CHANGED,
LAST_SIGNAL
};
static guint item_bar_signals [ITEM_BAR_LAST_SIGNAL] = { 0 };
static guint item_bar_signals [LAST_SIGNAL] = { 0 };
static GnomeCanvasItem *item_bar_parent_class;
......@@ -66,9 +82,6 @@ item_bar_unrealize (GnomeCanvasItem *item)
static void
item_bar_reconfigure (GnomeCanvasItem *item)
{
GnomeCanvas *canvas = item->canvas;
ItemBar *item_bar = ITEM_BAR (item);
item->x1 = 0;
item->y1 = 0;
item->x2 = INT_MAX;
......@@ -136,8 +149,7 @@ item_bar_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int w
{
ItemBar *item_bar = ITEM_BAR (item);
Sheet *sheet = item_bar->sheet;
ColRowInfo *ci;
ColRowInfo *ri;
ColRowInfo *cri;
int element, total, pixels, limit;
char *str;
......@@ -151,21 +163,29 @@ item_bar_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int w
total = 0;
do {
if (item_bar->orientation == GTK_ORIENTATION_VERTICAL){
ri = sheet_get_row_info (sheet, element);
pixels = ri->pixels;
if (total+pixels >= y){
cri = sheet_row_get_info (sheet, element);
if (item_bar->resize_pos == element)
pixels = item_bar->resize_width;
else
pixels = cri->pixels;
if (total + pixels >= y){
str = get_row_name (element);
bar_draw_cell (item_bar, drawable, ri, str,
bar_draw_cell (item_bar, drawable, cri, str,
-x, 1 + total - y,
item->canvas->width - x,
1 + total + pixels - y);
}
} else {
ci = sheet_get_col_info (sheet, element);
pixels = ci->pixels;
if (total+pixels >= x){
cri = sheet_col_get_info (sheet, element);
if (item_bar->resize_pos == element)
pixels = item_bar->resize_width;
else
pixels = cri->pixels;
if (total + pixels >= x){
str = get_col_name (element);
bar_draw_cell (item_bar, drawable, ci, str,
bar_draw_cell (item_bar, drawable, cri, str,
1 + total - x, -y,
1 + total + pixels - x,
item->canvas->height - y);
......@@ -191,8 +211,8 @@ item_bar_translate (GnomeCanvasItem *item, double dx, double dy)
printf ("item_bar_translate %g, %g\n", dx, dy);
}
static int
is_pointer_on_division (ItemBar *item_bar, int pos)
static ColRowInfo *
is_pointer_on_division (ItemBar *item_bar, int pos, int *the_total, int *the_element)
{
ColRowInfo *cri;
int i, total;
......@@ -201,15 +221,21 @@ is_pointer_on_division (ItemBar *item_bar, int pos)
for (i = item_bar->first_element; total < pos; i++){
if (item_bar->orientation == GTK_ORIENTATION_VERTICAL)
cri = sheet_get_row_info (item_bar->sheet, i);
cri = sheet_row_get_info (item_bar->sheet, i);
else
cri = sheet_get_col_info (item_bar->sheet, i);
cri = sheet_col_get_info (item_bar->sheet, i);
total += cri->pixels;
if ((total - 4 < pos) && (pos < total + 4))
return 1;
if ((total - 4 < pos) && (pos < total + 4)){
if (the_total)
*the_total = total;
if (the_element)
*the_element = i;
return cri;
}
}
return 0;
return NULL;
}
static void
......@@ -217,17 +243,55 @@ set_cursor (ItemBar *item_bar, int pos)
{
GtkWidget *canvas = GTK_WIDGET (GNOME_CANVAS_ITEM (item_bar)->canvas);
if (is_pointer_on_division (item_bar, pos))
if (is_pointer_on_division (item_bar, pos, NULL, NULL))
gdk_window_set_cursor(canvas->window, item_bar->change_cursor);
else
gdk_window_set_cursor(canvas->window, item_bar->normal_cursor);
}
static void
item_bar_start_resize (ItemBar *item_bar, int pos)
{
GnomeCanvas *canvas = GNOME_CANVAS (item_bar->sheet->sheet_view);
GnomeCanvasGroup *group = GNOME_CANVAS_GROUP (canvas->root);
GnomeCanvasItem *item;
double x1, x2, y1, y2;
if (item_bar->orientation == GTK_ORIENTATION_VERTICAL){
x1 = 0.0;
x2 = INT_MAX;
y1 = GNOME_CANVAS_ITEM (item_bar)->y1 + pos;
y2 = GNOME_CANVAS_ITEM (item_bar)->y1 + pos;
}
x1 = 0.0;
x2 = 1000.0;
y1 = 0.0;
y2 = 1000.0;
printf ("THIS SHOULD BE ADDING THE LINE!\n");
/* Add a guideline to the sheet canvas */
item = gnome_canvas_item_new (GNOME_CANVAS_ITEM (item_bar)->canvas,
group,
gnome_canvas_re_get_type (),
"GnomeCanvasRE::x1", x1,
"GnomeCanvasRE::y1", y1,
"GnomeCanvasRE::x2", x2,
"GnomeCanvasRE::y2", y2,
"GnomeCanvasRE::outline_color", "black",
"GnomeCanvasRE::width_pixels", 4,
NULL);
item_bar->resize_guide = GTK_OBJECT (item);
}
static gint
item_bar_event (GnomeCanvasItem *item, GdkEvent *event)
{
ColRowInfo *cri;
ItemBar *item_bar = ITEM_BAR (item);
int pos;
int pos, start, ele;
switch (event->type){
case GDK_ENTER_NOTIFY:
......@@ -243,6 +307,20 @@ item_bar_event (GnomeCanvasItem *item, GdkEvent *event)
pos = event->motion.y;
else
pos = event->motion.x;
/* Do column resizing or incremental marking */
if (ITEM_BAR_RESIZING (item_bar)){
int npos;
npos = pos - item_bar->resize_start_pos;
if (npos > 0){
item_bar->resize_width = npos;
gnome_canvas_request_redraw (
GNOME_CANVAS_ITEM(item_bar)->canvas,
0, 0, INT_MAX, INT_MAX);
}
} else {
}
set_cursor (item_bar, pos);
break;
......@@ -251,7 +329,31 @@ item_bar_event (GnomeCanvasItem *item, GdkEvent *event)
pos = event->button.y;
else
pos = event->button.x;
cri = is_pointer_on_division (item_bar, pos, &start, &ele);
if (cri){
/* Record the important bits */
item_bar->resize_pos = ele;
item_bar->resize_start_pos = start - cri->pixels;
item_bar->resize_width = cri->pixels;
item_bar_start_resize (item_bar, pos);
} else {
gtk_signal_emit (GTK_OBJECT (item),
item_bar_signals [SELECTION_CHANGED],
item_bar->resize_pos);
}
break;
case GDK_BUTTON_RELEASE:
if (ITEM_BAR_RESIZING (item_bar)){
gtk_signal_emit (GTK_OBJECT (item),
item_bar_signals [SIZE_CHANGED],
item_bar->resize_pos,
item_bar->resize_width);
item_bar->resize_pos = -1;
gtk_object_destroy (item_bar->resize_guide);
}
default:
return FALSE;
}
......@@ -273,6 +375,7 @@ item_bar_init (ItemBar *item_bar)
item_bar->first_element = 0;
item_bar->orientation = GTK_ORIENTATION_VERTICAL;
item_bar->resize_pos = -1;
}
static void
......@@ -324,7 +427,32 @@ item_bar_class_init (ItemBarClass *item_bar_class)
GTK_ARG_WRITABLE, ARG_ORIENTATION);
gtk_object_add_arg_type ("ItemBar::First", GTK_TYPE_INT,
GTK_ARG_WRITABLE, ARG_FIRST_ELEMENT);
item_bar_signals [SELECTION_CHANGED] =
gtk_signal_new ("selection_changed",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ItemBarClass, selection_changed),
item_bar_selection_marshal,
GTK_TYPE_NONE,
1,
GTK_TYPE_INT);
item_bar_signals [SIZE_CHANGED] =
gtk_signal_new ("size_changed",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ItemBarClass, size_changed),
item_bar_size_marshal,
GTK_TYPE_NONE,
2,
GTK_TYPE_INT,
GTK_TYPE_INT);
/* Register our signals */
gtk_object_class_add_signals (object_class, item_bar_signals,
LAST_SIGNAL);
/* Method overrides */
object_class->set_arg = item_bar_set_arg;
/* GnomeCanvasItem method overrides */
......@@ -359,3 +487,35 @@ item_bar_get_type (void)
return item_bar_type;
}
/*
* Marshaling routines for our signals
*/
static void
item_bar_selection_marshal (GtkObject *object,
GtkSignalFunc func,
gpointer func_data,
GtkArg *args)
{
ItemBarSignal1 rfunc;
rfunc = (ItemBarSignal1) func;
(*rfunc) (object, GTK_VALUE_INT (args [0]), func_data);
}
static void
item_bar_size_marshal (GtkObject *object,
GtkSignalFunc func,
gpointer func_data,
GtkArg *args)
{
ItemBarSignal2 rfunc;
rfunc = (ItemBarSignal2) func;
(*rfunc) (object,
GTK_VALUE_INT (args [0]),
GTK_VALUE_INT (args [1]),
func_data);
}
......@@ -5,6 +5,8 @@
#define ITEM_BAR_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), item_bar_get_type ()))
#define IS_ITEM_BAR(o) (GTK_CHECK_TYPE((o), item_bar_get_type ()))
#define ITEM_BAR_RESIZING(x) (ITEM_BAR(x)->resize_pos != -1)
typedef struct {
GnomeCanvasItem canvas_item;
Sheet *sheet;
......@@ -13,12 +15,21 @@ typedef struct {
GdkGC *gc; /* Draw gc */
GdkCursor *normal_cursor;
GdkCursor *change_cursor;
int resize_pos;
int resize_width;
int resize_start_pos;
GtkObject *resize_guide;
} ItemBar;
GtkType item_bar_get_type (void);
typedef struct {
GnomeCanvasItemClass parent_class;
/* Signals emited */
void (* selection_changed) (ItemBar *, int column);
void (* size_changed) (ItemBar *, int column, int new_width);
} ItemBarClass;
#endif
......@@ -121,7 +121,7 @@ find_col (ItemGrid *item_grid, int x, int *col_origin)
int pixel = item_grid->left_offset;
do {
ColRowInfo *ci = sheet_get_col_info (item_grid->sheet, col);
ColRowInfo *ci = sheet_col_get_info (item_grid->sheet, col);
if (x >= pixel && x <= pixel + ci->pixels){
if (col_origin)
......@@ -143,7 +143,7 @@ find_row (ItemGrid *item_grid, int y, int *row_origin)
int pixel = item_grid->top_offset;
do {
ColRowInfo *ri = sheet_get_row_info (item_grid->sheet, row);
ColRowInfo *ri = sheet_row_get_info (item_grid->sheet, row);
if (y >= pixel && y <= pixel + ri->pixels){
if (row_origin)
......@@ -198,9 +198,9 @@ item_grid_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int
for (x_paint = -diff_x; x_paint < end_x; col++){
ColRowInfo *ci;
ci = sheet_get_col_info (sheet, col);
ci = sheet_col_get_info (sheet, col);
g_assert (ci->pixels != 0);
gdk_draw_line (drawable, grid_gc, x_paint, 0, x_paint, height);
x_paint += ci->pixels;
......@@ -210,7 +210,7 @@ item_grid_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int
for (y_paint = -diff_y; y_paint < end_y; row++){
ColRowInfo *ri;
ri = sheet_get_row_info (sheet, row);
ri = sheet_row_get_info (sheet, row);
gdk_draw_line (drawable, grid_gc, 0, y_paint, width, y_paint);
y_paint += ri->pixels;
}
......@@ -218,13 +218,13 @@ item_grid_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int
for (x_paint = -diff_x; x_paint < end_x; col++){
ColRowInfo *ci;
ci = sheet_get_col_info (sheet, col);
ci = sheet_col_get_info (sheet, col);
row = paint_row;
for (y_paint = -diff_y; y_paint < end_y; row++){
ColRowInfo *ri;
ri = sheet_get_row_info (sheet, row);
ri = sheet_row_get_info (sheet, row);
#if 0
item_debug_cross (drawable, item_grid->grid_gc,
x_paint, y_paint,
......
......@@ -2,49 +2,56 @@
#include "gnumeric.h"
#include "gnumeric-sheet.h"
static void
sheet_redraw_all (Sheet *sheet)
{
gnome_canvas_request_redraw (
GNOME_CANVAS (sheet->sheet_view),
0, 0, INT_MAX, INT_MAX);
}
static void
sheet_init_default_styles (Sheet *sheet)
{
/* The default column style */
sheet->default_col_style.pos = -1;
sheet->default_col_style.style = style_new ();
sheet->default_col_style.units = 40;
sheet->default_col_style.pixels = 0;
sheet->default_col_style.margin_a = 0;
sheet->default_col_style.margin_b = 0;
sheet->default_col_style.selected = 0;
/* The default row style */
sheet->default_row_style.pos = -1;
sheet->default_row_style.style = style_new ();
sheet->default_row_style.units = 20;
sheet->default_row_style.pixels = 0;
sheet->default_row_style.margin_a = 0;
sheet->default_row_style.margin_b = 0;
sheet->default_row_style.selected = 0;
}
/* Initialize some of the columns and rows, to test the display engine */
static void
sheet_init_dummy_stuff (Sheet *sheet)
{
ColRowInfo *cp, *rp;
int x, y;
ColRowInfo c, *cp, *rp;
c.pos = 0;
c.style = NULL;
c.units = 40;
c.pixels = 0;
c.margin_a = 0;
c.margin_b = 0;
c.selected = 0;
sheet->default_col_style = c;
/* Initialize some of the columns */
for (x = 0; x < 40; x += 2){
cp = g_new0 (ColRowInfo, 1);
*cp = c;
cp = sheet_row_new (sheet);
cp->pos = x;
cp->units = (x+1) * 30;
sheet->cols_info = g_list_append (sheet->cols_info, cp);
sheet_col_add (sheet, cp);
}
/* Rows, we keep them consistent for now */
sheet->default_row_style.pos = 0;
sheet->default_row_style.style = NULL;
sheet->default_row_style.units = 20;
sheet->default_row_style.pixels = 0;
sheet->default_row_style.margin_a = 0;
sheet->default_row_style.margin_b = 0;
sheet->default_row_style.selected = 0;
for (y = 0; y < 6; y += 2){
rp = g_new0 (ColRowInfo, 1);
*rp = sheet->default_row_style;
rp = sheet_row_new (sheet);
rp->pos = y;
rp->units = (20 * (y + 1));
rp->selected = 1;
sheet->rows_info = g_list_append (sheet->rows_info, rp);
sheet_row_add (sheet, rp);
}
}
......@@ -75,11 +82,36 @@ new_canvas_bar (Sheet *sheet, GtkOrientation o, GnomeCanvasItem **itemp)
"ItemBar::Orientation", o,
"ItemBar::First", 0,
NULL);
*itemp = GNOME_CANVAS_ITEM (item);
gtk_widget_show (canvas);
return canvas;
}
static void
sheet_col_selection_changed (ItemBar *item_bar, int column, Sheet *sheet)
{
printf ("Sheet signal: Column %d selection changed\n", column);
}
static void
sheet_col_size_changed (ItemBar *item_bar, int col, int width, Sheet *sheet)
{
sheet_col_set_width (sheet, col, width);
}
static void
sheet_row_selection_changed (ItemBar *item_bar, int row, Sheet *sheet)
{
printf ("Sheet signal: Row %d selection changed\n", row);
}
static void
sheet_row_size_changed (ItemBar *item_bar, int row, int height, Sheet *sheet)
{
sheet_row_set_height (sheet, row, height);
}
Sheet *
sheet_new (Workbook *wb, char *name)
{
......@@ -90,7 +122,9 @@ sheet_new (Workbook *wb, char *name)
sheet->name = g_strdup (name);
sheet->last_zoom_factor_used = -1.0;
sheet->toplevel = gtk_table_new (0, 0, 0);
sheet_init_default_styles (sheet);
/* Dummy initialization */
sheet_init_dummy_stuff (sheet);
......@@ -107,12 +141,23 @@ sheet_new (Workbook *wb, char *name)
gtk_table_attach (GTK_TABLE (sheet->toplevel), sheet->col_canvas,
1, 2, 0, 1,
GTK_FILL | GTK_EXPAND, 0, 0, 0);
gtk_signal_connect (GTK_OBJECT (sheet->col_item), "selection_changed",
GTK_SIGNAL_FUNC (sheet_col_selection_changed),
sheet);
gtk_signal_connect (GTK_OBJECT (sheet->col_item), "size_changed",
GTK_SIGNAL_FUNC (sheet_col_size_changed),
sheet);
/* Row canvas */
sheet->row_canvas = new_canvas_bar (sheet, GTK_ORIENTATION_VERTICAL, &sheet->row_item);
gtk_table_attach (GTK_TABLE (sheet->toplevel), sheet->row_canvas,
0, 1, 1, 2,
0, GTK_FILL | GTK_EXPAND, 0, 0);
gtk_signal_connect (GTK_OBJECT (sheet->row_item), "selection_changed",
GTK_SIGNAL_FUNC (sheet_row_selection_changed),
sheet);
gtk_signal_connect (GTK_OBJECT (sheet->row_item), "size_changed",
GTK_SIGNAL_FUNC (sheet_row_size_changed),
sheet);
sheet_set_zoom_factor (sheet, 1.0);
return sheet;
......@@ -187,7 +232,44 @@ sheet_set_zoom_factor (Sheet *sheet, double factor)
}
ColRowInfo *
sheet_get_col_info (Sheet *sheet, int col)
sheet_duplicate_colrow (ColRowInfo *original)
{
ColRowInfo *info = g_new (ColRowInfo, 1);
*info = *original;
info->style = style_duplicate (original->style);
return info;
}
ColRowInfo *
sheet_row_new (Sheet *sheet)
{
return sheet_duplicate_colrow (&sheet->default_row_style);
}
ColRowInfo *
sheet_col_new (Sheet *sheet)
{
return sheet_duplicate_colrow (&sheet->default_col_style);
}
void
sheet_col_add (Sheet *sheet, ColRowInfo *cp)
{
sheet->cols_info = g_list_append (sheet->cols_info, cp);
}
void
sheet_row_add (Sheet *sheet, ColRowInfo *rp)
{
sheet->rows_info = g_list_append (sheet->rows_info, rp);
}
ColRowInfo *
sheet_col_get_info (Sheet *sheet, int col)
{
GList *l = sheet->cols_info;
......@@ -202,7 +284,7 @@ sheet_get_col_info (Sheet *sheet, int col)