Commit c73132df authored by Arturo Espinosa's avatar Arturo Espinosa

Alignment dialog box (does not work though, wonder why).



Alignment dialog box (does not work though, wonder why).

Various fixes to the cursor handling;

Stippled cursors for autofill and drag;

check in before going home.

Miguel.
parent 3c5f135d
1998-08-18 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_set_alignment): Provide a way to change the
cell alignment.
* src/dialog-cell-format.c (create_align_page): Implement the cell
formats/alignment page.
* src/item-cursor.c (item_cursor_realize): Add stypple support for
drag and autofill cursors.
* src/gnumeric-sheet.c (gnumeric_sheet_compute_visible_ranges):
Make the selected column and row be always fully visible (ie, use
the ->last_full_[col|row] instead of last_visible_[col|row].
......
1998-08-18 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_set_alignment): Provide a way to change the
cell alignment.
* src/dialog-cell-format.c (create_align_page): Implement the cell
formats/alignment page.
* src/item-cursor.c (item_cursor_realize): Add stypple support for
drag and autofill cursors.
* src/gnumeric-sheet.c (gnumeric_sheet_compute_visible_ranges):
Make the selected column and row be always fully visible (ie, use
the ->last_full_[col|row] instead of last_visible_[col|row].
......
1998-08-18 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_set_alignment): Provide a way to change the
cell alignment.
* src/dialog-cell-format.c (create_align_page): Implement the cell
formats/alignment page.
* src/item-cursor.c (item_cursor_realize): Add stypple support for
drag and autofill cursors.
* src/gnumeric-sheet.c (gnumeric_sheet_compute_visible_ranges):
Make the selected column and row be always fully visible (ie, use
the ->last_full_[col|row] instead of last_visible_[col|row].
......
1998-08-18 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (cell_set_alignment): Provide a way to change the
cell alignment.
* src/dialog-cell-format.c (create_align_page): Implement the cell
formats/alignment page.
* src/item-cursor.c (item_cursor_realize): Add stypple support for
drag and autofill cursors.
* src/gnumeric-sheet.c (gnumeric_sheet_compute_visible_ranges):
Make the selected column and row be always fully visible (ie, use
the ->last_full_[col|row] instead of last_visible_[col|row].
......
......@@ -197,6 +197,8 @@ cell_destroy (Cell *cell)
void
cell_queue_redraw (Cell *cell)
{
g_return_if_fail (cell != NULL);
sheet_redraw_cell_region (cell->sheet,
cell->col->pos, cell->row->pos,
cell->col->pos, cell->row->pos);
......@@ -205,6 +207,9 @@ cell_queue_redraw (Cell *cell)
void
cell_set_format (Cell *cell, char *format)
{
g_return_if_fail (cell != NULL);
g_return_if_fail (format != NULL);
if (strcmp (format, cell->style->format->format) == 0)
return;
......@@ -216,3 +221,21 @@ cell_set_format (Cell *cell, char *format)
cell_render_value (cell);
cell_queue_redraw (cell);
}
void
cell_set_alignment (Cell *cell, int halign, int valign, int orient)
{
g_return_if_fail (cell != NULL);
g_return_if_fail (cell->style != NULL);
if ((cell->style->halign == halign) &&
(cell->style->halign == valign) &&
(cell->style->orientation == orient))
return;
cell->style->halign = halign;
cell->style->valign = valign;
cell->style->orientation = orient;
cell_queue_redraw (cell);
}
......@@ -73,6 +73,7 @@ char *value_format (Value *value, StyleFormat *format, char *
void cell_set_text (Cell *cell, char *text);
void cell_set_formula (Cell *cell, char *text);
void cell_set_format (Cell *cell, char *format);
void cell_set_alignment (Cell *cell, int halign, int valign, int orientation);
void cell_set_rendered_text (Cell *cell, char *rendered_text);
void cell_render_value (Cell *cell);
void cell_calc_dimensions (Cell *cell);
......@@ -80,6 +81,5 @@ Cell *cell_copy (Cell *cell);
void cell_destroy (Cell *cell);
void cell_formula_changed (Cell *cell);
void cell_queue_redraw (Cell *cell);
#endif /* GNUMERIC_CELL_H */
......@@ -22,6 +22,10 @@ static GtkWidget *number_input;
static GtkWidget *number_cat_list;
static GtkWidget *number_format_list;
/* There point to the radio groups in the format/alignment page */
static GSList *hradio_list;
static GSList *vradio_list;
/* Points to the first cell in the selection */
static Cell *first_cell;
......@@ -139,6 +143,31 @@ format_list_fill (int n)
gtk_clist_thaw (cl);
}
/*
* This routine is just used at startup to find the current
* format that applies to this cell
*/
static int
format_find (char *format)
{
int i, row;
char **p;
for (i = 0; cell_formats [i].name; i++){
p = cell_formats [i].formats;
for (row = 0; *p; p++, row++){
if (strcmp (format, *p) == 0){
format_list_fill (i);
gtk_clist_select_row (GTK_CLIST (number_format_list), row, 0);
return 1;
}
}
}
return 0;
}
/*
* Invoked when the user has selected a new format category
*/
......@@ -262,7 +291,7 @@ create_number_format_page (GtkWidget *prop_win, CellList *cells)
INPUT_LINE = 3,
};
t = GTK_TABLE (gtk_table_new (0, 0, 0));
t = (GtkTable *) gtk_table_new (0, 0, 0);
/* try to select the current format the user is using */
format = cells_get_format (cells);
......@@ -297,7 +326,7 @@ create_number_format_page (GtkWidget *prop_win, CellList *cells)
number_input = gtk_entry_new ();
gtk_signal_connect (GTK_OBJECT (number_input), "changed",
GTK_SIGNAL_FUNC (format_code_changed), prop_win);
gtk_table_attach (tt, number_input, 1, 2, 0, 1, GTK_FILL | GTK_EXPAND, 0, 0, 2);
/* 2.2 Sample */
......@@ -322,8 +351,12 @@ create_number_format_page (GtkWidget *prop_win, CellList *cells)
/* 3.2: Invoke the current style for the cell if possible */
/* FIXME: Currently we just select the first format */
gtk_clist_select_row (GTK_CLIST (number_format_list), 0, 0);
if (format){
if (!format_find (format->format))
gtk_entry_set_text (GTK_ENTRY (number_input), format->format);
} else
gtk_clist_select_row (GTK_CLIST (number_format_list), 0, 0);
/* 4. finish */
......@@ -359,12 +392,137 @@ apply_number_formats (Sheet *sheet, CellList *list)
}
}
typedef struct {
char *name;
int flag;
} align_def_t;
static align_def_t horizontal_aligns [] = {
{ N_("General"), HALIGN_GENERAL },
{ N_("Left"), HALIGN_LEFT },
{ N_("Center"), HALIGN_CENTER },
{ N_("Right"), HALIGN_RIGHT },
{ N_("Fill"), HALIGN_FILL },
{ N_("Justify"), HALIGN_JUSTIFY },
{ NULL, 0 }
};
static align_def_t vertical_aligns [] = {
{ N_("Top"), VALIGN_TOP },
{ N_("Center"), VALIGN_CENTER },
{ N_("Bottom"), VALIGN_BOTTOM },
{ N_("Justify"), VALIGN_JUSTIFY },
{ NULL, 0 }
};
static GtkWidget *
make_radio_selection (GtkWidget *prop_win, char *title, align_def_t *array, GSList **dest_list)
{
GtkWidget *frame, *vbox;
GSList *group;
frame = gtk_frame_new (title);
vbox = gtk_vbox_new (0, 0);
gtk_container_add (GTK_CONTAINER (frame), vbox);
for (group = NULL;array->name; array++){
GtkWidget *item;
item = gtk_radio_button_new_with_label (group, _(array->name));
group = gtk_radio_button_group (GTK_RADIO_BUTTON (item));
gtk_box_pack_start_defaults (GTK_BOX (vbox), item);
}
*dest_list = group;
return frame;
}
static void
prop_modified (GtkWidget *widge, GnomePropertyBox *box)
{
gnome_property_box_changed (box);
}
static GtkWidget *
create_align_page (GtkWidget *prop_win, CellList *cells)
{
GtkTable *t;
GtkWidget *w;
int ha, va, ok = 0;
GList *l;
GSList *sl;
t = (GtkTable *) gtk_table_new (0, 0, 0);
/* Horizontal alignment */
w = make_radio_selection (prop_win, _("Horizontal"), horizontal_aligns, &hradio_list);
gtk_table_attach (t, w, 0, 1, 0, 2, 0, GTK_FILL, 4, 0);
/* Vertical alignment */
w = make_radio_selection (prop_win, _("Vertical"), vertical_aligns, &vradio_list);
gtk_table_attach (t, w, 1, 2, 0, 1, 0, GTK_FILL, 4, 0);
/* Check if all cells have the same properties */
if (cells){
ha = ((Cell *) (cells->data))->style->halign;
va = ((Cell *) (cells->data))->style->valign;
for (ok = 1, l = cells; l; l = l->data){
Cell *cell = l->data;
if (cell->style->halign != ha || cell->style->valign != va){
ok = 0;
break;
}
}
/* If all the cells share the same alignment, select that on the radio boxes */
if (ok){
int n;
for (n = 0; horizontal_aligns [n].name; n++)
if (horizontal_aligns [n].flag == ha){
gtk_radio_button_select (hradio_list, n);
break;
}
for (n = 0; vertical_aligns [n].name; n++)
if (vertical_aligns [n].flag == va){
gtk_radio_button_select (vradio_list, n);
break;
}
}
}
/* Now after we *potentially toggled the radio button above, we
* connect the signals to activate the propertybox
*/
for (sl = hradio_list; sl; sl = sl->next){
gtk_signal_connect (GTK_OBJECT (sl->data), "toggled",
GTK_SIGNAL_FUNC (prop_modified), prop_win);
}
for (sl = vradio_list; sl; sl = sl->next){
gtk_signal_connect (GTK_OBJECT (sl->data), "toggled",
GTK_SIGNAL_FUNC (prop_modified), prop_win);
}
gtk_widget_show_all (GTK_WIDGET (t));
return GTK_WIDGET (t);
}
static void
apply_align_format (Sheet *sheet, CellList *cells)
{
}
static struct {
char *title;
GtkWidget *(*create_page)(GtkWidget *prop_win, CellList *cells);
void (*apply_page)(Sheet *sheet, CellList *cells);
} cell_format_pages [] = {
{ N_("Number"), create_number_format_page, apply_number_formats },
{ N_("Number"), create_number_format_page, apply_number_formats },
{ N_("Alignment"), create_align_page, apply_align_format },
{ NULL, NULL }
};
......@@ -389,7 +547,10 @@ cell_properties_close (void)
gtk_main_quit ();
cell_format_prop_win = 0;
}
/*
* Main entry point for the Cell Format dialog box
*/
void
dialog_cell_format (Sheet *sheet)
{
......
......@@ -22,6 +22,10 @@ static GtkWidget *number_input;
static GtkWidget *number_cat_list;
static GtkWidget *number_format_list;
/* There point to the radio groups in the format/alignment page */
static GSList *hradio_list;
static GSList *vradio_list;
/* Points to the first cell in the selection */
static Cell *first_cell;
......@@ -139,6 +143,31 @@ format_list_fill (int n)
gtk_clist_thaw (cl);
}
/*
* This routine is just used at startup to find the current
* format that applies to this cell
*/
static int
format_find (char *format)
{
int i, row;
char **p;
for (i = 0; cell_formats [i].name; i++){
p = cell_formats [i].formats;
for (row = 0; *p; p++, row++){
if (strcmp (format, *p) == 0){
format_list_fill (i);
gtk_clist_select_row (GTK_CLIST (number_format_list), row, 0);
return 1;
}
}
}
return 0;
}
/*
* Invoked when the user has selected a new format category
*/
......@@ -262,7 +291,7 @@ create_number_format_page (GtkWidget *prop_win, CellList *cells)
INPUT_LINE = 3,
};
t = GTK_TABLE (gtk_table_new (0, 0, 0));
t = (GtkTable *) gtk_table_new (0, 0, 0);
/* try to select the current format the user is using */
format = cells_get_format (cells);
......@@ -297,7 +326,7 @@ create_number_format_page (GtkWidget *prop_win, CellList *cells)
number_input = gtk_entry_new ();
gtk_signal_connect (GTK_OBJECT (number_input), "changed",
GTK_SIGNAL_FUNC (format_code_changed), prop_win);
gtk_table_attach (tt, number_input, 1, 2, 0, 1, GTK_FILL | GTK_EXPAND, 0, 0, 2);
/* 2.2 Sample */
......@@ -322,8 +351,12 @@ create_number_format_page (GtkWidget *prop_win, CellList *cells)
/* 3.2: Invoke the current style for the cell if possible */
/* FIXME: Currently we just select the first format */
gtk_clist_select_row (GTK_CLIST (number_format_list), 0, 0);
if (format){
if (!format_find (format->format))
gtk_entry_set_text (GTK_ENTRY (number_input), format->format);
} else
gtk_clist_select_row (GTK_CLIST (number_format_list), 0, 0);
/* 4. finish */
......@@ -359,12 +392,137 @@ apply_number_formats (Sheet *sheet, CellList *list)
}
}
typedef struct {
char *name;
int flag;
} align_def_t;
static align_def_t horizontal_aligns [] = {
{ N_("General"), HALIGN_GENERAL },
{ N_("Left"), HALIGN_LEFT },
{ N_("Center"), HALIGN_CENTER },
{ N_("Right"), HALIGN_RIGHT },
{ N_("Fill"), HALIGN_FILL },
{ N_("Justify"), HALIGN_JUSTIFY },
{ NULL, 0 }
};
static align_def_t vertical_aligns [] = {
{ N_("Top"), VALIGN_TOP },
{ N_("Center"), VALIGN_CENTER },
{ N_("Bottom"), VALIGN_BOTTOM },
{ N_("Justify"), VALIGN_JUSTIFY },
{ NULL, 0 }
};
static GtkWidget *
make_radio_selection (GtkWidget *prop_win, char *title, align_def_t *array, GSList **dest_list)
{
GtkWidget *frame, *vbox;
GSList *group;
frame = gtk_frame_new (title);
vbox = gtk_vbox_new (0, 0);
gtk_container_add (GTK_CONTAINER (frame), vbox);
for (group = NULL;array->name; array++){
GtkWidget *item;
item = gtk_radio_button_new_with_label (group, _(array->name));
group = gtk_radio_button_group (GTK_RADIO_BUTTON (item));
gtk_box_pack_start_defaults (GTK_BOX (vbox), item);
}
*dest_list = group;
return frame;
}
static void
prop_modified (GtkWidget *widge, GnomePropertyBox *box)
{
gnome_property_box_changed (box);
}
static GtkWidget *
create_align_page (GtkWidget *prop_win, CellList *cells)
{
GtkTable *t;
GtkWidget *w;
int ha, va, ok = 0;
GList *l;
GSList *sl;
t = (GtkTable *) gtk_table_new (0, 0, 0);
/* Horizontal alignment */
w = make_radio_selection (prop_win, _("Horizontal"), horizontal_aligns, &hradio_list);
gtk_table_attach (t, w, 0, 1, 0, 2, 0, GTK_FILL, 4, 0);
/* Vertical alignment */
w = make_radio_selection (prop_win, _("Vertical"), vertical_aligns, &vradio_list);
gtk_table_attach (t, w, 1, 2, 0, 1, 0, GTK_FILL, 4, 0);
/* Check if all cells have the same properties */
if (cells){
ha = ((Cell *) (cells->data))->style->halign;
va = ((Cell *) (cells->data))->style->valign;
for (ok = 1, l = cells; l; l = l->data){
Cell *cell = l->data;
if (cell->style->halign != ha || cell->style->valign != va){
ok = 0;
break;
}
}
/* If all the cells share the same alignment, select that on the radio boxes */
if (ok){
int n;
for (n = 0; horizontal_aligns [n].name; n++)
if (horizontal_aligns [n].flag == ha){
gtk_radio_button_select (hradio_list, n);
break;
}
for (n = 0; vertical_aligns [n].name; n++)
if (vertical_aligns [n].flag == va){
gtk_radio_button_select (vradio_list, n);
break;
}
}
}
/* Now after we *potentially toggled the radio button above, we
* connect the signals to activate the propertybox
*/
for (sl = hradio_list; sl; sl = sl->next){
gtk_signal_connect (GTK_OBJECT (sl->data), "toggled",
GTK_SIGNAL_FUNC (prop_modified), prop_win);
}
for (sl = vradio_list; sl; sl = sl->next){
gtk_signal_connect (GTK_OBJECT (sl->data), "toggled",
GTK_SIGNAL_FUNC (prop_modified), prop_win);
}
gtk_widget_show_all (GTK_WIDGET (t));
return GTK_WIDGET (t);
}
static void
apply_align_format (Sheet *sheet, CellList *cells)
{
}
static struct {
char *title;
GtkWidget *(*create_page)(GtkWidget *prop_win, CellList *cells);
void (*apply_page)(Sheet *sheet, CellList *cells);
} cell_format_pages [] = {
{ N_("Number"), create_number_format_page, apply_number_formats },
{ N_("Number"), create_number_format_page, apply_number_formats },
{ N_("Alignment"), create_align_page, apply_align_format },
{ NULL, NULL }
};
......@@ -389,7 +547,10 @@ cell_properties_close (void)
gtk_main_quit ();
cell_format_prop_win = 0;
}
/*
* Main entry point for the Cell Format dialog box
*/
void
dialog_cell_format (Sheet *sheet)
{
......
......@@ -44,3 +44,13 @@ gtk_radio_group_get_selected (GSList *radio_group)
return 0;
}
void
gtk_radio_button_select (GSList *group, int n)
{
GSList *l;
int len = g_slist_length (group);
l = g_slist_nth (group, n);
gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (l->data));
}
......@@ -5,5 +5,6 @@ void gnumeric_notice (char *str);
/* 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);
#endif
......@@ -44,3 +44,13 @@ gtk_radio_group_get_selected (GSList *radio_group)
return 0;
}
void
gtk_radio_button_select (GSList *group, int n)
{
GSList *l;
int len = g_slist_length (group);
l = g_slist_nth (group, n);
gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (l->data));
}
......@@ -5,5 +5,6 @@ void gnumeric_notice (char *str);
/* 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);
#endif
......@@ -83,8 +83,21 @@ item_cursor_realize (GnomeCanvasItem *item)
if (item_cursor->style == ITEM_CURSOR_ANTED)
item_cursor_start_animation (item_cursor);
/*
* Create the stipple pattern for the drag and the autofill cursors
*/
if (item_cursor->style == ITEM_CURSOR_DRAG || item_cursor->style == ITEM_CURSOR_AUTOFILL){
static char stipple_data [] = { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa };