1 /* Copyright (c) 2007, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <glib/gi18n-lib.h>
34 #include <gtk/gtkscrolledwindow.h>
35 #include <gtk/gtktextview.h>
36 #include <gtk/gtkimage.h>
37 #include <gtk/gtkbutton.h>
39 #include <modest-text-utils.h>
40 #include <modest-recpt-editor.h>
42 static GObjectClass *parent_class = NULL;
49 typedef struct _ModestRecptEditorPrivate ModestRecptEditorPrivate;
51 struct _ModestRecptEditorPrivate
54 GtkWidget *abook_button;
55 GtkWidget *scrolled_window;
59 #define MODEST_RECPT_EDITOR_GET_PRIVATE(o) \
60 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_RECPT_EDITOR, ModestRecptEditorPrivate))
62 /* static guint signals[LAST_SIGNAL] = {0}; */
64 /* static functions: GObject */
65 static void modest_recpt_editor_instance_init (GTypeInstance *instance, gpointer g_class);
66 static void modest_recpt_editor_finalize (GObject *object);
67 static void modest_recpt_editor_class_init (ModestRecptEditorClass *klass);
70 * modest_recpt_editor_new:
72 * Return value: a new #ModestRecptEditor instance implemented for Gtk+
75 modest_recpt_editor_new (void)
77 ModestRecptEditor *self = g_object_new (MODEST_TYPE_RECPT_EDITOR,
82 return GTK_WIDGET (self);
86 modest_recpt_editor_set_recipients (ModestRecptEditor *recpt_editor, const gchar *recipients)
88 ModestRecptEditorPrivate *priv;
89 GtkTextBuffer *buffer = NULL;
91 g_return_if_fail (MODEST_IS_RECPT_EDITOR (recpt_editor));
92 priv = MODEST_RECPT_EDITOR_GET_PRIVATE (recpt_editor);
94 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view));
96 gtk_text_buffer_set_text (buffer, recipients, -1);
97 if (GTK_WIDGET_REALIZED (recpt_editor))
98 gtk_widget_queue_resize (GTK_WIDGET (recpt_editor));
103 modest_recpt_editor_get_recipients (ModestRecptEditor *recpt_editor)
105 ModestRecptEditorPrivate *priv;
106 GtkTextBuffer *buffer = NULL;
107 GtkTextIter start, end;
109 g_return_val_if_fail (MODEST_IS_RECPT_EDITOR (recpt_editor), NULL);
110 priv = MODEST_RECPT_EDITOR_GET_PRIVATE (recpt_editor);
112 if (priv->recipients != NULL) {
113 g_free (priv->recipients);
114 priv->recipients = NULL;
117 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view));
119 gtk_text_buffer_get_start_iter (buffer, &start);
120 gtk_text_buffer_get_end_iter (buffer, &end);
122 priv->recipients = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
124 return priv->recipients;
129 modest_recpt_editor_instance_init (GTypeInstance *instance, gpointer g_class)
131 ModestRecptEditorPrivate *priv;
132 GtkWidget *abook_icon;
134 priv = MODEST_RECPT_EDITOR_GET_PRIVATE (instance);
136 priv->abook_button = gtk_button_new ();
137 gtk_button_set_relief (GTK_BUTTON (priv->abook_button), GTK_RELIEF_NONE);
138 gtk_button_set_focus_on_click (GTK_BUTTON (priv->abook_button), FALSE);
139 gtk_button_set_alignment (GTK_BUTTON (priv->abook_button), 1.0, 1.0);
140 abook_icon = gtk_image_new_from_icon_name ("qgn_list_gene_contacts", GTK_ICON_SIZE_BUTTON);
141 gtk_container_add (GTK_CONTAINER (priv->abook_button), abook_icon);
143 priv->text_view = gtk_text_view_new ();
144 priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
145 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
146 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window), GTK_SHADOW_IN);
147 gtk_container_add (GTK_CONTAINER (priv->scrolled_window), priv->text_view);
149 gtk_box_pack_start (GTK_BOX (instance), priv->scrolled_window, TRUE, TRUE, 0);
150 gtk_box_pack_end (GTK_BOX (instance), priv->abook_button, FALSE, FALSE, 0);
152 gtk_text_view_set_accepts_tab (GTK_TEXT_VIEW (priv->text_view), FALSE);
153 gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (priv->text_view), TRUE);
154 gtk_text_view_set_editable (GTK_TEXT_VIEW (priv->text_view), TRUE);
155 gtk_text_view_set_justification (GTK_TEXT_VIEW (priv->text_view), GTK_JUSTIFY_LEFT);
156 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (priv->text_view), GTK_WRAP_WORD_CHAR);
162 modest_recpt_editor_set_field_size_group (ModestRecptEditor *recpt_editor, GtkSizeGroup *size_group)
164 ModestRecptEditorPrivate *priv;
166 g_return_if_fail (MODEST_IS_RECPT_EDITOR (recpt_editor));
167 g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
168 priv = MODEST_RECPT_EDITOR_GET_PRIVATE (recpt_editor);
170 gtk_size_group_add_widget (size_group, priv->scrolled_window);
174 modest_recpt_editor_finalize (GObject *object)
176 (*parent_class->finalize) (object);
182 modest_recpt_editor_class_init (ModestRecptEditorClass *klass)
184 GObjectClass *object_class;
185 GtkWidgetClass *widget_class;
187 parent_class = g_type_class_peek_parent (klass);
188 object_class = (GObjectClass*) klass;
189 widget_class = GTK_WIDGET_CLASS (klass);
191 object_class->finalize = modest_recpt_editor_finalize;
193 g_type_class_add_private (object_class, sizeof (ModestRecptEditorPrivate));
199 modest_recpt_editor_get_type (void)
201 static GType type = 0;
203 if (G_UNLIKELY(type == 0))
205 static const GTypeInfo info =
207 sizeof (ModestRecptEditorClass),
208 NULL, /* base_init */
209 NULL, /* base_finalize */
210 (GClassInitFunc) modest_recpt_editor_class_init, /* class_init */
211 NULL, /* class_finalize */
212 NULL, /* class_data */
213 sizeof (ModestRecptEditor),
215 modest_recpt_editor_instance_init /* instance_init */
218 type = g_type_register_static (GTK_TYPE_HBOX,