Commit ca8fa0ac authored by Arturo Espinosa's avatar Arturo Espinosa

Got cursors working.



Got cursors working.

Use the cursors properly on the spreadhseet (gives good feedback
on what is going to happen).

More work on autofill.

miguel.
parent be23a266
1998-09-14 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cursors.c: Define the Gnumeric cursors here.
(create_bitmap_and_mask_from_xpm): New simplistic function to
create cursors from an XPM inlined file. It assumes 3 colors are
used: none (transparency), black and white.
(cursors_init): Create various cursors for use in Gnumeric.
* src/item-grid.c (item_grid_event): Set the fat cross cursor on
enter-notify
* src/item-cursor.c (item_cursor_selection_event): Handle
GDK_ENTER_NOTIFY and GDK_MOTION_NOTIFY to set the X window pointer
shape properly according to the position of the mouse pointer.
1998-09-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_realize): Fix: initilaize
......
1998-09-14 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cursors.c: Define the Gnumeric cursors here.
(create_bitmap_and_mask_from_xpm): New simplistic function to
create cursors from an XPM inlined file. It assumes 3 colors are
used: none (transparency), black and white.
(cursors_init): Create various cursors for use in Gnumeric.
* src/item-grid.c (item_grid_event): Set the fat cross cursor on
enter-notify
* src/item-cursor.c (item_cursor_selection_event): Handle
GDK_ENTER_NOTIFY and GDK_MOTION_NOTIFY to set the X window pointer
shape properly according to the position of the mouse pointer.
1998-09-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_realize): Fix: initilaize
......
1998-09-14 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cursors.c: Define the Gnumeric cursors here.
(create_bitmap_and_mask_from_xpm): New simplistic function to
create cursors from an XPM inlined file. It assumes 3 colors are
used: none (transparency), black and white.
(cursors_init): Create various cursors for use in Gnumeric.
* src/item-grid.c (item_grid_event): Set the fat cross cursor on
enter-notify
* src/item-cursor.c (item_cursor_selection_event): Handle
GDK_ENTER_NOTIFY and GDK_MOTION_NOTIFY to set the X window pointer
shape properly according to the position of the mouse pointer.
1998-09-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_realize): Fix: initilaize
......
1998-09-14 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cursors.c: Define the Gnumeric cursors here.
(create_bitmap_and_mask_from_xpm): New simplistic function to
create cursors from an XPM inlined file. It assumes 3 colors are
used: none (transparency), black and white.
(cursors_init): Create various cursors for use in Gnumeric.
* src/item-grid.c (item_grid_event): Set the fat cross cursor on
enter-notify
* src/item-cursor.c (item_cursor_selection_event): Handle
GDK_ENTER_NOTIFY and GDK_MOTION_NOTIFY to set the X window pointer
shape properly according to the position of the mouse pointer.
1998-09-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_realize): Fix: initilaize
......
......@@ -2,36 +2,87 @@
#include <gnome.h>
#include "color.h"
#include "cursors.h"
#include "pixmaps.h"
#include "pixmaps/cursor_cross.xpm"
#define GNUMERIC_CURSORS 10
#define GDK_INTERNAL_CURSOR -1
GdkCursor *gnumeric_cursors [GNUMERIC_CURSORS] = { NULL, };
GnumericCursorDef gnumeric_cursors [] = {
{ NULL, 17, 17, cursor_cross_xpm },
{ NULL, GDK_INTERNAL_CURSOR, GDK_CROSSHAIR, NULL },
{ NULL, GDK_INTERNAL_CURSOR, GDK_ARROW, NULL },
{ NULL, 0, 0, NULL }
};
void
cursors_init (void)
static void
create_bitmap_and_mask_from_xpm (GdkBitmap **bitmap, GdkBitmap **mask, gchar **xpm)
{
GdkImlibImage *image;
GdkPixmap *pixmap;
GdkBitmap *bitmap;
int height, width, colors;
char pixmap_buffer [(32 * 32)/8];
char mask_buffer [(32 * 32)/8];
int x, y, pix;
int transparent_color, black_color;
image = gdk_imlib_create_image_from_xpm_data (arrow_xpm);
if (!image){
g_warning ("Could not create image\n");
return;
sscanf (xpm [0], "%d %d %d %d", &height, &width, &colors, &pix);
g_assert (height == 32);
g_assert (width == 32);
g_assert (colors == 3);
transparent_color = ' ';
black_color = '.';
for (y = 0; y < 32; y++){
for (x = 0; x < 32;){
char value = 0, maskv = 0;
for (pix = 0; pix < 8; pix++, x++){
if (xpm [4+y][x] != transparent_color){
maskv |= 1 << pix;
if (xpm [4+y][x] != black_color){
value |= 1 << pix;
}
}
}
pixmap_buffer [(y * 4 + x/8)-1] = value;
mask_buffer [(y * 4 + x/8)-1] = maskv;
}
}
*bitmap = gdk_bitmap_create_from_data (NULL, pixmap_buffer, 32, 32);
*mask = gdk_bitmap_create_from_data (NULL, mask_buffer, 32, 32);
}
gdk_imlib_render (image, image->rgb_width, image->rgb_height);
pixmap = gdk_imlib_move_image (image);
bitmap = gdk_imlib_move_mask (image);
void
cursors_init (void)
{
int i;
for (i = 0; gnumeric_cursors [i].hot_x; i++){
GdkBitmap *bitmap, *mask;
gnumeric_cursors [0] = gdk_cursor_new_from_pixmap (bitmap, bitmap, &gs_white, &gs_black, 1, 1);
gdk_imlib_destroy_image (image);
if (gnumeric_cursors [i].hot_x < 0)
gnumeric_cursors [i].cursor = gdk_cursor_new (
gnumeric_cursors [i].hot_y);
else {
create_bitmap_and_mask_from_xpm (
&bitmap, &mask, gnumeric_cursors [i].xpm);
gnumeric_cursors [i].cursor =
gdk_cursor_new_from_pixmap (
bitmap, mask,
&gs_white, &gs_black,
gnumeric_cursors [i].hot_x,
gnumeric_cursors [i].hot_y);
}
}
}
void
cursors_shutdown (void)
{
gdk_cursor_destroy (gnumeric_cursors [0]);
int i;
for (i = 0; gnumeric_cursors [i].hot_x; i++)
gdk_cursor_destroy (gnumeric_cursors [0].cursor);
}
#ifndef CURSORS_H
#define CURSORS_H
extern GdkCursor *gnumeric_cursors [];
typedef struct {
GdkCursor *cursor;
int hot_x, hot_y;
char **xpm;
} GnumericCursorDef;
#define GNUMERIC_CURSOR_FAT_CROSS 0
#define GNUMERIC_CURSOR_THIN_CROSS 1
#define GNUMERIC_CURSOR_ARROW 2
extern GnumericCursorDef gnumeric_cursors [];
void cursors_init (void);
void cursors_shutdown (void);
......
......@@ -24,11 +24,12 @@ typedef enum {
} Operation;
typedef enum {
VALUE_STRING,
VALUE_UNKNOWN = -1,
VALUE_STRING = 0,
VALUE_INTEGER,
VALUE_FLOAT,
VALUE_CELLRANGE,
VALUE_ARRAY
VALUE_ARRAY,
} ValueType;
/*
......
......@@ -815,7 +815,7 @@ gnumeric_sheet_realize (GtkWidget *widget)
gsheet->patterns [i] = gdk_bitmap_create_from_data (
window, gnumeric_sheet_patterns [i].pattern, 8, 8);
/* gdk_window_set_cursor (window, gnumeric_cursors [0]); */
gdk_window_set_cursor (window, gnumeric_cursors [GNUMERIC_CURSOR_FAT_CROSS].cursor);
}
void
......
......@@ -815,7 +815,7 @@ gnumeric_sheet_realize (GtkWidget *widget)
gsheet->patterns [i] = gdk_bitmap_create_from_data (
window, gnumeric_sheet_patterns [i].pattern, 8, 8);
/* gdk_window_set_cursor (window, gnumeric_cursors [0]); */
gdk_window_set_cursor (window, gnumeric_cursors [GNUMERIC_CURSOR_FAT_CROSS].cursor);
}
void
......
......@@ -16,11 +16,14 @@
#include "gnumeric-sheet.h"
#include "gnumeric-util.h"
#include "color.h"
#include "cursors.h"
static GnomeCanvasItem *item_cursor_parent_class;
static void item_cursor_request_redraw (ItemCursor *item_cursor);
#define IS_LITTLE_SQUARE(item,x,y) ((x) > (item)->x2 - 6) && ((y) > (item)->y2 - 6)
/* The argument we take */
enum {
ARG_0,
......@@ -337,11 +340,11 @@ item_cursor_point (GnomeCanvasItem *item, double x, double y, int cx, int cy,
{
*actual_item = NULL;
if (cx < item->x1)
if (cx < item->x1-1)
return INT_MAX;
if (cx > item->x2)
return INT_MAX;
if (cy < item->y1)
if (cy < item->y1-1)
return INT_MAX;
if (cy > item->y2)
return INT_MAX;
......@@ -378,6 +381,19 @@ item_cursor_setup_auto_fill (ItemCursor *item_cursor, ItemCursor *parent, int x,
item_cursor->base_row = parent->start_row;
}
static void
item_cursor_set_cursor (GdkWindow *window, GnomeCanvasItem *item, int x, int y)
{
int cursor;
if (IS_LITTLE_SQUARE (item, x, y))
cursor = GNUMERIC_CURSOR_THIN_CROSS;
else
cursor = GNUMERIC_CURSOR_ARROW;
gdk_window_set_cursor (window, gnumeric_cursors [cursor].cursor);
}
static gint
item_cursor_selection_event (GnomeCanvasItem *item, GdkEvent *event)
{
......@@ -387,6 +403,20 @@ item_cursor_selection_event (GnomeCanvasItem *item, GdkEvent *event)
int x, y;
switch (event->type){
case GDK_ENTER_NOTIFY:
gnome_canvas_w2c (
canvas, event->crossing.x, event->crossing.y, &x, &y);
item_cursor_set_cursor (GTK_WIDGET (canvas)->window, item, x, y);
return TRUE;
case GDK_MOTION_NOTIFY:
gnome_canvas_w2c (
canvas, event->motion.x, event->motion.y, &x, &y);
item_cursor_set_cursor (GTK_WIDGET (canvas)->window, item, x, y);
return TRUE;
case GDK_BUTTON_PRESS: {
GnomeCanvasGroup *group;
int style;
......@@ -399,7 +429,7 @@ item_cursor_selection_event (GnomeCanvasItem *item, GdkEvent *event)
/* determine which part of the cursor was clicked:
* the border or the handlebox
*/
if ((x > item->x2 - 6) && (y > item->y2 - 6))
if (IS_LITTLE_SQUARE (item, x, y))
style = ITEM_CURSOR_AUTOFILL;
else
style = ITEM_CURSOR_DRAG;
......@@ -618,10 +648,12 @@ item_cursor_autofill_event (GnomeCanvasItem *item, GdkEvent *event)
Sheet *sheet = item_cursor->sheet;
gnome_canvas_item_ungrab (item, event->button.time);
sheet_autofill (sheet,
item_cursor->base_col, item_cursor->base_row,
item_cursor->base_cols, item_cursor->base_rows,
item_cursor->end_col, item_cursor->end_row);
if (!((item_cursor->end_col == item_cursor->base_col + item_cursor->base_cols) &&
(item_cursor->end_row == item_cursor->base_row + item_cursor->base_rows)))
sheet_autofill (sheet,
item_cursor->base_col, item_cursor->base_row,
item_cursor->base_cols+1, item_cursor->base_rows+1,
item_cursor->end_col, item_cursor->end_row);
gtk_object_destroy (GTK_OBJECT (item));
......
......@@ -15,6 +15,7 @@
#include "item-debug.h"
#include "color.h"
#include "dialogs.h"
#include "cursors.h"
static GnomeCanvasItem *item_grid_parent_class;
......@@ -559,6 +560,12 @@ item_grid_event (GnomeCanvasItem *item, GdkEvent *event)
int scroll_x, scroll_y;
switch (event->type){
case GDK_ENTER_NOTIFY:
gdk_window_set_cursor (
GTK_WIDGET (canvas)->window,
gnumeric_cursors [GNUMERIC_CURSOR_FAT_CROSS].cursor);
return TRUE;
case GDK_BUTTON_RELEASE:
if (event->button.button == 1){
item_grid->selecting = 0;
......
......@@ -5,6 +5,7 @@
#include "plugin.h"
#include "format.h"
#include "color.h"
#include "cursors.h"
/* If set, the file to load at startup time */
static char *startup_file;
......
......@@ -5,6 +5,7 @@
#include "plugin.h"
#include "format.h"
#include "color.h"
#include "cursors.h"
/* If set, the file to load at startup time */
static char *startup_file;
......
/* XPM */
static char * cursor_cross_xpm[] = {
"32 32 3 1",
" c None",
". c #000000",
"+ c #FFFFFF",
" ",
" ",
" ",
" ",
" ",
" ......... ",
" .+++++++.. ",
" .+++++++.. ",
" .+++++++.. ",
" .+++++++.. ",
" .+++++++.. ",
" .......+++++++........ ",
" .+++++++++++++++++++.. ",
" .+++++++++++++++++++.. ",
" .+++++++++++++++++++.. ",
" .+++++++++++++++++++.. ",
" .+++++++++++++++++++.. ",
" .+++++++++++++++++++.. ",
" .+++++++++++++++++++.. ",
" .......+++++++........ ",
" ......+++++++........ ",
" .+++++++.. ",
" .+++++++.. ",
" .+++++++.. ",
" .+++++++.. ",
" .......... ",
" ......... ",
" ",
" ",
" ",
" ",
" "};
......@@ -10,39 +10,100 @@
#include "gnumeric.h"
#include "sheet-autofill.h"
static GList *autofill_functions;
void
sheet_autofill (Sheet *sheet, int base_col, int base_row, int w, int h, int end_col, int end_row)
static void
sheet_autofill_dir (Sheet *sheet,
int base_col, int base_row,
int region_count,
int start_pos, int end_pos,
int col_inc, int row_inc)
{
GList *l;
ValueType last_value_type = VALUE_UNKNOWN;
int x = base_col;
int y = base_row;
int i, pos, fill_start;
int region_types = 0;
Value **values;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
values = g_new (Value *, region_count);
printf ("region_count=%d\n", region_count);
fill_start = start_pos;
/*
* Count the number of different region types we have
*
* We need this to deal with regions that have numbers and strings
* and apply an autofill function depending on it.
*/
for (i = 0; i < region_count; i++){
Cell *cell;
fill_start++;
cell = sheet_cell_get (sheet, x, y);
if (cell)
values [i] = cell->value;
else
values [i] = NULL;
x += col_inc;
y += row_inc;
for (l = autofill_functions; l; l = l->next){
AutofillFunction *aff = l->data;
if (values [i]){
if (last_value_type != VALUE_UNKNOWN)
if (last_value_type != values [i]->type)
region_types++;
last_value_type = values [i]->type;
/* Integers and floats are all numbers, count them together */
if (last_value_type == VALUE_FLOAT)
last_value_type = VALUE_INTEGER;
}
}
if ((*aff)(sheet, base_col, base_row, w, h, end_col, end_row))
return;
printf ("we have %d different region types\n", region_types);
for (pos = fill_start; pos < end_pos; pos++){
Cell *cell;
cell = sheet_cell_new (sheet, x, y);
cell_set_text (cell, "Autofilled");
x += col_inc;
y += row_inc;
}
workbook_recalc (sheet->workbook);
}
void
register_autofill_function (AutofillFunction fn)
sheet_autofill (Sheet *sheet, int base_col, int base_row, int w, int h, int end_col, int end_row)
{
g_return_if_fail (fn != NULL);
int n; /* Number of different auto fill ranges */
int end_pos; /* Where to stop */
int items; /* Items provided per auto-fill range */
int item_next_col; /* increment col */
int item_next_row; /* increment row */
int range; /* range iterator */
autofill_functions = g_list_prepend (autofill_functions, fn);
}
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
static int
autofill_integers (Sheet *sheet, int base_col, int base_row, int w, int h, int end_col, int end_row)
{
return TRUE;
printf ("base_col=%d, base_row=%d\n", base_col, base_row);
printf ("width=%d height=%d\n", w, h);
printf ("end_col=%d end_row=%d\n", end_col, end_row);
if (end_col != base_col + w - 1){
for (range = 0; range < h; range++)
sheet_autofill_dir (sheet, base_col, base_row+range, w, base_col, end_col+1, 1, 0);
} else {
for (range = 0; range < w; range++)
sheet_autofill_dir (sheet, base_col+range, base_row, h, base_row, end_row+1, 0, 1);
}
}
void
autofill_init (void)
{
/* register_autofill_function (autofill_integers); */
}
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