X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-recpt-editor.c;h=b0a4bc9a05f00897d4cdd25a20dcff1997bc4466;hb=1a9626a1582455159bfeb0997aab45e589088859;hp=49ef16922f7e39d34a1e86a4af0c4d2d12b66601;hpb=8ad69835f4ecd0ad6e8759b9aa951964649314af;p=modest diff --git a/src/widgets/modest-recpt-editor.c b/src/widgets/modest-recpt-editor.c index 49ef169..b0a4bc9 100644 --- a/src/widgets/modest-recpt-editor.c +++ b/src/widgets/modest-recpt-editor.c @@ -43,12 +43,15 @@ #include #include #include +#include /* FIXNE: we should have no maemo-deps in widgets/ */ #ifndef MODEST_TOOLKIT_GTK -#include "maemo/modest-hildon-includes.h" +#include "modest-hildon-includes.h" #endif /*!MODEST_TOOLKIT_GTK*/ +#define RECPT_BUTTON_WIDTH_HILDON2 118 + static GObjectClass *parent_class = NULL; @@ -84,13 +87,14 @@ static void modest_recpt_editor_class_init (ModestRecptEditorClass *klass); /* widget events */ static void modest_recpt_editor_on_abook_clicked (GtkButton *button, ModestRecptEditor *editor); -static gboolean modest_recpt_editor_on_button_release_event (GtkWidget *widget, - GdkEventButton *event, - ModestRecptEditor *editor); static void modest_recpt_editor_move_cursor_to_end (ModestRecptEditor *editor); -static void modest_recpt_editor_on_focus_in (GtkTextView *text_view, +static gboolean modest_recpt_editor_on_focus_in (GtkTextView *text_view, GdkEventFocus *event, ModestRecptEditor *editor); +static void modest_recpt_editor_on_mark_set (GtkTextBuffer *buffer, + GtkTextIter *iter, + GtkTextMark *mark, + ModestRecptEditor *editor); static void modest_recpt_editor_on_insert_text (GtkTextBuffer *buffer, GtkTextIter *location, gchar *text, @@ -119,7 +123,7 @@ modest_recpt_editor_new (void) { ModestRecptEditor *self = g_object_new (MODEST_TYPE_RECPT_EDITOR, "homogeneous", FALSE, - "spacing", 1, + "spacing", MODEST_MARGIN_NONE, NULL); return GTK_WIDGET (self); @@ -135,7 +139,11 @@ modest_recpt_editor_set_recipients (ModestRecptEditor *recpt_editor, const gchar g_return_if_fail (MODEST_IS_RECPT_EDITOR (recpt_editor)); priv = MODEST_RECPT_EDITOR_GET_PRIVATE (recpt_editor); +#ifdef MODEST_TOOLKIT_HILDON2 + buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (priv->text_view)); +#else buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view)); +#endif valid_recipients = create_valid_text (recipients, -1); g_signal_handlers_block_by_func (buffer, modest_recpt_editor_on_insert_text, recpt_editor); @@ -161,7 +169,11 @@ modest_recpt_editor_add_recipients (ModestRecptEditor *recpt_editor, const gchar if (recipients == NULL) return; +#ifdef MODEST_TOOLKIT_HILDON2 + buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (priv->text_view)); +#else buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view)); +#endif if (gtk_text_buffer_get_char_count (buffer) > 0) { string_to_add = g_strconcat (";\n", recipients, NULL); @@ -196,7 +208,11 @@ modest_recpt_editor_add_resolved_recipient (ModestRecptEditor *recpt_editor, GSL g_return_if_fail (MODEST_IS_RECPT_EDITOR (recpt_editor)); priv = MODEST_RECPT_EDITOR_GET_PRIVATE (recpt_editor); +#ifdef MODEST_TOOLKIT_HILDON2 + buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (priv->text_view)); +#else buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view)); +#endif g_signal_handlers_block_by_func (buffer, modest_recpt_editor_on_insert_text, recpt_editor); gtk_text_buffer_get_bounds (buffer, &start, &end); @@ -248,6 +264,25 @@ modest_recpt_editor_replace_with_resolved_recipient (ModestRecptEditor *recpt_ed GtkTextIter *start, GtkTextIter *end, GSList *email_list, const gchar * recipient_id) { + GSList *email_lists_list; + GSList *recipient_ids_list; + + email_lists_list = g_slist_append (NULL, email_list); + recipient_ids_list = g_slist_append (NULL, (gpointer) recipient_id); + + modest_recpt_editor_replace_with_resolved_recipients (recpt_editor, start, end, + email_lists_list, recipient_ids_list); + + g_slist_free (email_lists_list); + g_slist_free (recipient_ids_list); + +} + +void +modest_recpt_editor_replace_with_resolved_recipients (ModestRecptEditor *recpt_editor, + GtkTextIter *start, GtkTextIter *end, + GSList *email_lists_list, GSList * recipient_ids_list) +{ ModestRecptEditorPrivate *priv; GtkTextBuffer *buffer; GtkTextTag *tag; @@ -257,33 +292,46 @@ modest_recpt_editor_replace_with_resolved_recipient (ModestRecptEditor *recpt_ed g_return_if_fail (MODEST_IS_RECPT_EDITOR (recpt_editor)); priv = MODEST_RECPT_EDITOR_GET_PRIVATE (recpt_editor); +#ifdef MODEST_TOOLKIT_HILDON2 + buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (priv->text_view)); +#else buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view)); +#endif g_signal_handlers_block_by_func (buffer, modest_recpt_editor_on_insert_text, recpt_editor); gtk_text_buffer_delete (buffer, start, end); - tag = gtk_text_buffer_create_tag (buffer, NULL, - "underline", PANGO_UNDERLINE_SINGLE, - "wrap-mode", GTK_WRAP_NONE, - "editable", TRUE, NULL); - - g_object_set_data (G_OBJECT (tag), "recipient-tag-id", GINT_TO_POINTER (RECIPIENT_TAG_ID)); - g_object_set_data_full (G_OBJECT (tag), "recipient-id", g_strdup (recipient_id), (GDestroyNotify) g_free); - - for (node = email_list; node != NULL; node = g_slist_next (node)) { - gchar *recipient = (gchar *) node->data; - - if ((recipient) && (strlen (recipient) != 0)) { - - if (!is_first_recipient) - gtk_text_buffer_insert (buffer, start, "\n", -1); - - gtk_text_buffer_insert_with_tags (buffer, start, recipient, -1, tag, NULL); - - if (node->next != NULL) - gtk_text_buffer_insert (buffer, start, ";", -1); - is_first_recipient = FALSE; + while (email_lists_list) { + gchar *recipient_id = (gchar *) recipient_ids_list->data; + GSList *email_list = (GSList *) email_lists_list->data; + + + tag = gtk_text_buffer_create_tag (buffer, NULL, + "underline", PANGO_UNDERLINE_SINGLE, + "wrap-mode", GTK_WRAP_NONE, + "editable", TRUE, NULL); + + g_object_set_data (G_OBJECT (tag), "recipient-tag-id", GINT_TO_POINTER (RECIPIENT_TAG_ID)); + g_object_set_data_full (G_OBJECT (tag), "recipient-id", g_strdup (recipient_id), (GDestroyNotify) g_free); + + for (node = email_list; node != NULL; node = g_slist_next (node)) { + gchar *recipient = (gchar *) node->data; + + if ((recipient) && (strlen (recipient) != 0)) { + + if (!is_first_recipient) + gtk_text_buffer_insert (buffer, start, "\n", -1); + + gtk_text_buffer_insert_with_tags (buffer, start, recipient, -1, tag, NULL); + + if (node->next != NULL) + gtk_text_buffer_insert (buffer, start, ";", -1); + is_first_recipient = FALSE; + } } + + email_lists_list = g_slist_next (email_lists_list); + recipient_ids_list = g_slist_next (recipient_ids_list); } g_signal_handlers_unblock_by_func (buffer, modest_recpt_editor_on_insert_text, recpt_editor); @@ -306,7 +354,11 @@ modest_recpt_editor_get_recipients (ModestRecptEditor *recpt_editor) priv->recipients = NULL; } +#ifdef MODEST_TOOKIT_HILDON2 + buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (priv->text_view)); +#else buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view)); +#endif gtk_text_buffer_get_start_iter (buffer, &start); gtk_text_buffer_get_end_iter (buffer, &end); @@ -327,23 +379,32 @@ modest_recpt_editor_instance_init (GTypeInstance *instance, gpointer g_class) { ModestRecptEditorPrivate *priv; GtkWidget *abook_icon; + GtkWidget *abook_align; GtkTextBuffer *buffer; priv = MODEST_RECPT_EDITOR_GET_PRIVATE (instance); priv->abook_button = gtk_button_new (); +#ifdef MODEST_TOOLKIT_HILDON2 + gtk_widget_set_size_request (priv->abook_button, RECPT_BUTTON_WIDTH_HILDON2, -1); +#else gtk_button_set_relief (GTK_BUTTON (priv->abook_button), GTK_RELIEF_NONE); +#endif gtk_button_set_focus_on_click (GTK_BUTTON (priv->abook_button), FALSE); GTK_WIDGET_UNSET_FLAGS (priv->abook_button, GTK_CAN_FOCUS); - gtk_button_set_alignment (GTK_BUTTON (priv->abook_button), 1.0, 1.0); + gtk_button_set_alignment (GTK_BUTTON (priv->abook_button), 0.5, 0.5); #ifdef MODEST_TOOLKIT_HILDON2 - abook_icon = gtk_image_new_from_icon_name ("tasklaunch_contact", GTK_ICON_SIZE_BUTTON); + abook_icon = gtk_image_new_from_icon_name ("general_contacts", HILDON_ICON_SIZE_FINGER); #else abook_icon = gtk_image_new_from_icon_name ("qgn_list_addressbook", GTK_ICON_SIZE_BUTTON); #endif gtk_container_add (GTK_CONTAINER (priv->abook_button), abook_icon); +#ifdef MODEST_TOOLKIT_HILDON2 + priv->text_view = hildon_text_view_new (); +#else priv->text_view = gtk_text_view_new (); +#endif /* Auto-capitalization is the default, so let's turn it off: */ #ifdef MAEMO_CHANGES hildon_gtk_text_view_set_input_mode (GTK_TEXT_VIEW (priv->text_view), @@ -352,6 +413,10 @@ modest_recpt_editor_instance_init (GTypeInstance *instance, gpointer g_class) priv->recipients = NULL; +#ifdef MODEST_TOOLKIT_HILDON2 + priv->scrolled_window = NULL; + gtk_box_pack_start (GTK_BOX (instance), priv->text_view, TRUE, TRUE, 0); +#else priv->scrolled_window = modest_scroll_text_new (GTK_TEXT_VIEW (priv->text_view), 1024); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); @@ -360,7 +425,11 @@ modest_recpt_editor_instance_init (GTypeInstance *instance, gpointer g_class) gtk_box_pack_start (GTK_BOX (instance), priv->scrolled_window, TRUE, TRUE, 0); /* gtk_box_pack_start (GTK_BOX (instance), priv->text_view, TRUE, TRUE, 0); */ - gtk_box_pack_end (GTK_BOX (instance), priv->abook_button, FALSE, FALSE, 0); +#endif + abook_align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0); + gtk_alignment_set_padding (GTK_ALIGNMENT (abook_align), 0, 0, MODEST_MARGIN_DEFAULT, 0); + gtk_container_add (GTK_CONTAINER (abook_align), priv->abook_button); + gtk_box_pack_end (GTK_BOX (instance), abook_align, FALSE, FALSE, 0); gtk_text_view_set_accepts_tab (GTK_TEXT_VIEW (priv->text_view), FALSE); gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (priv->text_view), TRUE); @@ -371,12 +440,16 @@ modest_recpt_editor_instance_init (GTypeInstance *instance, gpointer g_class) gtk_widget_set_size_request (priv->text_view, 75, -1); +#ifdef MODEST_TOOLKIT_HILDON2 + buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (priv->text_view)); +#else buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view)); +#endif g_signal_connect (G_OBJECT (priv->abook_button), "clicked", G_CALLBACK (modest_recpt_editor_on_abook_clicked), instance); - g_signal_connect (G_OBJECT (priv->text_view), "button-release-event", G_CALLBACK (modest_recpt_editor_on_button_release_event), instance); g_signal_connect (G_OBJECT (priv->text_view), "key-press-event", G_CALLBACK (modest_recpt_editor_on_key_press_event), instance); g_signal_connect (G_OBJECT (priv->text_view), "focus-in-event", G_CALLBACK (modest_recpt_editor_on_focus_in), instance); g_signal_connect (G_OBJECT (buffer), "insert-text", G_CALLBACK (modest_recpt_editor_on_insert_text), instance); + g_signal_connect (G_OBJECT (buffer), "mark-set", G_CALLBACK (modest_recpt_editor_on_mark_set), instance); /* gtk_container_set_focus_child (GTK_CONTAINER (instance), priv->text_view); */ @@ -392,7 +465,11 @@ modest_recpt_editor_set_field_size_group (ModestRecptEditor *recpt_editor, GtkSi g_return_if_fail (GTK_IS_SIZE_GROUP (size_group)); priv = MODEST_RECPT_EDITOR_GET_PRIVATE (recpt_editor); +#ifdef MODEST_TOOLKIT_HILDON2 + gtk_size_group_add_widget (size_group, priv->text_view); +#else gtk_size_group_add_widget (size_group, priv->scrolled_window); +#endif } GtkTextBuffer * @@ -403,7 +480,11 @@ modest_recpt_editor_get_buffer (ModestRecptEditor *recpt_editor) g_return_val_if_fail (MODEST_IS_RECPT_EDITOR (recpt_editor), NULL); priv = MODEST_RECPT_EDITOR_GET_PRIVATE (recpt_editor); +#ifdef MODEST_TOOLKIT_HILDON2 + return hildon_text_view_get_buffer (HILDON_TEXT_VIEW (priv->text_view)); +#else return gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view)); +#endif } static void @@ -414,23 +495,25 @@ modest_recpt_editor_on_abook_clicked (GtkButton *button, ModestRecptEditor *edit g_signal_emit_by_name (G_OBJECT (editor), "open-addressbook"); } -static gboolean -modest_recpt_editor_on_button_release_event (GtkWidget *widget, - GdkEventButton *event, - ModestRecptEditor *recpt_editor) +static void +modest_recpt_editor_on_mark_set (GtkTextBuffer *buffer, + GtkTextIter *iter, + GtkTextMark *mark, + ModestRecptEditor *recpt_editor) { ModestRecptEditorPrivate *priv; - GtkTextIter location, start, end; - GtkTextMark *mark; - GtkTextBuffer *buffer; + GtkTextIter start, end; + GtkTextMark *selection_bound; GtkTextTag *tag; gboolean selection_changed = FALSE; priv = MODEST_RECPT_EDITOR_GET_PRIVATE (recpt_editor); buffer = modest_recpt_editor_get_buffer (recpt_editor); - mark = gtk_text_buffer_get_insert (buffer); - gtk_text_buffer_get_iter_at_mark (buffer, &location, mark); + selection_bound = gtk_text_buffer_get_selection_bound (buffer); + + if (mark != selection_bound) + return; gtk_text_buffer_get_selection_bounds (buffer, &start, &end); @@ -450,20 +533,18 @@ modest_recpt_editor_on_button_release_event (GtkWidget *widget, if (selection_changed) { gtk_text_buffer_select_range (buffer, &start, &end); - } else { - GTK_TEXT_VIEW (priv->text_view)->pending_place_cursor_button = 0; } - - return FALSE; } -static void +static gboolean modest_recpt_editor_on_focus_in (GtkTextView *text_view, GdkEventFocus *event, ModestRecptEditor *editor) { ModestRecptEditorPrivate *priv = MODEST_RECPT_EDITOR_GET_PRIVATE (editor); gtk_text_view_place_cursor_onscreen (GTK_TEXT_VIEW (priv->text_view)); + + return FALSE; } static gboolean @@ -706,7 +787,11 @@ modest_recpt_editor_on_key_press_event (GtkTextView *text_view, GtkTextIter location, selection_loc; GtkTextTag *tag; +#ifdef MODEST_TOOLKIT_HILDON2 + buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (text_view)); +#else buffer = gtk_text_view_get_buffer (text_view); +#endif insert = gtk_text_buffer_get_insert (buffer); selection = gtk_text_buffer_get_selection_bound (buffer); @@ -863,7 +948,11 @@ static void modest_recpt_editor_move_cursor_to_end (ModestRecptEditor *editor) { ModestRecptEditorPrivate *priv = MODEST_RECPT_EDITOR_GET_PRIVATE (editor); +#ifdef MODEST_TOOLKIT_HILDON2 + GtkTextBuffer *buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (priv->text_view)); +#else GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view)); +#endif GtkTextIter start, end; gtk_text_buffer_get_end_iter (buffer, &start); @@ -881,7 +970,9 @@ modest_recpt_editor_grab_focus (ModestRecptEditor *recpt_editor) g_return_if_fail (MODEST_IS_RECPT_EDITOR (recpt_editor)); priv = MODEST_RECPT_EDITOR_GET_PRIVATE (recpt_editor); - gtk_widget_grab_focus (priv->text_view); + if (GTK_WIDGET_VISIBLE (recpt_editor)) { + gtk_widget_grab_focus (priv->text_view); + } } gboolean @@ -892,7 +983,8 @@ modest_recpt_editor_has_focus (ModestRecptEditor *recpt_editor) g_return_val_if_fail (MODEST_IS_RECPT_EDITOR (recpt_editor), FALSE); priv = MODEST_RECPT_EDITOR_GET_PRIVATE (recpt_editor); - return gtk_widget_is_focus (priv->text_view); + return GTK_WIDGET_VISIBLE (priv->text_view) && + gtk_widget_is_focus (priv->text_view); } static void