X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fhildon2%2Fmodest-signature-editor-dialog.c;h=bcb1ef613d102d4d8edcf0d0658b2951c52ced85;hp=70e88278e56de66f09cd3134d9d1ea0feda6bf92;hb=2bca28dca2c6aa234f8297eab0dc9cb6affdc50f;hpb=469562b2be9c3984f17366c25fe662299e230a5a diff --git a/src/hildon2/modest-signature-editor-dialog.c b/src/hildon2/modest-signature-editor-dialog.c index 70e8827..bcb1ef6 100644 --- a/src/hildon2/modest-signature-editor-dialog.c +++ b/src/hildon2/modest-signature-editor-dialog.c @@ -37,7 +37,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -55,10 +56,15 @@ struct _ModestSignatureEditorDialogPrivate { GtkWidget *checkbox_use; GtkWidget *label; - GtkWidget *pannable; + GtkWidget *scrollable; GtkWidget *textview; + + guint correct_scroll_idle; }; +static void text_buffer_end_user_action (GtkTextBuffer *buffer, + ModestSignatureEditorDialog *userdata); + static void modest_signature_editor_dialog_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) @@ -89,6 +95,14 @@ modest_signature_editor_dialog_dispose (GObject *object) static void modest_signature_editor_dialog_finalize (GObject *object) { + ModestSignatureEditorDialogPrivate *priv; + + priv = SIGNATURE_EDITOR_DIALOG_GET_PRIVATE (object); + + if (priv->correct_scroll_idle > 0) { + g_source_remove (priv->correct_scroll_idle); + priv->correct_scroll_idle = 0; + } G_OBJECT_CLASS (modest_signature_editor_dialog_parent_class)->finalize (object); } @@ -111,14 +125,14 @@ enable_widgets (ModestSignatureEditorDialog *self) ModestSignatureEditorDialogPrivate *priv = SIGNATURE_EDITOR_DIALOG_GET_PRIVATE (self); - const gboolean enable = hildon_check_button_get_active (HILDON_CHECK_BUTTON (priv->checkbox_use)); + const gboolean enable = modest_togglable_get_active (priv->checkbox_use); gtk_widget_set_sensitive (priv->label, enable); gtk_widget_set_sensitive (priv->textview, enable); gtk_text_view_set_editable (GTK_TEXT_VIEW (priv->textview), enable); } static void -on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data) +on_toggle_button_changed (GtkWidget *togglebutton, gpointer user_data) { ModestSignatureEditorDialog *self = MODEST_SIGNATURE_EDITOR_DIALOG (user_data); enable_widgets (self); @@ -136,10 +150,8 @@ modest_signature_editor_dialog_init (ModestSignatureEditorDialog *self) GtkWidget *box = GTK_DIALOG(self)->vbox; /* gtk_vbox_new (FALSE, MODEST_MARGIN_HALF); */ top_box = gtk_vbox_new (FALSE, 0); - priv->checkbox_use = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT); - gtk_button_set_label (GTK_BUTTON (priv->checkbox_use), - _("mcen_fi_email_signatures_use_signature")); - gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_use), 0.0, 0.5); + priv->checkbox_use = modest_toolkit_factory_create_check_button (modest_runtime_get_toolkit_factory (), + _("mcen_fi_email_signatures_use_signature")); gtk_box_pack_start (GTK_BOX (top_box), priv->checkbox_use, FALSE, FALSE, 0); gtk_widget_show (priv->checkbox_use); @@ -156,7 +168,11 @@ modest_signature_editor_dialog_init (ModestSignatureEditorDialog *self) gtk_widget_show (priv->textview); GtkTextBuffer *buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (priv->textview)); gtk_text_buffer_set_text (buffer, _("mcen_va_default_signature_tablet"), -1); /* Default, as per the UI spec. */ + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (priv->textview), GTK_WRAP_WORD_CHAR); gtk_box_pack_start (GTK_BOX (top_box), priv->textview, TRUE, TRUE, 0); + + g_signal_connect (G_OBJECT (buffer), "end-user-action", + G_CALLBACK (text_buffer_end_user_action), self); /* Add the buttons: */ gtk_dialog_add_button (GTK_DIALOG (self), _HL("wdgt_bd_save"), GTK_RESPONSE_OK); @@ -168,12 +184,10 @@ modest_signature_editor_dialog_init (ModestSignatureEditorDialog *self) gtk_widget_show (top_box); - priv->pannable = hildon_pannable_area_new (); - hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (priv->pannable), align); - gtk_container_set_focus_vadjustment (GTK_CONTAINER (top_box), - hildon_pannable_area_get_vadjustment (HILDON_PANNABLE_AREA (priv->pannable))); - gtk_container_add (GTK_CONTAINER (GTK_DIALOG (self)->vbox), priv->pannable); - gtk_widget_show (priv->pannable); + priv->scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ()); + modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (priv->scrollable), align); + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (self)->vbox), priv->scrollable); + gtk_widget_show (priv->scrollable); gtk_widget_show (box); gtk_widget_set_size_request (GTK_WIDGET (self), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT); @@ -182,6 +196,8 @@ modest_signature_editor_dialog_init (ModestSignatureEditorDialog *self) * because there is no sensible way to save the state: */ modest_window_mgr_prevent_hibernation_while_window_is_shown ( modest_runtime_get_window_mgr (), GTK_WINDOW (self)); + + priv->correct_scroll_idle = 0; } @@ -206,7 +222,7 @@ modest_signature_editor_dialog_set_settings ( gtk_label_set_ellipsize (GTK_LABEL (priv->label), PANGO_ELLIPSIZE_END); g_free (label_text); - hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_use), use_signature); + modest_togglable_set_active (priv->checkbox_use, use_signature); GtkTextBuffer *buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (priv->textview)); if (signature && signature[0] != '\0') @@ -228,7 +244,7 @@ modest_signature_editor_dialog_get_settings ( g_assert(use_signature); - *use_signature = hildon_check_button_get_active (HILDON_CHECK_BUTTON (priv->checkbox_use)); + *use_signature = modest_togglable_get_active (priv->checkbox_use); GtkTextBuffer *buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (priv->textview)); @@ -236,3 +252,80 @@ modest_signature_editor_dialog_get_settings ( gtk_text_buffer_get_bounds (buffer, &start, &end); return gtk_text_buffer_get_text (buffer, &start, &end, TRUE); } + +static gboolean +correct_scroll_idle_func (gpointer userdata) +{ + ModestSignatureEditorDialog *self = (ModestSignatureEditorDialog *) userdata; + ModestSignatureEditorDialogPrivate *priv; + GtkTextBuffer *buffer; + GtkTextIter iter; + GdkRectangle rectangle; + gint offset_min, offset_max; + GtkTextMark *insert; + GtkAdjustment *vadj; + + /* It could happen that the window was already closed */ + if (!GTK_WIDGET_VISIBLE (self)) + return FALSE; + + priv = SIGNATURE_EDITOR_DIALOG_GET_PRIVATE(self); + buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (priv->textview)); + + insert = gtk_text_buffer_get_insert (buffer); + gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert); + + gtk_text_view_get_iter_location (GTK_TEXT_VIEW (priv->textview), &iter, &rectangle); + offset_min = priv->textview->allocation.y + rectangle.y; + offset_max = offset_min + rectangle.height; + + vadj = modest_scrollable_get_vadjustment (MODEST_SCROLLABLE (priv->scrollable)); + offset_min = MAX (offset_min - 48, 0); + offset_max = MIN (offset_max + 48, vadj->upper); + + if ((offset_min < vadj->value) || (offset_max > vadj->value + vadj->page_size)) { + /* We check if the current center of the visible area is already matching the center + of the selection */ + gint offset_center; + gint center_top, center_bottom; + + offset_center = (offset_min + offset_max) / 2; + center_top = vadj->value + vadj->page_size / 3; + center_bottom = vadj->value + vadj->page_size * 2 / 3; + + if ((offset_center < center_top) || + (offset_center > center_bottom)) + modest_scrollable_scroll_to (MODEST_SCROLLABLE (priv->scrollable), -1, offset_center); + } + + priv->correct_scroll_idle = 0; + return FALSE; +} + +static void correct_scroll (ModestSignatureEditorDialog *self) +{ + ModestSignatureEditorDialogPrivate *priv; + + priv = SIGNATURE_EDITOR_DIALOG_GET_PRIVATE(self); + + if (!gtk_widget_is_focus (priv->textview)) + return; + + if (priv->correct_scroll_idle > 0) { + return; + } + + priv->correct_scroll_idle = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, + (GSourceFunc) correct_scroll_idle_func, + g_object_ref (self), + g_object_unref); +} + +static void +text_buffer_end_user_action (GtkTextBuffer *buffer, + ModestSignatureEditorDialog *userdata) +{ + + correct_scroll (userdata); +} +