X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fhildon2%2Fmodest-signature-editor-dialog.c;h=bcb1ef613d102d4d8edcf0d0658b2951c52ced85;hp=2226b3b3827fd9ae0a2216d95a4874ea8b57284d;hb=2bca28dca2c6aa234f8297eab0dc9cb6affdc50f;hpb=e374da56f67092cecb1572dd4bee2ca34e0bc04c diff --git a/src/hildon2/modest-signature-editor-dialog.c b/src/hildon2/modest-signature-editor-dialog.c index 2226b3b..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->pannable, 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); @@ -129,17 +143,16 @@ modest_signature_editor_dialog_init (ModestSignatureEditorDialog *self) { ModestSignatureEditorDialogPrivate *priv = SIGNATURE_EDITOR_DIALOG_GET_PRIVATE (self); + GtkWidget *top_box, *align; gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_email_signatures_edit_title")); GtkWidget *box = GTK_DIALOG(self)->vbox; /* gtk_vbox_new (FALSE, MODEST_MARGIN_HALF); */ - gtk_container_set_border_width (GTK_CONTAINER (box), 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); - gtk_box_pack_start (GTK_BOX (box), priv->checkbox_use, FALSE, FALSE, MODEST_MARGIN_HALF); + 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); g_signal_connect (G_OBJECT (priv->checkbox_use), "toggled", @@ -147,29 +160,44 @@ modest_signature_editor_dialog_init (ModestSignatureEditorDialog *self) priv->label = gtk_label_new (""); /* Set in modest_signature_editor_dialog_set_settings(). */ gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.0); - gtk_box_pack_start (GTK_BOX (box), priv->label, FALSE, FALSE, MODEST_MARGIN_HALF); + gtk_misc_set_padding (GTK_MISC (priv->label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE); + gtk_box_pack_start (GTK_BOX (top_box), priv->label, FALSE, FALSE, 0); gtk_widget_show (priv->label); - priv->pannable = hildon_pannable_area_new (); - gtk_box_pack_start (GTK_BOX (box), priv->pannable, TRUE, TRUE, MODEST_MARGIN_HALF); - gtk_widget_show (priv->pannable); - priv->textview = hildon_text_view_new (); - gtk_container_add (GTK_CONTAINER (priv->pannable), priv->textview); 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); + + align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0); + gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0); + gtk_widget_show (align); + gtk_container_add (GTK_CONTAINER (align), top_box); + gtk_widget_show (top_box); + + 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, 320); + gtk_widget_set_size_request (GTK_WIDGET (self), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT); /* When this window is shown, hibernation should not be possible, * 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; } @@ -194,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') @@ -216,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)); @@ -224,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); +} +