diff options
author | Christopher James Lahey <clahey@helixcode.com> | 2000-05-08 13:22:28 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2000-05-08 13:22:28 +0800 |
commit | 918cfb0b28bb47ae0ffd3f921e7399aa75b61530 (patch) | |
tree | 0c1a0f41f39da6ac28f551f2d144c9f8b0a0b9e8 | |
parent | 2d5740212cec3db7df1c993b2446f7e3f11685d0 (diff) | |
download | gsoc2013-evolution-918cfb0b28bb47ae0ffd3f921e7399aa75b61530.tar gsoc2013-evolution-918cfb0b28bb47ae0ffd3f921e7399aa75b61530.tar.gz gsoc2013-evolution-918cfb0b28bb47ae0ffd3f921e7399aa75b61530.tar.bz2 gsoc2013-evolution-918cfb0b28bb47ae0ffd3f921e7399aa75b61530.tar.lz gsoc2013-evolution-918cfb0b28bb47ae0ffd3f921e7399aa75b61530.tar.xz gsoc2013-evolution-918cfb0b28bb47ae0ffd3f921e7399aa75b61530.tar.zst gsoc2013-evolution-918cfb0b28bb47ae0ffd3f921e7399aa75b61530.zip |
Made a minimal number of things be destroyed and recreated when updating a
2000-05-08 Christopher James Lahey <clahey@helixcode.com>
* gui/minicard/e-minicard-view.c, gui/minicard/e-minicard.c,
gui/minicard/e-minicard.h, gui/minicard/e-reflow-sorted.c,
gui/minicard/e-reflow-sorted.h: Made a minimal number of things be
destroyed and recreated when updating a field.
svn path=/trunk/; revision=2904
-rw-r--r-- | addressbook/ChangeLog | 7 | ||||
-rw-r--r-- | addressbook/gui/minicard/e-minicard-view.c | 12 | ||||
-rw-r--r-- | addressbook/gui/minicard/e-minicard.c | 148 | ||||
-rw-r--r-- | addressbook/gui/minicard/e-minicard.h | 2 | ||||
-rw-r--r-- | addressbook/gui/minicard/e-reflow-sorted.c | 61 | ||||
-rw-r--r-- | addressbook/gui/minicard/e-reflow-sorted.h | 8 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard-view.c | 12 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard.c | 148 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard.h | 2 | ||||
-rw-r--r-- | widgets/e-reflow/e-reflow-sorted.c | 61 | ||||
-rw-r--r-- | widgets/e-reflow/e-reflow-sorted.h | 8 |
11 files changed, 309 insertions, 160 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index c05d832dde..07b556b16e 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,10 @@ +2000-05-08 Christopher James Lahey <clahey@helixcode.com> + + * gui/minicard/e-minicard-view.c, gui/minicard/e-minicard.c, + gui/minicard/e-minicard.h, gui/minicard/e-reflow-sorted.c, + gui/minicard/e-reflow-sorted.h: Made a minimal number of things be + destroyed and recreated when updating a field. + 2000-05-07 <toshok@the-dot-in.helixcode.com> * gui/minicard/e-minicard.c (remodel): make sure to free the diff --git a/addressbook/gui/minicard/e-minicard-view.c b/addressbook/gui/minicard/e-minicard-view.c index 812fee47f0..13f3d01f26 100644 --- a/addressbook/gui/minicard/e-minicard-view.c +++ b/addressbook/gui/minicard/e-minicard-view.c @@ -123,11 +123,13 @@ static void modify_card(EBookView *book_view, const GList *cards, EMinicardView *view) { for (; cards; cards = g_list_next(cards)) { - GnomeCanvasItem *item = gnome_canvas_item_new(GNOME_CANVAS_GROUP(view), - e_minicard_get_type(), - "card", cards->data, - NULL); - e_reflow_sorted_replace_item(E_REFLOW_SORTED(view), item); + ECard *card = cards->data; + gchar *id = e_card_get_id(card); + GnomeCanvasItem *item = e_reflow_sorted_get_item(E_REFLOW_SORTED(view), id); + gnome_canvas_item_set(item, + "card", card, + NULL); + e_reflow_sorted_reorder_item(E_REFLOW_SORTED(view), id); } } diff --git a/addressbook/gui/minicard/e-minicard.c b/addressbook/gui/minicard/e-minicard.c index 0d60824c81..66f7c69da6 100644 --- a/addressbook/gui/minicard/e-minicard.c +++ b/addressbook/gui/minicard/e-minicard.c @@ -47,6 +47,22 @@ static void remodel( EMinicard *e_minicard ); static GnomeCanvasGroupClass *parent_class = NULL; +typedef struct _EMinicardField EMinicardField; + +struct _EMinicardField { + ECardSimpleField field; + GnomeCanvasItem *label; +}; + +#define E_MINICARD_FIELD(field) ((EMinicardField *)(field)) + +static void +e_minicard_field_destroy(EMinicardField *field) +{ + gtk_object_destroy(GTK_OBJECT(field->label)); + g_free(field); +} + /* The arguments we take */ enum { ARG_0, @@ -149,11 +165,11 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) if (e_minicard->fields) { if ( GTK_VALUE_ENUM(*arg) == E_FOCUS_START || GTK_VALUE_ENUM(*arg) == E_FOCUS_CURRENT) { - gnome_canvas_item_set(GNOME_CANVAS_ITEM(e_minicard->fields->data), + gnome_canvas_item_set(E_MINICARD_FIELD(e_minicard->fields->data)->label, "has_focus", GTK_VALUE_ENUM(*arg), NULL); } else if ( GTK_VALUE_ENUM(*arg) == E_FOCUS_END ) { - gnome_canvas_item_set(GNOME_CANVAS_ITEM(g_list_last(e_minicard->fields)->data), + gnome_canvas_item_set(E_MINICARD_FIELD(g_list_last(e_minicard->fields)->data)->label, "has_focus", GTK_VALUE_ENUM(*arg), NULL); } @@ -212,6 +228,9 @@ e_minicard_destroy (GtkObject *object) g_return_if_fail (E_IS_MINICARD (object)); e_minicard = E_MINICARD (object); + + g_list_foreach(e_minicard->fields, (GFunc) e_minicard_field_destroy, NULL); + g_list_free(e_minicard->fields); if (e_minicard->card) gtk_object_unref (GTK_OBJECT(e_minicard->card)); @@ -318,6 +337,20 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) NULL ); e_minicard->has_focus = TRUE; } else { + EBook *book; + + e_card_simple_sync_card(e_minicard->simple); + + gtk_object_get(GTK_OBJECT(GNOME_CANVAS_ITEM(e_minicard)->parent), + "book", &book, + NULL); + + /* Add the card in the contact editor to our ebook */ + e_book_commit_card (book, + e_minicard->card, + card_changed_cb, + NULL); + gnome_canvas_item_set( e_minicard->rect, "outline_color", NULL, NULL ); @@ -384,7 +417,8 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) event->key.keyval == GDK_ISO_Left_Tab) { GList *list; for (list = e_minicard->fields; list; list = list->next) { - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); + EMinicardField *field = E_MINICARD_FIELD(list->data); + GnomeCanvasItem *item = field->label; EFocus has_focus; gtk_object_get(GTK_OBJECT(item), "has_focus", &has_focus, @@ -395,7 +429,8 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) else list = list->next; if (list) { - item = GNOME_CANVAS_ITEM (list->data); + EMinicardField *field = E_MINICARD_FIELD(list->data); + GnomeCanvasItem *item = field->label; gnome_canvas_item_set(item, "has_focus", (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START, NULL); @@ -426,7 +461,7 @@ e_minicard_resize_children( EMinicard *e_minicard ) "width", (double) e_minicard->width - 12, NULL ); for ( list = e_minicard->fields; list; list = g_list_next( list ) ) { - gnome_canvas_item_set( GNOME_CANVAS_ITEM( list->data ), + gnome_canvas_item_set( E_MINICARD_FIELD( list->data )->label, "width", (double) e_minicard->width - 4.0, NULL ); } @@ -452,52 +487,12 @@ field_changed (EText *text, EMinicard *e_minicard) } static void -field_activated (EText *text, EMinicard *e_minicard) -{ - EBook *book; - - e_card_simple_sync_card(e_minicard->simple); - - gtk_object_get(GTK_OBJECT(GNOME_CANVAS_ITEM(e_minicard)->parent), - "book", &book, - NULL); - - /* Add the card in the contact editor to our ebook */ - e_book_commit_card (book, - e_minicard->card, - card_changed_cb, - NULL); -} - -static void -field_event (EText *text, GdkEvent *event, EMinicard *e_minicard) -{ - switch (event->type) { - case GDK_FOCUS_CHANGE: - if (!((GdkEventFocus *)event)->in) { - EBook *book; - - e_card_simple_sync_card(e_minicard->simple); - - gtk_object_get(GTK_OBJECT(GNOME_CANVAS_ITEM(e_minicard)->parent), - "book", &book, - NULL); - - /* Add the card in the contact editor to our ebook */ - e_book_commit_card (book, - e_minicard->card, - card_changed_cb, - NULL); - } - } -} - -static void add_field (EMinicard *e_minicard, ECardSimpleField field) { GnomeCanvasItem *new_item; GnomeCanvasGroup *group; ECardSimpleType type; + EMinicardField *minicard_field; char *name; char *string; @@ -515,45 +510,72 @@ add_field (EMinicard *e_minicard, ECardSimpleField field) NULL ); gtk_signal_connect(GTK_OBJECT(E_MINICARD_LABEL(new_item)->field), "changed", GTK_SIGNAL_FUNC(field_changed), e_minicard); - gtk_signal_connect(GTK_OBJECT(E_MINICARD_LABEL(new_item)->field), - "activate", GTK_SIGNAL_FUNC(field_activated), e_minicard); - gtk_signal_connect(GTK_OBJECT(E_MINICARD_LABEL(new_item)->field), - "event", GTK_SIGNAL_FUNC(field_event), e_minicard); gtk_object_set_data(GTK_OBJECT(E_MINICARD_LABEL(new_item)->field), "EMinicard:field", GINT_TO_POINTER(field)); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + minicard_field = g_new(EMinicardField, 1); + minicard_field->field = field; + minicard_field->label = new_item; + + e_minicard->fields = g_list_append( e_minicard->fields, minicard_field); e_canvas_item_move_absolute(new_item, 2, e_minicard->height); g_free(name); g_free(string); } - static void remodel( EMinicard *e_minicard ) { int count = 0; if (e_minicard->simple) { ECardSimpleField field; + GList *list; char *file_as; + file_as = e_card_simple_get(e_minicard->simple, E_CARD_SIMPLE_FIELD_FILE_AS); gnome_canvas_item_set( e_minicard->header_text, "text", file_as ? file_as : "", NULL ); g_free(file_as); - - g_list_foreach(e_minicard->fields, (GFunc) gtk_object_destroy, NULL); - g_list_free(e_minicard->fields); + + list = e_minicard->fields; e_minicard->fields = NULL; for(field = E_CARD_SIMPLE_FIELD_FULL_NAME; field != E_CARD_SIMPLE_FIELD_LAST && count < 5; field++) { - char *value = e_card_simple_get(e_minicard->simple, field); - if (value) { - add_field(e_minicard, field); - count++; - g_free (value); + EMinicardField *minicard_field = NULL; + if (list) + minicard_field = list->data; + if (minicard_field && minicard_field->field == field) { + GList *this_list = list; + char *string; + + string = e_card_simple_get(e_minicard->simple, field); + if (string && *string) { + e_minicard->fields = g_list_append(e_minicard->fields, minicard_field); + gtk_object_set(GTK_OBJECT(minicard_field->label), + "field", string, + NULL); + count ++; + } else { + e_minicard_field_destroy(minicard_field); + } + list = g_list_remove_link(list, this_list); + g_list_free_1(this_list); + g_free(string); + } else { + char *string; + string = e_card_simple_get(e_minicard->simple, field); + if (string && *string) { + add_field(e_minicard, field); + count++; + } + g_free(string); } } + + g_list_foreach(list, (GFunc) e_minicard_field_destroy, NULL); + g_list_free(list); } } @@ -579,10 +601,12 @@ e_minicard_reflow( GnomeCanvasItem *item, int flags ) NULL ); for(list = e_minicard->fields; list; list = g_list_next(list)) { - gtk_object_get (GTK_OBJECT(list->data), + EMinicardField *field = E_MINICARD_FIELD(list->data); + GnomeCanvasItem *item = field->label; + gtk_object_get (GTK_OBJECT(item), "height", &text_height, NULL); - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), 2, e_minicard->height); + e_canvas_item_move_absolute(item, 2, e_minicard->height); e_minicard->height += text_height; } e_minicard->height += 2; diff --git a/addressbook/gui/minicard/e-minicard.h b/addressbook/gui/minicard/e-minicard.h index 81a6f8bae6..47da8110c2 100644 --- a/addressbook/gui/minicard/e-minicard.h +++ b/addressbook/gui/minicard/e-minicard.h @@ -69,7 +69,7 @@ struct _EMinicard GnomeCanvasItem *header_rect; GnomeCanvasItem *header_text; - GList *fields; /* Of type GnomeCanvasItem. */ + GList *fields; /* Of type EMinicardField */ guint needs_remodeling : 1; gboolean has_focus; diff --git a/addressbook/gui/minicard/e-reflow-sorted.c b/addressbook/gui/minicard/e-reflow-sorted.c index c70d7b2739..688cf87c98 100644 --- a/addressbook/gui/minicard/e-reflow-sorted.c +++ b/addressbook/gui/minicard/e-reflow-sorted.c @@ -136,8 +136,8 @@ e_reflow_sorted_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) } } -void -e_reflow_sorted_remove_item(EReflowSorted *e_reflow_sorted, const gchar *id) +static GList * +e_reflow_sorted_get_list(EReflowSorted *e_reflow_sorted, const gchar *id) { if (e_reflow_sorted->string_func) { EReflow *reflow = E_REFLOW(e_reflow_sorted); @@ -146,16 +146,32 @@ e_reflow_sorted_remove_item(EReflowSorted *e_reflow_sorted, const gchar *id) GnomeCanvasItem *item = list->data; char *string = e_reflow_sorted->string_func (item); if (string && !strcmp(string, id)) { - reflow->items = g_list_remove_link(reflow->items, list); - g_list_free_1(list); - gtk_object_destroy(GTK_OBJECT(item)); - if ( GTK_OBJECT_FLAGS( e_reflow_sorted ) & GNOME_CANVAS_ITEM_REALIZED ) { - e_canvas_item_request_reflow(item); - } - return; + return list; } } } + return NULL; +} + +void +e_reflow_sorted_remove_item(EReflowSorted *e_reflow_sorted, const gchar *id) +{ + GList *list; + GnomeCanvasItem *item = NULL; + + list = e_reflow_sorted_get_list(e_reflow_sorted, id); + if (list) + item = list->data; + + if (item) { + EReflow *reflow = E_REFLOW(e_reflow_sorted); + reflow->items = g_list_remove_link(reflow->items, list); + g_list_free_1(list); + gtk_object_destroy(GTK_OBJECT(item)); + if ( GTK_OBJECT_FLAGS( e_reflow_sorted ) & GNOME_CANVAS_ITEM_REALIZED ) { + e_canvas_item_request_reflow(item); + } + } } void @@ -168,6 +184,33 @@ e_reflow_sorted_replace_item(EReflowSorted *e_reflow_sorted, GnomeCanvasItem *it } } +GnomeCanvasItem * +e_reflow_sorted_get_item(EReflowSorted *e_reflow_sorted, const gchar *id) +{ + GList *list; + list = e_reflow_sorted_get_list(e_reflow_sorted, id); + if (list) + return list->data; + else + return NULL; +} + +void +e_reflow_sorted_reorder_item(EReflowSorted *e_reflow_sorted, const gchar *id) +{ + GList *list; + GnomeCanvasItem *item = NULL; + + list = e_reflow_sorted_get_list(e_reflow_sorted, id); + if (list) + item = list->data; + if (item) { + EReflow *reflow = E_REFLOW(e_reflow_sorted); + reflow->items = g_list_remove_link(reflow->items, list); + g_list_free_1(list); + e_reflow_sorted_add_item(reflow, item); + } +} static void e_reflow_sorted_add_item(EReflow *reflow, GnomeCanvasItem *item) diff --git a/addressbook/gui/minicard/e-reflow-sorted.h b/addressbook/gui/minicard/e-reflow-sorted.h index 4ffec7579b..d9b4acc747 100644 --- a/addressbook/gui/minicard/e-reflow-sorted.h +++ b/addressbook/gui/minicard/e-reflow-sorted.h @@ -76,9 +76,11 @@ struct _EReflowSortedClass * should also do an ECanvas parent reflow request if its size * changes. */ -void e_reflow_sorted_remove_item (EReflowSorted *sorted, const char *id); -void e_reflow_sorted_replace_item (EReflowSorted *sorted, GnomeCanvasItem *item); -GtkType e_reflow_sorted_get_type (void); +void e_reflow_sorted_remove_item (EReflowSorted *sorted, const char *id); +void e_reflow_sorted_replace_item (EReflowSorted *sorted, GnomeCanvasItem *item); +void e_reflow_sorted_reorder_item (EReflowSorted *e_reflow_sorted, const gchar *id); +GnomeCanvasItem *e_reflow_sorted_get_item (EReflowSorted *e_reflow_sorted, const gchar *id); +GtkType e_reflow_sorted_get_type (void); #ifdef __cplusplus } diff --git a/addressbook/gui/widgets/e-minicard-view.c b/addressbook/gui/widgets/e-minicard-view.c index 812fee47f0..13f3d01f26 100644 --- a/addressbook/gui/widgets/e-minicard-view.c +++ b/addressbook/gui/widgets/e-minicard-view.c @@ -123,11 +123,13 @@ static void modify_card(EBookView *book_view, const GList *cards, EMinicardView *view) { for (; cards; cards = g_list_next(cards)) { - GnomeCanvasItem *item = gnome_canvas_item_new(GNOME_CANVAS_GROUP(view), - e_minicard_get_type(), - "card", cards->data, - NULL); - e_reflow_sorted_replace_item(E_REFLOW_SORTED(view), item); + ECard *card = cards->data; + gchar *id = e_card_get_id(card); + GnomeCanvasItem *item = e_reflow_sorted_get_item(E_REFLOW_SORTED(view), id); + gnome_canvas_item_set(item, + "card", card, + NULL); + e_reflow_sorted_reorder_item(E_REFLOW_SORTED(view), id); } } diff --git a/addressbook/gui/widgets/e-minicard.c b/addressbook/gui/widgets/e-minicard.c index 0d60824c81..66f7c69da6 100644 --- a/addressbook/gui/widgets/e-minicard.c +++ b/addressbook/gui/widgets/e-minicard.c @@ -47,6 +47,22 @@ static void remodel( EMinicard *e_minicard ); static GnomeCanvasGroupClass *parent_class = NULL; +typedef struct _EMinicardField EMinicardField; + +struct _EMinicardField { + ECardSimpleField field; + GnomeCanvasItem *label; +}; + +#define E_MINICARD_FIELD(field) ((EMinicardField *)(field)) + +static void +e_minicard_field_destroy(EMinicardField *field) +{ + gtk_object_destroy(GTK_OBJECT(field->label)); + g_free(field); +} + /* The arguments we take */ enum { ARG_0, @@ -149,11 +165,11 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) if (e_minicard->fields) { if ( GTK_VALUE_ENUM(*arg) == E_FOCUS_START || GTK_VALUE_ENUM(*arg) == E_FOCUS_CURRENT) { - gnome_canvas_item_set(GNOME_CANVAS_ITEM(e_minicard->fields->data), + gnome_canvas_item_set(E_MINICARD_FIELD(e_minicard->fields->data)->label, "has_focus", GTK_VALUE_ENUM(*arg), NULL); } else if ( GTK_VALUE_ENUM(*arg) == E_FOCUS_END ) { - gnome_canvas_item_set(GNOME_CANVAS_ITEM(g_list_last(e_minicard->fields)->data), + gnome_canvas_item_set(E_MINICARD_FIELD(g_list_last(e_minicard->fields)->data)->label, "has_focus", GTK_VALUE_ENUM(*arg), NULL); } @@ -212,6 +228,9 @@ e_minicard_destroy (GtkObject *object) g_return_if_fail (E_IS_MINICARD (object)); e_minicard = E_MINICARD (object); + + g_list_foreach(e_minicard->fields, (GFunc) e_minicard_field_destroy, NULL); + g_list_free(e_minicard->fields); if (e_minicard->card) gtk_object_unref (GTK_OBJECT(e_minicard->card)); @@ -318,6 +337,20 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) NULL ); e_minicard->has_focus = TRUE; } else { + EBook *book; + + e_card_simple_sync_card(e_minicard->simple); + + gtk_object_get(GTK_OBJECT(GNOME_CANVAS_ITEM(e_minicard)->parent), + "book", &book, + NULL); + + /* Add the card in the contact editor to our ebook */ + e_book_commit_card (book, + e_minicard->card, + card_changed_cb, + NULL); + gnome_canvas_item_set( e_minicard->rect, "outline_color", NULL, NULL ); @@ -384,7 +417,8 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) event->key.keyval == GDK_ISO_Left_Tab) { GList *list; for (list = e_minicard->fields; list; list = list->next) { - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); + EMinicardField *field = E_MINICARD_FIELD(list->data); + GnomeCanvasItem *item = field->label; EFocus has_focus; gtk_object_get(GTK_OBJECT(item), "has_focus", &has_focus, @@ -395,7 +429,8 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) else list = list->next; if (list) { - item = GNOME_CANVAS_ITEM (list->data); + EMinicardField *field = E_MINICARD_FIELD(list->data); + GnomeCanvasItem *item = field->label; gnome_canvas_item_set(item, "has_focus", (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START, NULL); @@ -426,7 +461,7 @@ e_minicard_resize_children( EMinicard *e_minicard ) "width", (double) e_minicard->width - 12, NULL ); for ( list = e_minicard->fields; list; list = g_list_next( list ) ) { - gnome_canvas_item_set( GNOME_CANVAS_ITEM( list->data ), + gnome_canvas_item_set( E_MINICARD_FIELD( list->data )->label, "width", (double) e_minicard->width - 4.0, NULL ); } @@ -452,52 +487,12 @@ field_changed (EText *text, EMinicard *e_minicard) } static void -field_activated (EText *text, EMinicard *e_minicard) -{ - EBook *book; - - e_card_simple_sync_card(e_minicard->simple); - - gtk_object_get(GTK_OBJECT(GNOME_CANVAS_ITEM(e_minicard)->parent), - "book", &book, - NULL); - - /* Add the card in the contact editor to our ebook */ - e_book_commit_card (book, - e_minicard->card, - card_changed_cb, - NULL); -} - -static void -field_event (EText *text, GdkEvent *event, EMinicard *e_minicard) -{ - switch (event->type) { - case GDK_FOCUS_CHANGE: - if (!((GdkEventFocus *)event)->in) { - EBook *book; - - e_card_simple_sync_card(e_minicard->simple); - - gtk_object_get(GTK_OBJECT(GNOME_CANVAS_ITEM(e_minicard)->parent), - "book", &book, - NULL); - - /* Add the card in the contact editor to our ebook */ - e_book_commit_card (book, - e_minicard->card, - card_changed_cb, - NULL); - } - } -} - -static void add_field (EMinicard *e_minicard, ECardSimpleField field) { GnomeCanvasItem *new_item; GnomeCanvasGroup *group; ECardSimpleType type; + EMinicardField *minicard_field; char *name; char *string; @@ -515,45 +510,72 @@ add_field (EMinicard *e_minicard, ECardSimpleField field) NULL ); gtk_signal_connect(GTK_OBJECT(E_MINICARD_LABEL(new_item)->field), "changed", GTK_SIGNAL_FUNC(field_changed), e_minicard); - gtk_signal_connect(GTK_OBJECT(E_MINICARD_LABEL(new_item)->field), - "activate", GTK_SIGNAL_FUNC(field_activated), e_minicard); - gtk_signal_connect(GTK_OBJECT(E_MINICARD_LABEL(new_item)->field), - "event", GTK_SIGNAL_FUNC(field_event), e_minicard); gtk_object_set_data(GTK_OBJECT(E_MINICARD_LABEL(new_item)->field), "EMinicard:field", GINT_TO_POINTER(field)); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + minicard_field = g_new(EMinicardField, 1); + minicard_field->field = field; + minicard_field->label = new_item; + + e_minicard->fields = g_list_append( e_minicard->fields, minicard_field); e_canvas_item_move_absolute(new_item, 2, e_minicard->height); g_free(name); g_free(string); } - static void remodel( EMinicard *e_minicard ) { int count = 0; if (e_minicard->simple) { ECardSimpleField field; + GList *list; char *file_as; + file_as = e_card_simple_get(e_minicard->simple, E_CARD_SIMPLE_FIELD_FILE_AS); gnome_canvas_item_set( e_minicard->header_text, "text", file_as ? file_as : "", NULL ); g_free(file_as); - - g_list_foreach(e_minicard->fields, (GFunc) gtk_object_destroy, NULL); - g_list_free(e_minicard->fields); + + list = e_minicard->fields; e_minicard->fields = NULL; for(field = E_CARD_SIMPLE_FIELD_FULL_NAME; field != E_CARD_SIMPLE_FIELD_LAST && count < 5; field++) { - char *value = e_card_simple_get(e_minicard->simple, field); - if (value) { - add_field(e_minicard, field); - count++; - g_free (value); + EMinicardField *minicard_field = NULL; + if (list) + minicard_field = list->data; + if (minicard_field && minicard_field->field == field) { + GList *this_list = list; + char *string; + + string = e_card_simple_get(e_minicard->simple, field); + if (string && *string) { + e_minicard->fields = g_list_append(e_minicard->fields, minicard_field); + gtk_object_set(GTK_OBJECT(minicard_field->label), + "field", string, + NULL); + count ++; + } else { + e_minicard_field_destroy(minicard_field); + } + list = g_list_remove_link(list, this_list); + g_list_free_1(this_list); + g_free(string); + } else { + char *string; + string = e_card_simple_get(e_minicard->simple, field); + if (string && *string) { + add_field(e_minicard, field); + count++; + } + g_free(string); } } + + g_list_foreach(list, (GFunc) e_minicard_field_destroy, NULL); + g_list_free(list); } } @@ -579,10 +601,12 @@ e_minicard_reflow( GnomeCanvasItem *item, int flags ) NULL ); for(list = e_minicard->fields; list; list = g_list_next(list)) { - gtk_object_get (GTK_OBJECT(list->data), + EMinicardField *field = E_MINICARD_FIELD(list->data); + GnomeCanvasItem *item = field->label; + gtk_object_get (GTK_OBJECT(item), "height", &text_height, NULL); - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), 2, e_minicard->height); + e_canvas_item_move_absolute(item, 2, e_minicard->height); e_minicard->height += text_height; } e_minicard->height += 2; diff --git a/addressbook/gui/widgets/e-minicard.h b/addressbook/gui/widgets/e-minicard.h index 81a6f8bae6..47da8110c2 100644 --- a/addressbook/gui/widgets/e-minicard.h +++ b/addressbook/gui/widgets/e-minicard.h @@ -69,7 +69,7 @@ struct _EMinicard GnomeCanvasItem *header_rect; GnomeCanvasItem *header_text; - GList *fields; /* Of type GnomeCanvasItem. */ + GList *fields; /* Of type EMinicardField */ guint needs_remodeling : 1; gboolean has_focus; diff --git a/widgets/e-reflow/e-reflow-sorted.c b/widgets/e-reflow/e-reflow-sorted.c index c70d7b2739..688cf87c98 100644 --- a/widgets/e-reflow/e-reflow-sorted.c +++ b/widgets/e-reflow/e-reflow-sorted.c @@ -136,8 +136,8 @@ e_reflow_sorted_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) } } -void -e_reflow_sorted_remove_item(EReflowSorted *e_reflow_sorted, const gchar *id) +static GList * +e_reflow_sorted_get_list(EReflowSorted *e_reflow_sorted, const gchar *id) { if (e_reflow_sorted->string_func) { EReflow *reflow = E_REFLOW(e_reflow_sorted); @@ -146,16 +146,32 @@ e_reflow_sorted_remove_item(EReflowSorted *e_reflow_sorted, const gchar *id) GnomeCanvasItem *item = list->data; char *string = e_reflow_sorted->string_func (item); if (string && !strcmp(string, id)) { - reflow->items = g_list_remove_link(reflow->items, list); - g_list_free_1(list); - gtk_object_destroy(GTK_OBJECT(item)); - if ( GTK_OBJECT_FLAGS( e_reflow_sorted ) & GNOME_CANVAS_ITEM_REALIZED ) { - e_canvas_item_request_reflow(item); - } - return; + return list; } } } + return NULL; +} + +void +e_reflow_sorted_remove_item(EReflowSorted *e_reflow_sorted, const gchar *id) +{ + GList *list; + GnomeCanvasItem *item = NULL; + + list = e_reflow_sorted_get_list(e_reflow_sorted, id); + if (list) + item = list->data; + + if (item) { + EReflow *reflow = E_REFLOW(e_reflow_sorted); + reflow->items = g_list_remove_link(reflow->items, list); + g_list_free_1(list); + gtk_object_destroy(GTK_OBJECT(item)); + if ( GTK_OBJECT_FLAGS( e_reflow_sorted ) & GNOME_CANVAS_ITEM_REALIZED ) { + e_canvas_item_request_reflow(item); + } + } } void @@ -168,6 +184,33 @@ e_reflow_sorted_replace_item(EReflowSorted *e_reflow_sorted, GnomeCanvasItem *it } } +GnomeCanvasItem * +e_reflow_sorted_get_item(EReflowSorted *e_reflow_sorted, const gchar *id) +{ + GList *list; + list = e_reflow_sorted_get_list(e_reflow_sorted, id); + if (list) + return list->data; + else + return NULL; +} + +void +e_reflow_sorted_reorder_item(EReflowSorted *e_reflow_sorted, const gchar *id) +{ + GList *list; + GnomeCanvasItem *item = NULL; + + list = e_reflow_sorted_get_list(e_reflow_sorted, id); + if (list) + item = list->data; + if (item) { + EReflow *reflow = E_REFLOW(e_reflow_sorted); + reflow->items = g_list_remove_link(reflow->items, list); + g_list_free_1(list); + e_reflow_sorted_add_item(reflow, item); + } +} static void e_reflow_sorted_add_item(EReflow *reflow, GnomeCanvasItem *item) diff --git a/widgets/e-reflow/e-reflow-sorted.h b/widgets/e-reflow/e-reflow-sorted.h index 4ffec7579b..d9b4acc747 100644 --- a/widgets/e-reflow/e-reflow-sorted.h +++ b/widgets/e-reflow/e-reflow-sorted.h @@ -76,9 +76,11 @@ struct _EReflowSortedClass * should also do an ECanvas parent reflow request if its size * changes. */ -void e_reflow_sorted_remove_item (EReflowSorted *sorted, const char *id); -void e_reflow_sorted_replace_item (EReflowSorted *sorted, GnomeCanvasItem *item); -GtkType e_reflow_sorted_get_type (void); +void e_reflow_sorted_remove_item (EReflowSorted *sorted, const char *id); +void e_reflow_sorted_replace_item (EReflowSorted *sorted, GnomeCanvasItem *item); +void e_reflow_sorted_reorder_item (EReflowSorted *e_reflow_sorted, const gchar *id); +GnomeCanvasItem *e_reflow_sorted_get_item (EReflowSorted *e_reflow_sorted, const gchar *id); +GtkType e_reflow_sorted_get_type (void); #ifdef __cplusplus } |