diff options
-rw-r--r-- | widgets/table/e-cell-combo.c | 36 | ||||
-rw-r--r-- | widgets/table/e-cell-combo.h | 4 | ||||
-rw-r--r-- | widgets/table/e-cell-text.c | 50 | ||||
-rw-r--r-- | widgets/table/e-cell-text.h | 12 |
4 files changed, 65 insertions, 37 deletions
diff --git a/widgets/table/e-cell-combo.c b/widgets/table/e-cell-combo.c index cbf9b4aa18..7a6a0c29b6 100644 --- a/widgets/table/e-cell-combo.c +++ b/widgets/table/e-cell-combo.c @@ -59,6 +59,7 @@ #include "gal/util/e-util.h" #include "e-table-item.h" #include "e-cell-combo.h" +#include "e-cell-text.h" /* The height to make the popup list if there aren't any items in it. */ @@ -257,6 +258,7 @@ e_cell_combo_select_matching_item (ECellCombo *ecc) { ECellPopup *ecp = E_CELL_POPUP (ecc); ECellView *ecv = (ECellView*) ecp->popup_cell_view; + ECellText *ecell_text = E_CELL_TEXT (ecp->child); ETableItem *eti = E_TABLE_ITEM (ecp->popup_cell_view->cell_view.e_table_item_view); ETableCol *ecol; GtkList *list; @@ -266,8 +268,8 @@ e_cell_combo_select_matching_item (ECellCombo *ecc) char *cell_text, *list_item_text; ecol = e_table_header_get_column (eti->header, ecp->popup_view_col); - cell_text = e_table_model_value_at (ecv->e_table_model, - ecol->col_idx, ecp->popup_row); + cell_text = e_cell_text_get_text (ecell_text, ecv->e_table_model, + ecol->col_idx, ecp->popup_row); list = GTK_LIST (ecc->popup_list); elem = list->children; @@ -291,6 +293,8 @@ e_cell_combo_select_matching_item (ECellCombo *ecc) if (list->children) gtk_widget_grab_focus (GTK_WIDGET (list->children->data)); } + + e_cell_text_free_text (ecell_text, cell_text); } @@ -299,8 +303,6 @@ e_cell_combo_show_popup (ECellCombo *ecc) { gint x, y, width, height, old_width, old_height; - g_print ("In e_cell_popup_popup_list\n"); - /* This code is practically copied from GtkCombo. */ old_width = ecc->popup_window->allocation.width; old_height = ecc->popup_window->allocation.height; @@ -470,8 +472,6 @@ e_cell_combo_button_press (GtkWidget *popup_window, { GtkWidget *event_widget; - g_print ("In e_cell_combo_button_press\n"); - event_widget = gtk_get_event_widget (event); /* If the button press was for a widget inside the popup list, but @@ -516,9 +516,6 @@ e_cell_combo_button_release (GtkWidget *popup_window, event_widget = gtk_get_event_widget ((GdkEvent*) event); - g_print ("In e_cell_popup_button_release event_widget:%s\n", - gtk_widget_get_name (event_widget)); - /* See if the button was released in the list (or its children). */ while (event_widget && event_widget != ecc->popup_list) event_widget = event_widget->parent; @@ -549,8 +546,6 @@ e_cell_combo_key_press (GtkWidget *popup_window, GdkEventKey *event, ECellCombo *ecc) { - g_print ("In e_cell_popup_key_press\n"); - /* If the Escape key is pressed we hide the popup. */ if (event->keyval != GDK_Escape && event->keyval != GDK_Return @@ -579,14 +574,13 @@ e_cell_combo_update_cell (ECellCombo *ecc) { ECellPopup *ecp = E_CELL_POPUP (ecc); ECellView *ecv = (ECellView*) ecp->popup_cell_view; + ECellText *ecell_text = E_CELL_TEXT (ecp->child); ETableItem *eti = E_TABLE_ITEM (ecv->e_table_item_view); ETableCol *ecol; GtkList *list = GTK_LIST (ecc->popup_list); GtkListItem *listitem; gchar *text, *old_text; - g_print ("In e_cell_popup_update_cell\n"); - /* Return if no item is selected. */ if (list->selection == NULL) return; @@ -597,19 +591,17 @@ e_cell_combo_update_cell (ECellCombo *ecc) /* Compare it with the existing cell contents. */ ecol = e_table_header_get_column (eti->header, ecp->popup_view_col); - old_text = e_table_model_value_at (ecv->e_table_model, - ecol->col_idx, ecp->popup_row); - g_print (" Old text: %s New text: %s\n", old_text, text); + old_text = e_cell_text_get_text (ecell_text, ecv->e_table_model, + ecol->col_idx, ecp->popup_row); /* If they are different, update the cell contents. */ - if (strcmp (old_text, text)) { - g_print (" Setting cell text...\n"); - e_table_model_set_value_at (ecv->e_table_model, - ecol->col_idx, ecp->popup_row, - text); - g_print (" Set cell text.\n"); + if (old_text && strcmp (old_text, text)) { + e_cell_text_set_value (ecell_text, ecv->e_table_model, + ecol->col_idx, ecp->popup_row, text); } + + e_cell_text_free_text (ecell_text, old_text); } diff --git a/widgets/table/e-cell-combo.h b/widgets/table/e-cell-combo.h index 9f8833d029..27b841a936 100644 --- a/widgets/table/e-cell-combo.h +++ b/widgets/table/e-cell-combo.h @@ -25,7 +25,8 @@ /* * ECellCombo - a subclass of ECellPopup used to support popup lists like a * GtkCombo widget. It only supports a basic popup list of strings at present, - * with no auto-completion. + * with no auto-completion. The child ECell of the ECellPopup must be an + * ECellText or subclass. */ #ifndef _E_CELL_COMBO_H_ @@ -56,6 +57,7 @@ typedef struct { GtkType e_cell_combo_get_type (void); ECell *e_cell_combo_new (void); +/* These must be UTF-8. */ void e_cell_combo_set_popdown_strings (ECellCombo *ecc, GList *strings); diff --git a/widgets/table/e-cell-text.c b/widgets/table/e-cell-text.c index 2894ff30d5..469b5fb261 100644 --- a/widgets/table/e-cell-text.c +++ b/widgets/table/e-cell-text.c @@ -211,8 +211,8 @@ static GdkColor* e_cell_text_get_color (ECellTextView *cell_view, gchar *color_s static ECellClass *parent_class; -static char * -ect_get_text (ECellText *cell, ETableModel *model, int col, int row) +char * +e_cell_text_get_text (ECellText *cell, ETableModel *model, int col, int row) { if (ECT_CLASS(cell)->get_text) return ECT_CLASS(cell)->get_text (cell, model, col, row); @@ -220,13 +220,21 @@ ect_get_text (ECellText *cell, ETableModel *model, int col, int row) return NULL; } -static void -ect_free_text (ECellText *cell, char *text) +void +e_cell_text_free_text (ECellText *cell, char *text) { if (ECT_CLASS(cell)->free_text) ECT_CLASS(cell)->free_text (cell, text); } +void +e_cell_text_set_value (ECellText *cell, ETableModel *model, int col, int row, + const char *text) +{ + if (ECT_CLASS(cell)->set_value) + ECT_CLASS(cell)->set_value (cell, model, col, row, text); +} + static char * ect_real_get_text (ECellText *cell, ETableModel *model, int col, int row) { @@ -238,6 +246,17 @@ ect_real_free_text (ECellText *cell, char *text) { } +/* This is the default method for setting the ETableModel value based on + the text in the ECellText. This simply uses the text as it is - it assumes + the value in the model is a char*. Subclasses may parse the text into + data structures to pass to the model. */ +static void +ect_real_set_value (ECellText *cell, ETableModel *model, int col, int row, + const char *text) +{ + e_table_model_set_value_at (model, col, row, text); +} + static void ect_queue_redraw (ECellTextView *text_view, int view_col, int view_row) { @@ -253,10 +272,12 @@ static void ect_accept_edits (ECellTextView *text_view) { CurrentCell *cell = (CurrentCell *) text_view->edit; + ECellView *ecell_view = (ECellView *) text_view; + ECellText *ect = (ECellText *) ecell_view->ecell; if (strcmp (text_view->edit->old_text, cell->text)) { - e_table_model_set_value_at (text_view->cell_view.e_table_model, - cell->model_col, cell->row, cell->text); + e_cell_text_set_value (ect, ecell_view->e_table_model, + cell->model_col, cell->row, cell->text); } } @@ -951,9 +972,9 @@ ect_height (ECellView *ecell_view, int model_col, int view_col, int row) if (row == -1) { value = e_font_height (font) + TEXT_PAD; } else { - string = ect_get_text(ect, ecell_view->e_table_model, model_col, row); + string = e_cell_text_get_text(ect, ecell_view->e_table_model, model_col, row); value = e_font_height (font) * number_of_lines(string) + TEXT_PAD; - ect_free_text(ect, string); + e_cell_text_free_text(ect, string); } return value; @@ -1010,9 +1031,9 @@ ect_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) edit->pointer_in = FALSE; edit->default_cursor_shown = TRUE; - temp = ect_get_text(ect, ecell_view->e_table_model, model_col, row); + temp = e_cell_text_get_text(ect, ecell_view->e_table_model, model_col, row); edit->old_text = g_strdup (temp); - ect_free_text(ect, temp); + e_cell_text_free_text(ect, temp); edit->cell.text = g_strdup (edit->old_text); #if 0 @@ -1059,7 +1080,7 @@ ect_print (ECellView *ecell_view, GnomePrintContext *context, GnomeFont *font = gnome_font_new ("Helvetica", 12); char *string; ECellText *ect = E_CELL_TEXT(ecell_view->ecell); - string = ect_get_text(ect, ecell_view->e_table_model, model_col, row); + string = e_cell_text_get_text(ect, ecell_view->e_table_model, model_col, row); gnome_print_gsave(context); if (gnome_print_moveto(context, 2, 2) == -1) /* FIXME */; @@ -1077,7 +1098,7 @@ ect_print (ECellView *ecell_view, GnomePrintContext *context, gnome_print_setfont(context, font); gnome_print_show(context, string); gnome_print_grestore(context); - ect_free_text(ect, string); + e_cell_text_free_text(ect, string); } static gdouble @@ -1421,6 +1442,7 @@ e_cell_text_class_init (GtkObjectClass *object_class) ectc->get_text = ect_real_get_text; ectc->free_text = ect_real_free_text; + ectc->set_value = ect_real_set_value; object_class->get_arg = ect_get_arg; object_class->set_arg = ect_set_arg; @@ -2415,9 +2437,9 @@ build_current_cell (CurrentCell *cell, ECellTextView *text_view, int model_col, cell->row = row; cell->breaks = NULL; - temp = ect_get_text(ect, ecell_view->e_table_model, model_col, row); + temp = e_cell_text_get_text(ect, ecell_view->e_table_model, model_col, row); cell->text = g_strdup(temp); - ect_free_text(ect, temp); + e_cell_text_free_text(ect, temp); cell->width = e_table_header_get_column ( ((ETableItem *)ecell_view->e_table_item_view)->header, diff --git a/widgets/table/e-cell-text.h b/widgets/table/e-cell-text.h index 078f8e7629..e5dfd54b71 100644 --- a/widgets/table/e-cell-text.h +++ b/widgets/table/e-cell-text.h @@ -69,12 +69,24 @@ typedef struct { char *(*get_text) (ECellText *cell, ETableModel *model, int col, int row); void (*free_text) (ECellText *cell, char *text); + void (*set_value) (ECellText *cell, ETableModel *model, int col, int row, const char *text); } ECellTextClass; GtkType e_cell_text_get_type (void); ECell *e_cell_text_new (const char *fontname, GtkJustification justify); ECell *e_cell_text_construct(ECellText *cell, const char *fontname, GtkJustification justify); +/* Gets the value from the model and converts it into a string. In ECellText + itself, the value is assumed to be a char* and so needs no conversion. + In subclasses the ETableModel value may be a more complicated datatype. */ +char *e_cell_text_get_text (ECellText *cell, ETableModel *model, int col, int row); + +/* Frees the value returned by e_cell_text_get_text(). */ +void e_cell_text_free_text (ECellText *cell, char *text); + +/* Sets the ETableModel value, based on the given string. */ +void e_cell_text_set_value (ECellText *cell, ETableModel *model, int col, int row, const char *text); + END_GNOME_DECLS #endif /* _E_CELL_TEXT_H_ */ |