diff options
author | Chris Lahey <clahey@src.gnome.org> | 2000-01-12 13:05:30 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2000-01-12 13:05:30 +0800 |
commit | 4d2a782588b3d7b7a24b5838be9a9b280a089895 (patch) | |
tree | 64f7b2cfe89c29f86988144e6725f9e18a3904c1 /widgets | |
parent | c1209c281ed79b5dcc9c201f1968fba972c3641a (diff) | |
download | gsoc2013-evolution-4d2a782588b3d7b7a24b5838be9a9b280a089895.tar gsoc2013-evolution-4d2a782588b3d7b7a24b5838be9a9b280a089895.tar.gz gsoc2013-evolution-4d2a782588b3d7b7a24b5838be9a9b280a089895.tar.bz2 gsoc2013-evolution-4d2a782588b3d7b7a24b5838be9a9b280a089895.tar.lz gsoc2013-evolution-4d2a782588b3d7b7a24b5838be9a9b280a089895.tar.xz gsoc2013-evolution-4d2a782588b3d7b7a24b5838be9a9b280a089895.tar.zst gsoc2013-evolution-4d2a782588b3d7b7a24b5838be9a9b280a089895.zip |
Added a resize signal for when the card changes height. Made it so that
* widgets/e-minicard.c, widgets/e-minicard.h: Added a resize
signal for when the card changes height. Made it so that when you
press tab inside of a field, it goes to the next field.
* widgets/e-minicard-label.c, widgets/e-minicard-label.h: Added a
resize signal for when the label changes height.
* widgets/e-text.c, widgets/e-text.h: Added a resize signal for
multiple lines. Added scrolling based on cursor position.
* widgets/Makefile.am: Removed an extraneous build target.
svn path=/trunk/; revision=1562
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/Makefile.am | 9 | ||||
-rw-r--r-- | widgets/e-minicard-label.c | 114 | ||||
-rw-r--r-- | widgets/e-minicard-label.h | 4 | ||||
-rw-r--r-- | widgets/e-minicard.c | 208 | ||||
-rw-r--r-- | widgets/e-minicard.h | 28 | ||||
-rw-r--r-- | widgets/e-minicard/e-minicard-label.c | 114 | ||||
-rw-r--r-- | widgets/e-minicard/e-minicard-label.h | 4 | ||||
-rw-r--r-- | widgets/e-minicard/e-minicard.c | 208 | ||||
-rw-r--r-- | widgets/e-minicard/e-minicard.h | 28 | ||||
-rw-r--r-- | widgets/e-text.c | 85 | ||||
-rw-r--r-- | widgets/e-text.h | 3 | ||||
-rw-r--r-- | widgets/e-text/e-text.c | 85 | ||||
-rw-r--r-- | widgets/e-text/e-text.h | 3 | ||||
-rw-r--r-- | widgets/text/e-text.c | 85 | ||||
-rw-r--r-- | widgets/text/e-text.h | 3 |
15 files changed, 733 insertions, 248 deletions
diff --git a/widgets/Makefile.am b/widgets/Makefile.am index 2012b00429..91e97910a7 100644 --- a/widgets/Makefile.am +++ b/widgets/Makefile.am @@ -26,8 +26,7 @@ libevolutionwidgets_a_SOURCES = \ noinst_PROGRAMS = \ minicard-label-test \ - minicard-test \ - focus-test + minicard-test minicard_label_test_SOURCES = \ test-minicard-label.c @@ -42,9 +41,3 @@ minicard_test_SOURCES = \ minicard_test_LDADD = \ $(EXTRA_GNOME_LIBS) \ libevolutionwidgets.a - -focus_test_SOURCES = \ - test-focus.c - -focus_test_LDADD = \ - $(EXTRA_GNOME_LIBS) diff --git a/widgets/e-minicard-label.c b/widgets/e-minicard-label.c index 0b6db4115a..9efdd0ba65 100644 --- a/widgets/e-minicard-label.c +++ b/widgets/e-minicard-label.c @@ -22,6 +22,7 @@ #include <gnome.h> #include "e-minicard-label.h" +#include "e-text.h" static void e_minicard_label_init (EMinicardLabel *card); static void e_minicard_label_class_init (EMinicardLabelClass *klass); static void e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); @@ -31,9 +32,17 @@ static void e_minicard_label_realize (GnomeCanvasItem *item); static void e_minicard_label_unrealize (GnomeCanvasItem *item); static void _update_label( EMinicardLabel *minicard_label ); +static void _resize( GtkObject *object, gpointer data ); static GnomeCanvasGroupClass *parent_class = NULL; +enum { + E_MINICARD_LABEL_RESIZE, + E_MINICARD_LABEL_LAST_SIGNAL +}; + +static guint e_minicard_label_signals[E_MINICARD_LABEL_LAST_SIGNAL] = { 0 }; + /* The arguments we take */ enum { ARG_0, @@ -79,14 +88,27 @@ e_minicard_label_class_init (EMinicardLabelClass *klass) parent_class = gtk_type_class (gnome_canvas_group_get_type ()); + e_minicard_label_signals[E_MINICARD_LABEL_RESIZE] = + gtk_signal_new ("resize", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (EMinicardLabelClass, resize), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + + gtk_object_class_add_signals (object_class, e_minicard_label_signals, E_MINICARD_LABEL_LAST_SIGNAL); + gtk_object_add_arg_type ("EMinicardLabel::width", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_WIDTH); gtk_object_add_arg_type ("EMinicardLabel::height", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_HEIGHT); + GTK_ARG_READABLE, ARG_HEIGHT); gtk_object_add_arg_type ("EMinicardLabel::field", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_FIELD); gtk_object_add_arg_type ("EMinicardLabel::fieldname", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_FIELDNAME); + + klass->resize = NULL; object_class->set_arg = e_minicard_label_set_arg; object_class->get_arg = e_minicard_label_get_arg; @@ -126,11 +148,6 @@ e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) _update_label( e_minicard_label ); gnome_canvas_item_request_update (item); break; - case ARG_HEIGHT: - e_minicard_label->height = GTK_VALUE_DOUBLE (*arg); - _update_label( e_minicard_label ); - gnome_canvas_item_request_update (item); - break; case ARG_FIELD: if ( e_minicard_label->field ) gnome_canvas_item_set( e_minicard_label->field, "text", GTK_VALUE_STRING (*arg), NULL ); @@ -214,7 +231,7 @@ e_minicard_label_realize (GnomeCanvasItem *item) "y", (double) 1, "anchor", GTK_ANCHOR_NW, "clip_width", (double) ( e_minicard_label->width / 2 - 4 ), - "clip_height", (double) ( e_minicard_label->height - 3 ), + "clip_height", (double) 1, "clip", TRUE, "use_ellipsis", TRUE, "font", "lucidasans-10", @@ -227,6 +244,11 @@ e_minicard_label_realize (GnomeCanvasItem *item) NULL ); g_free( e_minicard_label->fieldname_text ); } + gtk_signal_connect(GTK_OBJECT(e_minicard_label->fieldname), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard_label); + e_minicard_label->field = gnome_canvas_item_new( group, e_text_get_type(), @@ -234,14 +256,13 @@ e_minicard_label_realize (GnomeCanvasItem *item) "y", (double) 1, "anchor", GTK_ANCHOR_NW, "clip_width", (double) ( ( e_minicard_label->width + 1 ) / 2 - 4 ), - "clip_height", (double) ( e_minicard_label->height - 3 ), + "clip_height", (double) 1, "clip", TRUE, "use_ellipsis", TRUE, "font", "lucidasans-10", "fill_color", "black", "editable", TRUE, NULL ); - if ( e_minicard_label->field_text ) { gnome_canvas_item_set( e_minicard_label->field, @@ -249,6 +270,14 @@ e_minicard_label_realize (GnomeCanvasItem *item) NULL ); g_free( e_minicard_label->field_text ); } + + gtk_signal_connect(GTK_OBJECT(e_minicard_label->field), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard_label); + + _update_label (e_minicard_label); + if (!item->canvas->aa) { } @@ -309,24 +338,57 @@ e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event) } static void -_update_label( EMinicardLabel *minicard_label ) +_update_label( EMinicardLabel *e_minicard_label ) { - if ( GTK_OBJECT_FLAGS( minicard_label ) & GNOME_CANVAS_ITEM_REALIZED ) + if ( GTK_OBJECT_FLAGS( e_minicard_label ) & GNOME_CANVAS_ITEM_REALIZED ) { - gnome_canvas_item_set( minicard_label->rect, - "x2", (double) minicard_label->width - 1, - "y2", (double) minicard_label->height - 1, - NULL ); - gnome_canvas_item_set( minicard_label->fieldname, - "clip_width", (double) ( minicard_label->width / 2 - 4 ), - "clip_height", (double) ( minicard_label->height - 3 ), - "fill_color", "black", - NULL ); - gnome_canvas_item_set( minicard_label->field, - "x", (double) ( minicard_label->width / 2 + 2 ), - "clip_width", (double) ( ( minicard_label->width + 1 ) / 2 - 4 ), - "clip_height", (double) ( minicard_label->height - 3 ), - "fill_color", "black", - NULL ); + gint old_height; + gdouble text_height; + old_height = e_minicard_label->height; + + gtk_object_get(GTK_OBJECT(e_minicard_label->fieldname), + "text_height", &text_height, + NULL); + gnome_canvas_item_set(e_minicard_label->fieldname, + "clip_height", (double) text_height, + NULL); + + e_minicard_label->height = text_height; + + + gtk_object_get(GTK_OBJECT(e_minicard_label->field), + "text_height", &text_height, + NULL); + gnome_canvas_item_set(e_minicard_label->field, + "clip_height", (double) text_height, + NULL); + + if (e_minicard_label->height < text_height) + e_minicard_label->height = text_height; + e_minicard_label->height += 3; + + gnome_canvas_item_set( e_minicard_label->rect, + "x2", (double) e_minicard_label->width - 1, + "y2", (double) e_minicard_label->height - 1, + NULL ); + gnome_canvas_item_set( e_minicard_label->fieldname, + "clip_width", (double) ( e_minicard_label->width / 2 - 4 ), + NULL ); + gnome_canvas_item_set( e_minicard_label->field, + "x", (double) ( e_minicard_label->width / 2 + 2 ), + "clip_width", (double) ( ( e_minicard_label->width + 1 ) / 2 - 4 ), + NULL ); + + if (old_height != e_minicard_label->height) + gtk_signal_emit_by_name (GTK_OBJECT (e_minicard_label), "resize"); + } } + + + +static void +_resize( GtkObject *object, gpointer data ) +{ + _update_label(E_MINICARD_LABEL(data)); +} diff --git a/widgets/e-minicard-label.h b/widgets/e-minicard-label.h index dbf9c3944a..bbaca884ac 100644 --- a/widgets/e-minicard-label.h +++ b/widgets/e-minicard-label.h @@ -66,7 +66,9 @@ struct _EMinicardLabel struct _EMinicardLabelClass { - GnomeCanvasGroupClass parent_class; + GnomeCanvasGroupClass parent_class; + + void (* resize) (EMinicardLabel *text); }; diff --git a/widgets/e-minicard.c b/widgets/e-minicard.c index a5602baef4..01c326d568 100644 --- a/widgets/e-minicard.c +++ b/widgets/e-minicard.c @@ -23,6 +23,7 @@ #include <gnome.h> #include "e-minicard.h" #include "e-minicard-label.h" +#include "e-text.h" static void e_minicard_init (EMinicard *card); static void e_minicard_class_init (EMinicardClass *klass); static void e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); @@ -32,9 +33,17 @@ static void e_minicard_realize (GnomeCanvasItem *item); static void e_minicard_unrealize (GnomeCanvasItem *item); static void _update_card ( EMinicard *minicard ); +static void _resize( GtkObject *object, gpointer data ); static GnomeCanvasGroupClass *parent_class = NULL; +enum { + E_MINICARD_RESIZE, + E_MINICARD_LAST_SIGNAL +}; + +static guint e_minicard_signals[E_MINICARD_LAST_SIGNAL] = { 0 }; + /* The arguments we take */ enum { ARG_0, @@ -79,6 +88,17 @@ e_minicard_class_init (EMinicardClass *klass) parent_class = gtk_type_class (gnome_canvas_group_get_type ()); + e_minicard_signals[E_MINICARD_RESIZE] = + gtk_signal_new ("resize", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (EMinicardClass, resize), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + + gtk_object_class_add_signals (object_class, e_minicard_signals, E_MINICARD_LAST_SIGNAL); + gtk_object_add_arg_type ("EMinicard::width", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_WIDTH); gtk_object_add_arg_type ("EMinicard::height", GTK_TYPE_DOUBLE, @@ -155,9 +175,9 @@ e_minicard_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) static void e_minicard_realize (GnomeCanvasItem *item) { - double text_height; EMinicard *e_minicard; GnomeCanvasGroup *group; + GnomeCanvasItem *new_item; e_minicard = E_MINICARD (item); group = GNOME_CANVAS_GROUP( item ); @@ -199,54 +219,45 @@ e_minicard_realize (GnomeCanvasItem *item) "text", "Chris Lahey", NULL ); - gtk_object_get( GTK_OBJECT( e_minicard->header_text ), - "text_height", &text_height, - NULL ); + gtk_signal_connect(GTK_OBJECT(e_minicard->header_text), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); - e_minicard->height = text_height + 12.0; - - gnome_canvas_item_set( e_minicard->header_rect, - "y2", text_height + 9.0, - NULL ); - - gnome_canvas_item_set( e_minicard->header_text, - "clip_height", text_height, - NULL ); - - e_minicard->fields = - g_list_append( e_minicard->fields, - gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4, - "height", text_height + 3, - "fieldname", "Full Name:", - "field", "Christopher James Lahey", - NULL ) ); - e_minicard->height += text_height + 3; - - e_minicard->fields = - g_list_append( e_minicard->fields, - gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4.0, - "height", text_height + 3.0, - "fieldname", "Email:", - "field", "clahey@helixcode.com", - NULL ) ); - e_minicard->height += text_height + 3; - e_minicard->height += 2; - - gnome_canvas_item_set( e_minicard->rect, - "y2", e_minicard->height - 1, - NULL ); - - if (!item->canvas->aa) - { - } + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4, + "fieldname", "Full Name:", + "field", "Christopher James Lahey", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4.0, + "fieldname", "Email:", + "field", "clahey@helixcode.com", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + + _update_card( e_minicard ); + + if (!item->canvas->aa) { + } } static void @@ -302,6 +313,26 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) } } break; + case GDK_KEY_PRESS: + if (event->key.length == 1 && event->key.string[0] == '\t') { + GList *list; + for (list = e_minicard->fields; list; list = list->next) { + EMinicardLabel *label = E_MINICARD_LABEL (list->data); + if (label->field == label->field->canvas->focused_item) { + if (event->key.state & GDK_SHIFT_MASK) + list = list->prev; + else + list = list->next; + if (list) { + label = E_MINICARD_LABEL (list->data); + gnome_canvas_item_grab_focus(label->field); + return 1; + } else { + return 0; + } + } + } + } default: break; } @@ -313,26 +344,67 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) } static void -_update_card( EMinicard *minicard ) +_update_card( EMinicard *e_minicard ) { - if ( GTK_OBJECT_FLAGS( minicard ) & GNOME_CANVAS_ITEM_REALIZED ) - { - GList *field; - gnome_canvas_item_set( minicard->rect, - "x2", (double) minicard->width - 1.0, - "y2", (double) minicard->height - 1.0, - NULL ); - gnome_canvas_item_set( minicard->header_rect, - "x2", (double) minicard->width - 4.0, - NULL ); - gnome_canvas_item_set( minicard->header_text, - "clip_width", (double) minicard->width - 12, - NULL ); - for ( field = minicard->fields; field; field = g_list_next( field ) ) - { - gnome_canvas_item_set( GNOME_CANVAS_ITEM( field->data ), - "width", minicard->width - 4.0, - NULL ); - } + if ( GTK_OBJECT_FLAGS( e_minicard ) & GNOME_CANVAS_ITEM_REALIZED ) { + GList *list; + gdouble text_height; + gint old_height; + + old_height = e_minicard->height; + + gtk_object_get( GTK_OBJECT( e_minicard->header_text ), + "text_height", &text_height, + NULL ); + + e_minicard->height = text_height + 12.0; + + gnome_canvas_item_set( e_minicard->header_rect, + "y2", text_height + 9.0, + NULL ); + + gnome_canvas_item_set( e_minicard->header_text, + "clip_height", (double)text_height, + NULL ); + + for(list = e_minicard->fields; list; list = g_list_next(list)) { + gtk_object_get (GTK_OBJECT(list->data), + "height", &text_height, + NULL); + gnome_canvas_item_set(GNOME_CANVAS_ITEM(list->data), + "y", (double) e_minicard->height, + NULL); + e_minicard->height += text_height; + } + e_minicard->height += 2; + + gnome_canvas_item_set( e_minicard->rect, + "y2", (double) e_minicard->height - 1, + NULL ); + + gnome_canvas_item_set( e_minicard->rect, + "x2", (double) e_minicard->width - 1.0, + "y2", (double) e_minicard->height - 1.0, + NULL ); + gnome_canvas_item_set( e_minicard->header_rect, + "x2", (double) e_minicard->width - 4.0, + NULL ); + gnome_canvas_item_set( e_minicard->header_text, + "clip_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 ), + "width", (double) e_minicard->width - 4.0, + NULL ); + + if (old_height != e_minicard->height) + gtk_signal_emit_by_name (GTK_OBJECT (e_minicard), "resize"); + } } } + +static void +_resize( GtkObject *object, gpointer data ) +{ + _update_card(E_MINICARD(data)); +} diff --git a/widgets/e-minicard.h b/widgets/e-minicard.h index 759cc4ffb7..43e7d8307f 100644 --- a/widgets/e-minicard.h +++ b/widgets/e-minicard.h @@ -51,23 +51,25 @@ typedef struct _EMinicardClass EMinicardClass; struct _EMinicard { - GnomeCanvasGroup parent; - - /* item specific fields */ - /* ECard *card; */ - - GnomeCanvasItem *rect; - GnomeCanvasItem *header_rect; - GnomeCanvasItem *header_text; - GList *fields; /* Of type GnomeCanvasItem. */ - - double width; - double height; + GnomeCanvasGroup parent; + + /* item specific fields */ + /* ECard *card; */ + + GnomeCanvasItem *rect; + GnomeCanvasItem *header_rect; + GnomeCanvasItem *header_text; + GList *fields; /* Of type GnomeCanvasItem. */ + + double width; + double height; }; struct _EMinicardClass { - GnomeCanvasGroupClass parent_class; + GnomeCanvasGroupClass parent_class; + + void (* resize) (EMinicard *text); }; diff --git a/widgets/e-minicard/e-minicard-label.c b/widgets/e-minicard/e-minicard-label.c index 0b6db4115a..9efdd0ba65 100644 --- a/widgets/e-minicard/e-minicard-label.c +++ b/widgets/e-minicard/e-minicard-label.c @@ -22,6 +22,7 @@ #include <gnome.h> #include "e-minicard-label.h" +#include "e-text.h" static void e_minicard_label_init (EMinicardLabel *card); static void e_minicard_label_class_init (EMinicardLabelClass *klass); static void e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); @@ -31,9 +32,17 @@ static void e_minicard_label_realize (GnomeCanvasItem *item); static void e_minicard_label_unrealize (GnomeCanvasItem *item); static void _update_label( EMinicardLabel *minicard_label ); +static void _resize( GtkObject *object, gpointer data ); static GnomeCanvasGroupClass *parent_class = NULL; +enum { + E_MINICARD_LABEL_RESIZE, + E_MINICARD_LABEL_LAST_SIGNAL +}; + +static guint e_minicard_label_signals[E_MINICARD_LABEL_LAST_SIGNAL] = { 0 }; + /* The arguments we take */ enum { ARG_0, @@ -79,14 +88,27 @@ e_minicard_label_class_init (EMinicardLabelClass *klass) parent_class = gtk_type_class (gnome_canvas_group_get_type ()); + e_minicard_label_signals[E_MINICARD_LABEL_RESIZE] = + gtk_signal_new ("resize", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (EMinicardLabelClass, resize), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + + gtk_object_class_add_signals (object_class, e_minicard_label_signals, E_MINICARD_LABEL_LAST_SIGNAL); + gtk_object_add_arg_type ("EMinicardLabel::width", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_WIDTH); gtk_object_add_arg_type ("EMinicardLabel::height", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_HEIGHT); + GTK_ARG_READABLE, ARG_HEIGHT); gtk_object_add_arg_type ("EMinicardLabel::field", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_FIELD); gtk_object_add_arg_type ("EMinicardLabel::fieldname", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_FIELDNAME); + + klass->resize = NULL; object_class->set_arg = e_minicard_label_set_arg; object_class->get_arg = e_minicard_label_get_arg; @@ -126,11 +148,6 @@ e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) _update_label( e_minicard_label ); gnome_canvas_item_request_update (item); break; - case ARG_HEIGHT: - e_minicard_label->height = GTK_VALUE_DOUBLE (*arg); - _update_label( e_minicard_label ); - gnome_canvas_item_request_update (item); - break; case ARG_FIELD: if ( e_minicard_label->field ) gnome_canvas_item_set( e_minicard_label->field, "text", GTK_VALUE_STRING (*arg), NULL ); @@ -214,7 +231,7 @@ e_minicard_label_realize (GnomeCanvasItem *item) "y", (double) 1, "anchor", GTK_ANCHOR_NW, "clip_width", (double) ( e_minicard_label->width / 2 - 4 ), - "clip_height", (double) ( e_minicard_label->height - 3 ), + "clip_height", (double) 1, "clip", TRUE, "use_ellipsis", TRUE, "font", "lucidasans-10", @@ -227,6 +244,11 @@ e_minicard_label_realize (GnomeCanvasItem *item) NULL ); g_free( e_minicard_label->fieldname_text ); } + gtk_signal_connect(GTK_OBJECT(e_minicard_label->fieldname), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard_label); + e_minicard_label->field = gnome_canvas_item_new( group, e_text_get_type(), @@ -234,14 +256,13 @@ e_minicard_label_realize (GnomeCanvasItem *item) "y", (double) 1, "anchor", GTK_ANCHOR_NW, "clip_width", (double) ( ( e_minicard_label->width + 1 ) / 2 - 4 ), - "clip_height", (double) ( e_minicard_label->height - 3 ), + "clip_height", (double) 1, "clip", TRUE, "use_ellipsis", TRUE, "font", "lucidasans-10", "fill_color", "black", "editable", TRUE, NULL ); - if ( e_minicard_label->field_text ) { gnome_canvas_item_set( e_minicard_label->field, @@ -249,6 +270,14 @@ e_minicard_label_realize (GnomeCanvasItem *item) NULL ); g_free( e_minicard_label->field_text ); } + + gtk_signal_connect(GTK_OBJECT(e_minicard_label->field), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard_label); + + _update_label (e_minicard_label); + if (!item->canvas->aa) { } @@ -309,24 +338,57 @@ e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event) } static void -_update_label( EMinicardLabel *minicard_label ) +_update_label( EMinicardLabel *e_minicard_label ) { - if ( GTK_OBJECT_FLAGS( minicard_label ) & GNOME_CANVAS_ITEM_REALIZED ) + if ( GTK_OBJECT_FLAGS( e_minicard_label ) & GNOME_CANVAS_ITEM_REALIZED ) { - gnome_canvas_item_set( minicard_label->rect, - "x2", (double) minicard_label->width - 1, - "y2", (double) minicard_label->height - 1, - NULL ); - gnome_canvas_item_set( minicard_label->fieldname, - "clip_width", (double) ( minicard_label->width / 2 - 4 ), - "clip_height", (double) ( minicard_label->height - 3 ), - "fill_color", "black", - NULL ); - gnome_canvas_item_set( minicard_label->field, - "x", (double) ( minicard_label->width / 2 + 2 ), - "clip_width", (double) ( ( minicard_label->width + 1 ) / 2 - 4 ), - "clip_height", (double) ( minicard_label->height - 3 ), - "fill_color", "black", - NULL ); + gint old_height; + gdouble text_height; + old_height = e_minicard_label->height; + + gtk_object_get(GTK_OBJECT(e_minicard_label->fieldname), + "text_height", &text_height, + NULL); + gnome_canvas_item_set(e_minicard_label->fieldname, + "clip_height", (double) text_height, + NULL); + + e_minicard_label->height = text_height; + + + gtk_object_get(GTK_OBJECT(e_minicard_label->field), + "text_height", &text_height, + NULL); + gnome_canvas_item_set(e_minicard_label->field, + "clip_height", (double) text_height, + NULL); + + if (e_minicard_label->height < text_height) + e_minicard_label->height = text_height; + e_minicard_label->height += 3; + + gnome_canvas_item_set( e_minicard_label->rect, + "x2", (double) e_minicard_label->width - 1, + "y2", (double) e_minicard_label->height - 1, + NULL ); + gnome_canvas_item_set( e_minicard_label->fieldname, + "clip_width", (double) ( e_minicard_label->width / 2 - 4 ), + NULL ); + gnome_canvas_item_set( e_minicard_label->field, + "x", (double) ( e_minicard_label->width / 2 + 2 ), + "clip_width", (double) ( ( e_minicard_label->width + 1 ) / 2 - 4 ), + NULL ); + + if (old_height != e_minicard_label->height) + gtk_signal_emit_by_name (GTK_OBJECT (e_minicard_label), "resize"); + } } + + + +static void +_resize( GtkObject *object, gpointer data ) +{ + _update_label(E_MINICARD_LABEL(data)); +} diff --git a/widgets/e-minicard/e-minicard-label.h b/widgets/e-minicard/e-minicard-label.h index dbf9c3944a..bbaca884ac 100644 --- a/widgets/e-minicard/e-minicard-label.h +++ b/widgets/e-minicard/e-minicard-label.h @@ -66,7 +66,9 @@ struct _EMinicardLabel struct _EMinicardLabelClass { - GnomeCanvasGroupClass parent_class; + GnomeCanvasGroupClass parent_class; + + void (* resize) (EMinicardLabel *text); }; diff --git a/widgets/e-minicard/e-minicard.c b/widgets/e-minicard/e-minicard.c index a5602baef4..01c326d568 100644 --- a/widgets/e-minicard/e-minicard.c +++ b/widgets/e-minicard/e-minicard.c @@ -23,6 +23,7 @@ #include <gnome.h> #include "e-minicard.h" #include "e-minicard-label.h" +#include "e-text.h" static void e_minicard_init (EMinicard *card); static void e_minicard_class_init (EMinicardClass *klass); static void e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); @@ -32,9 +33,17 @@ static void e_minicard_realize (GnomeCanvasItem *item); static void e_minicard_unrealize (GnomeCanvasItem *item); static void _update_card ( EMinicard *minicard ); +static void _resize( GtkObject *object, gpointer data ); static GnomeCanvasGroupClass *parent_class = NULL; +enum { + E_MINICARD_RESIZE, + E_MINICARD_LAST_SIGNAL +}; + +static guint e_minicard_signals[E_MINICARD_LAST_SIGNAL] = { 0 }; + /* The arguments we take */ enum { ARG_0, @@ -79,6 +88,17 @@ e_minicard_class_init (EMinicardClass *klass) parent_class = gtk_type_class (gnome_canvas_group_get_type ()); + e_minicard_signals[E_MINICARD_RESIZE] = + gtk_signal_new ("resize", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (EMinicardClass, resize), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + + gtk_object_class_add_signals (object_class, e_minicard_signals, E_MINICARD_LAST_SIGNAL); + gtk_object_add_arg_type ("EMinicard::width", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_WIDTH); gtk_object_add_arg_type ("EMinicard::height", GTK_TYPE_DOUBLE, @@ -155,9 +175,9 @@ e_minicard_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) static void e_minicard_realize (GnomeCanvasItem *item) { - double text_height; EMinicard *e_minicard; GnomeCanvasGroup *group; + GnomeCanvasItem *new_item; e_minicard = E_MINICARD (item); group = GNOME_CANVAS_GROUP( item ); @@ -199,54 +219,45 @@ e_minicard_realize (GnomeCanvasItem *item) "text", "Chris Lahey", NULL ); - gtk_object_get( GTK_OBJECT( e_minicard->header_text ), - "text_height", &text_height, - NULL ); + gtk_signal_connect(GTK_OBJECT(e_minicard->header_text), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); - e_minicard->height = text_height + 12.0; - - gnome_canvas_item_set( e_minicard->header_rect, - "y2", text_height + 9.0, - NULL ); - - gnome_canvas_item_set( e_minicard->header_text, - "clip_height", text_height, - NULL ); - - e_minicard->fields = - g_list_append( e_minicard->fields, - gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4, - "height", text_height + 3, - "fieldname", "Full Name:", - "field", "Christopher James Lahey", - NULL ) ); - e_minicard->height += text_height + 3; - - e_minicard->fields = - g_list_append( e_minicard->fields, - gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4.0, - "height", text_height + 3.0, - "fieldname", "Email:", - "field", "clahey@helixcode.com", - NULL ) ); - e_minicard->height += text_height + 3; - e_minicard->height += 2; - - gnome_canvas_item_set( e_minicard->rect, - "y2", e_minicard->height - 1, - NULL ); - - if (!item->canvas->aa) - { - } + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4, + "fieldname", "Full Name:", + "field", "Christopher James Lahey", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4.0, + "fieldname", "Email:", + "field", "clahey@helixcode.com", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + + _update_card( e_minicard ); + + if (!item->canvas->aa) { + } } static void @@ -302,6 +313,26 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) } } break; + case GDK_KEY_PRESS: + if (event->key.length == 1 && event->key.string[0] == '\t') { + GList *list; + for (list = e_minicard->fields; list; list = list->next) { + EMinicardLabel *label = E_MINICARD_LABEL (list->data); + if (label->field == label->field->canvas->focused_item) { + if (event->key.state & GDK_SHIFT_MASK) + list = list->prev; + else + list = list->next; + if (list) { + label = E_MINICARD_LABEL (list->data); + gnome_canvas_item_grab_focus(label->field); + return 1; + } else { + return 0; + } + } + } + } default: break; } @@ -313,26 +344,67 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) } static void -_update_card( EMinicard *minicard ) +_update_card( EMinicard *e_minicard ) { - if ( GTK_OBJECT_FLAGS( minicard ) & GNOME_CANVAS_ITEM_REALIZED ) - { - GList *field; - gnome_canvas_item_set( minicard->rect, - "x2", (double) minicard->width - 1.0, - "y2", (double) minicard->height - 1.0, - NULL ); - gnome_canvas_item_set( minicard->header_rect, - "x2", (double) minicard->width - 4.0, - NULL ); - gnome_canvas_item_set( minicard->header_text, - "clip_width", (double) minicard->width - 12, - NULL ); - for ( field = minicard->fields; field; field = g_list_next( field ) ) - { - gnome_canvas_item_set( GNOME_CANVAS_ITEM( field->data ), - "width", minicard->width - 4.0, - NULL ); - } + if ( GTK_OBJECT_FLAGS( e_minicard ) & GNOME_CANVAS_ITEM_REALIZED ) { + GList *list; + gdouble text_height; + gint old_height; + + old_height = e_minicard->height; + + gtk_object_get( GTK_OBJECT( e_minicard->header_text ), + "text_height", &text_height, + NULL ); + + e_minicard->height = text_height + 12.0; + + gnome_canvas_item_set( e_minicard->header_rect, + "y2", text_height + 9.0, + NULL ); + + gnome_canvas_item_set( e_minicard->header_text, + "clip_height", (double)text_height, + NULL ); + + for(list = e_minicard->fields; list; list = g_list_next(list)) { + gtk_object_get (GTK_OBJECT(list->data), + "height", &text_height, + NULL); + gnome_canvas_item_set(GNOME_CANVAS_ITEM(list->data), + "y", (double) e_minicard->height, + NULL); + e_minicard->height += text_height; + } + e_minicard->height += 2; + + gnome_canvas_item_set( e_minicard->rect, + "y2", (double) e_minicard->height - 1, + NULL ); + + gnome_canvas_item_set( e_minicard->rect, + "x2", (double) e_minicard->width - 1.0, + "y2", (double) e_minicard->height - 1.0, + NULL ); + gnome_canvas_item_set( e_minicard->header_rect, + "x2", (double) e_minicard->width - 4.0, + NULL ); + gnome_canvas_item_set( e_minicard->header_text, + "clip_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 ), + "width", (double) e_minicard->width - 4.0, + NULL ); + + if (old_height != e_minicard->height) + gtk_signal_emit_by_name (GTK_OBJECT (e_minicard), "resize"); + } } } + +static void +_resize( GtkObject *object, gpointer data ) +{ + _update_card(E_MINICARD(data)); +} diff --git a/widgets/e-minicard/e-minicard.h b/widgets/e-minicard/e-minicard.h index 759cc4ffb7..43e7d8307f 100644 --- a/widgets/e-minicard/e-minicard.h +++ b/widgets/e-minicard/e-minicard.h @@ -51,23 +51,25 @@ typedef struct _EMinicardClass EMinicardClass; struct _EMinicard { - GnomeCanvasGroup parent; - - /* item specific fields */ - /* ECard *card; */ - - GnomeCanvasItem *rect; - GnomeCanvasItem *header_rect; - GnomeCanvasItem *header_text; - GList *fields; /* Of type GnomeCanvasItem. */ - - double width; - double height; + GnomeCanvasGroup parent; + + /* item specific fields */ + /* ECard *card; */ + + GnomeCanvasItem *rect; + GnomeCanvasItem *header_rect; + GnomeCanvasItem *header_text; + GList *fields; /* Of type GnomeCanvasItem. */ + + double width; + double height; }; struct _EMinicardClass { - GnomeCanvasGroupClass parent_class; + GnomeCanvasGroupClass parent_class; + + void (* resize) (EMinicard *text); }; diff --git a/widgets/e-text.c b/widgets/e-text.c index e4e8e11f9b..023ad2428d 100644 --- a/widgets/e-text.c +++ b/widgets/e-text.c @@ -27,6 +27,14 @@ #include "e-text-event-processor-emacs-like.h" +enum { + E_TEXT_RESIZE, + E_TEXT_CHANGE, + E_TEXT_LAST_SIGNAL +}; + +static guint e_text_signals[E_TEXT_LAST_SIGNAL] = { 0 }; + /* This defines a line of text */ @@ -130,16 +138,36 @@ e_text_get_type (void) /* Class initialization function for the text item */ static void -e_text_class_init (ETextClass *class) +e_text_class_init (ETextClass *klass) { GtkObjectClass *object_class; GnomeCanvasItemClass *item_class; - object_class = (GtkObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; + object_class = (GtkObjectClass *) klass; + item_class = (GnomeCanvasItemClass *) klass; parent_class = gtk_type_class (gnome_canvas_item_get_type ()); + e_text_signals[E_TEXT_RESIZE] = + gtk_signal_new ("resize", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (ETextClass, resize), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + + e_text_signals[E_TEXT_CHANGE] = + gtk_signal_new ("change", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (ETextClass, change), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + + gtk_object_class_add_signals (object_class, e_text_signals, E_TEXT_LAST_SIGNAL); + gtk_object_add_arg_type ("EText::text", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT); gtk_object_add_arg_type ("EText::x", @@ -185,6 +213,9 @@ e_text_class_init (ETextClass *class) gtk_object_add_arg_type ("EText::ellipsis", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ELLIPSIS); + klass->resize = NULL; + klass->change = NULL; + object_class->destroy = e_text_destroy; object_class->set_arg = e_text_set_arg; object_class->get_arg = e_text_get_arg; @@ -277,6 +308,7 @@ get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, do GnomeCanvasItem *item; double x, y; double clip_x, clip_y; + int old_height; item = GNOME_CANVAS_ITEM (text); @@ -288,11 +320,16 @@ get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, do /* Calculate text dimensions */ + old_height = text->height; + if (text->text && text->font) text->height = (text->font->ascent + text->font->descent) * text->num_lines; else text->height = 0; + if (old_height != text->height) + gtk_signal_emit_by_name (GTK_OBJECT (text), "resize"); + /* Anchor text */ switch (text->anchor) { @@ -358,6 +395,7 @@ get_bounds (EText *text, double *px1, double *py1, double *px2, double *py2) { GnomeCanvasItem *item; double wx, wy; + int old_height; item = GNOME_CANVAS_ITEM (text); @@ -376,11 +414,16 @@ get_bounds (EText *text, double *px1, double *py1, double *px2, double *py2) /* Calculate text dimensions */ + old_height = text->height; + if (text->text && text->font) text->height = (text->font->ascent + text->font->descent) * text->num_lines; else text->height = 0; + if (old_height != text->height) + gtk_signal_emit_by_name (GTK_OBJECT (text), "resize"); + /* Anchor text */ switch (text->anchor) { @@ -552,17 +595,18 @@ split_into_lines (EText *text) len = 0; for (p = text->text; *p; p++) { + if (len == 0) + lines->text = p; if (*p == '\n') { lines->length = len; lines++; len = 0; - } else if (len == 0) { - len++; - lines->text = p; } else len++; } + if (len == 0) + lines->text = p; lines->length = len; calc_line_widths (text); @@ -1517,8 +1561,8 @@ _blink_scroll_timeout (gpointer data) if (text->lastx - text->clip_cx > text->clip_cwidth && text->xofs_edit < text->max_width - text->clip_cwidth) { text->xofs_edit += 4; - if (text->xofs_edit > text->max_width - text->clip_cwidth) - text->xofs_edit = text->max_width - text->clip_cwidth; + if (text->xofs_edit > text->max_width - text->clip_cwidth + 1) + text->xofs_edit = text->max_width - text->clip_cwidth + 1; redraw = TRUE; } if (text->lastx - text->clip_cx < 0 && @@ -1826,6 +1870,31 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp case E_TEP_NOP: break; } + + if (!text->button_down) { + int x; + int i; + struct line *lines = text->lines; + for (lines = text->lines, i = 0; i < text->num_lines ; i++, lines ++) { + if (lines->text - text->text > text->selection_end) { + break; + } + } + lines --; + x = gdk_text_width(text->font, + lines->text, + text->selection_end - (lines->text - text->text)); + + + if (x < text->xofs_edit) { + text->xofs_edit = x; + } + + if (2 + x - text->clip_width > text->xofs_edit) { + text->xofs_edit = 2 + x - text->clip_width; + } + } + gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); } diff --git a/widgets/e-text.h b/widgets/e-text.h index 23713563c3..42683a6a74 100644 --- a/widgets/e-text.h +++ b/widgets/e-text.h @@ -164,6 +164,9 @@ struct _EText { struct _ETextClass { GnomeCanvasItemClass parent_class; + + void (* resize) (EText *text); + void (* change) (EText *text); }; diff --git a/widgets/e-text/e-text.c b/widgets/e-text/e-text.c index e4e8e11f9b..023ad2428d 100644 --- a/widgets/e-text/e-text.c +++ b/widgets/e-text/e-text.c @@ -27,6 +27,14 @@ #include "e-text-event-processor-emacs-like.h" +enum { + E_TEXT_RESIZE, + E_TEXT_CHANGE, + E_TEXT_LAST_SIGNAL +}; + +static guint e_text_signals[E_TEXT_LAST_SIGNAL] = { 0 }; + /* This defines a line of text */ @@ -130,16 +138,36 @@ e_text_get_type (void) /* Class initialization function for the text item */ static void -e_text_class_init (ETextClass *class) +e_text_class_init (ETextClass *klass) { GtkObjectClass *object_class; GnomeCanvasItemClass *item_class; - object_class = (GtkObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; + object_class = (GtkObjectClass *) klass; + item_class = (GnomeCanvasItemClass *) klass; parent_class = gtk_type_class (gnome_canvas_item_get_type ()); + e_text_signals[E_TEXT_RESIZE] = + gtk_signal_new ("resize", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (ETextClass, resize), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + + e_text_signals[E_TEXT_CHANGE] = + gtk_signal_new ("change", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (ETextClass, change), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + + gtk_object_class_add_signals (object_class, e_text_signals, E_TEXT_LAST_SIGNAL); + gtk_object_add_arg_type ("EText::text", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT); gtk_object_add_arg_type ("EText::x", @@ -185,6 +213,9 @@ e_text_class_init (ETextClass *class) gtk_object_add_arg_type ("EText::ellipsis", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ELLIPSIS); + klass->resize = NULL; + klass->change = NULL; + object_class->destroy = e_text_destroy; object_class->set_arg = e_text_set_arg; object_class->get_arg = e_text_get_arg; @@ -277,6 +308,7 @@ get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, do GnomeCanvasItem *item; double x, y; double clip_x, clip_y; + int old_height; item = GNOME_CANVAS_ITEM (text); @@ -288,11 +320,16 @@ get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, do /* Calculate text dimensions */ + old_height = text->height; + if (text->text && text->font) text->height = (text->font->ascent + text->font->descent) * text->num_lines; else text->height = 0; + if (old_height != text->height) + gtk_signal_emit_by_name (GTK_OBJECT (text), "resize"); + /* Anchor text */ switch (text->anchor) { @@ -358,6 +395,7 @@ get_bounds (EText *text, double *px1, double *py1, double *px2, double *py2) { GnomeCanvasItem *item; double wx, wy; + int old_height; item = GNOME_CANVAS_ITEM (text); @@ -376,11 +414,16 @@ get_bounds (EText *text, double *px1, double *py1, double *px2, double *py2) /* Calculate text dimensions */ + old_height = text->height; + if (text->text && text->font) text->height = (text->font->ascent + text->font->descent) * text->num_lines; else text->height = 0; + if (old_height != text->height) + gtk_signal_emit_by_name (GTK_OBJECT (text), "resize"); + /* Anchor text */ switch (text->anchor) { @@ -552,17 +595,18 @@ split_into_lines (EText *text) len = 0; for (p = text->text; *p; p++) { + if (len == 0) + lines->text = p; if (*p == '\n') { lines->length = len; lines++; len = 0; - } else if (len == 0) { - len++; - lines->text = p; } else len++; } + if (len == 0) + lines->text = p; lines->length = len; calc_line_widths (text); @@ -1517,8 +1561,8 @@ _blink_scroll_timeout (gpointer data) if (text->lastx - text->clip_cx > text->clip_cwidth && text->xofs_edit < text->max_width - text->clip_cwidth) { text->xofs_edit += 4; - if (text->xofs_edit > text->max_width - text->clip_cwidth) - text->xofs_edit = text->max_width - text->clip_cwidth; + if (text->xofs_edit > text->max_width - text->clip_cwidth + 1) + text->xofs_edit = text->max_width - text->clip_cwidth + 1; redraw = TRUE; } if (text->lastx - text->clip_cx < 0 && @@ -1826,6 +1870,31 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp case E_TEP_NOP: break; } + + if (!text->button_down) { + int x; + int i; + struct line *lines = text->lines; + for (lines = text->lines, i = 0; i < text->num_lines ; i++, lines ++) { + if (lines->text - text->text > text->selection_end) { + break; + } + } + lines --; + x = gdk_text_width(text->font, + lines->text, + text->selection_end - (lines->text - text->text)); + + + if (x < text->xofs_edit) { + text->xofs_edit = x; + } + + if (2 + x - text->clip_width > text->xofs_edit) { + text->xofs_edit = 2 + x - text->clip_width; + } + } + gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); } diff --git a/widgets/e-text/e-text.h b/widgets/e-text/e-text.h index 23713563c3..42683a6a74 100644 --- a/widgets/e-text/e-text.h +++ b/widgets/e-text/e-text.h @@ -164,6 +164,9 @@ struct _EText { struct _ETextClass { GnomeCanvasItemClass parent_class; + + void (* resize) (EText *text); + void (* change) (EText *text); }; diff --git a/widgets/text/e-text.c b/widgets/text/e-text.c index e4e8e11f9b..023ad2428d 100644 --- a/widgets/text/e-text.c +++ b/widgets/text/e-text.c @@ -27,6 +27,14 @@ #include "e-text-event-processor-emacs-like.h" +enum { + E_TEXT_RESIZE, + E_TEXT_CHANGE, + E_TEXT_LAST_SIGNAL +}; + +static guint e_text_signals[E_TEXT_LAST_SIGNAL] = { 0 }; + /* This defines a line of text */ @@ -130,16 +138,36 @@ e_text_get_type (void) /* Class initialization function for the text item */ static void -e_text_class_init (ETextClass *class) +e_text_class_init (ETextClass *klass) { GtkObjectClass *object_class; GnomeCanvasItemClass *item_class; - object_class = (GtkObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; + object_class = (GtkObjectClass *) klass; + item_class = (GnomeCanvasItemClass *) klass; parent_class = gtk_type_class (gnome_canvas_item_get_type ()); + e_text_signals[E_TEXT_RESIZE] = + gtk_signal_new ("resize", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (ETextClass, resize), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + + e_text_signals[E_TEXT_CHANGE] = + gtk_signal_new ("change", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (ETextClass, change), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + + gtk_object_class_add_signals (object_class, e_text_signals, E_TEXT_LAST_SIGNAL); + gtk_object_add_arg_type ("EText::text", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT); gtk_object_add_arg_type ("EText::x", @@ -185,6 +213,9 @@ e_text_class_init (ETextClass *class) gtk_object_add_arg_type ("EText::ellipsis", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ELLIPSIS); + klass->resize = NULL; + klass->change = NULL; + object_class->destroy = e_text_destroy; object_class->set_arg = e_text_set_arg; object_class->get_arg = e_text_get_arg; @@ -277,6 +308,7 @@ get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, do GnomeCanvasItem *item; double x, y; double clip_x, clip_y; + int old_height; item = GNOME_CANVAS_ITEM (text); @@ -288,11 +320,16 @@ get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, do /* Calculate text dimensions */ + old_height = text->height; + if (text->text && text->font) text->height = (text->font->ascent + text->font->descent) * text->num_lines; else text->height = 0; + if (old_height != text->height) + gtk_signal_emit_by_name (GTK_OBJECT (text), "resize"); + /* Anchor text */ switch (text->anchor) { @@ -358,6 +395,7 @@ get_bounds (EText *text, double *px1, double *py1, double *px2, double *py2) { GnomeCanvasItem *item; double wx, wy; + int old_height; item = GNOME_CANVAS_ITEM (text); @@ -376,11 +414,16 @@ get_bounds (EText *text, double *px1, double *py1, double *px2, double *py2) /* Calculate text dimensions */ + old_height = text->height; + if (text->text && text->font) text->height = (text->font->ascent + text->font->descent) * text->num_lines; else text->height = 0; + if (old_height != text->height) + gtk_signal_emit_by_name (GTK_OBJECT (text), "resize"); + /* Anchor text */ switch (text->anchor) { @@ -552,17 +595,18 @@ split_into_lines (EText *text) len = 0; for (p = text->text; *p; p++) { + if (len == 0) + lines->text = p; if (*p == '\n') { lines->length = len; lines++; len = 0; - } else if (len == 0) { - len++; - lines->text = p; } else len++; } + if (len == 0) + lines->text = p; lines->length = len; calc_line_widths (text); @@ -1517,8 +1561,8 @@ _blink_scroll_timeout (gpointer data) if (text->lastx - text->clip_cx > text->clip_cwidth && text->xofs_edit < text->max_width - text->clip_cwidth) { text->xofs_edit += 4; - if (text->xofs_edit > text->max_width - text->clip_cwidth) - text->xofs_edit = text->max_width - text->clip_cwidth; + if (text->xofs_edit > text->max_width - text->clip_cwidth + 1) + text->xofs_edit = text->max_width - text->clip_cwidth + 1; redraw = TRUE; } if (text->lastx - text->clip_cx < 0 && @@ -1826,6 +1870,31 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp case E_TEP_NOP: break; } + + if (!text->button_down) { + int x; + int i; + struct line *lines = text->lines; + for (lines = text->lines, i = 0; i < text->num_lines ; i++, lines ++) { + if (lines->text - text->text > text->selection_end) { + break; + } + } + lines --; + x = gdk_text_width(text->font, + lines->text, + text->selection_end - (lines->text - text->text)); + + + if (x < text->xofs_edit) { + text->xofs_edit = x; + } + + if (2 + x - text->clip_width > text->xofs_edit) { + text->xofs_edit = 2 + x - text->clip_width; + } + } + gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); } diff --git a/widgets/text/e-text.h b/widgets/text/e-text.h index 23713563c3..42683a6a74 100644 --- a/widgets/text/e-text.h +++ b/widgets/text/e-text.h @@ -164,6 +164,9 @@ struct _EText { struct _ETextClass { GnomeCanvasItemClass parent_class; + + void (* resize) (EText *text); + void (* change) (EText *text); }; |