1 /* Copyright (c) 2006, 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.
30 #include <widgets/modest-mozembed-mime-part-view.h>
32 #include <tny-stream.h>
33 #include <tny-mime-part-view.h>
34 #include <tny-gtk-text-buffer-stream.h>
35 #include <tny-moz-embed-html-mime-part-view.h>
36 #include <modest-text-utils.h>
37 #include <widgets/modest-mime-part-view.h>
38 #include <widgets/modest-zoomable.h>
40 /* gobject structure methods */
41 static void modest_mozembed_mime_part_view_class_init (ModestMozembedMimePartViewClass *klass);
42 static void modest_mime_part_view_init (gpointer g, gpointer iface_data);
43 static void modest_zoomable_init (gpointer g, gpointer iface_data);
44 static void modest_isearch_view_init (gpointer g, gpointer iface_data);
45 static void modest_mozembed_mime_part_view_init (ModestMozembedMimePartView *self);
46 static void modest_mozembed_mime_part_view_finalize (GObject *self);
48 /* ModestMimePartView implementation */
49 static gboolean modest_mozembed_mime_part_view_is_empty (ModestMimePartView *self);
50 static gboolean modest_mozembed_mime_part_view_is_empty_default (ModestMimePartView *self);
51 /* ModestZoomable implementation */
52 static gdouble modest_mozembed_mime_part_view_get_zoom (ModestZoomable *self);
53 static void modest_mozembed_mime_part_view_set_zoom (ModestZoomable *self, gdouble value);
54 static gboolean modest_mozembed_mime_part_view_zoom_minus (ModestZoomable *self);
55 static gboolean modest_mozembed_mime_part_view_zoom_plus (ModestZoomable *self);
56 static gdouble modest_mozembed_mime_part_view_get_zoom_default (ModestZoomable *self);
57 static void modest_mozembed_mime_part_view_set_zoom_default (ModestZoomable *self, gdouble value);
58 static gboolean modest_mozembed_mime_part_view_zoom_minus_default (ModestZoomable *self);
59 static gboolean modest_mozembed_mime_part_view_zoom_plus_default (ModestZoomable *self);
60 /* ModestISearchView implementation */
61 static gboolean modest_mozembed_mime_part_view_search (ModestISearchView *self, const gchar *string);
62 static gboolean modest_mozembed_mime_part_view_search_next (ModestISearchView *self);
63 static gboolean modest_mozembed_mime_part_view_get_selection_area (ModestISearchView *self, gint *x, gint *y,
64 gint *width, gint *height);
65 static gboolean modest_mozembed_mime_part_view_search_default (ModestISearchView *self, const gchar *string);
66 static gboolean modest_mozembed_mime_part_view_search_next_default (ModestISearchView *self);
67 static gboolean modest_mozembed_mime_part_view_get_selection_area_default (ModestISearchView *self, gint *x, gint *y,
68 gint *width, gint *height);
72 static gboolean is_empty (ModestMozembedMimePartView *self);
73 static void set_zoom (ModestMozembedMimePartView *self, gdouble zoom);
74 static gdouble get_zoom (ModestMozembedMimePartView *self);
75 static gboolean search (ModestMozembedMimePartView *self, const gchar *string);
76 static gboolean search_next (ModestMozembedMimePartView *self);
77 static gboolean get_selection_area (ModestMozembedMimePartView *self, gint *x, gint *y,
78 gint *width, gint *height);
80 typedef struct _ModestMozembedMimePartViewPrivate ModestMozembedMimePartViewPrivate;
81 struct _ModestMozembedMimePartViewPrivate {
86 #define MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
87 MODEST_TYPE_MOZEMBED_MIME_PART_VIEW, \
88 ModestMozembedMimePartViewPrivate))
90 static GtkMozEmbedClass *parent_class = NULL;
93 modest_mozembed_mime_part_view_new ()
95 return g_object_new (MODEST_TYPE_MOZEMBED_MIME_PART_VIEW, NULL);
98 /* GOBJECT IMPLEMENTATION */
100 modest_mozembed_mime_part_view_get_type (void)
102 static GType my_type = 0;
104 static const GTypeInfo my_info = {
105 sizeof(ModestMozembedMimePartViewClass),
106 NULL, /* base init */
107 NULL, /* base finalize */
108 (GClassInitFunc) modest_mozembed_mime_part_view_class_init,
109 NULL, /* class finalize */
110 NULL, /* class data */
111 sizeof(ModestMozembedMimePartView),
113 (GInstanceInitFunc) modest_mozembed_mime_part_view_init,
117 static const GInterfaceInfo modest_mime_part_view_info =
119 (GInterfaceInitFunc) modest_mime_part_view_init, /* interface_init */
120 NULL, /* interface_finalize */
121 NULL /* interface_data */
124 static const GInterfaceInfo modest_zoomable_info =
126 (GInterfaceInitFunc) modest_zoomable_init, /* interface_init */
127 NULL, /* interface_finalize */
128 NULL /* interface_data */
131 static const GInterfaceInfo modest_isearch_view_info =
133 (GInterfaceInitFunc) modest_isearch_view_init, /* interface_init */
134 NULL, /* interface_finalize */
135 NULL /* interface_data */
138 my_type = g_type_register_static (TNY_TYPE_MOZ_EMBED_HTML_MIME_PART_VIEW,
139 "ModestMozembedMimePartView",
142 g_type_add_interface_static (my_type, MODEST_TYPE_MIME_PART_VIEW,
143 &modest_mime_part_view_info);
145 g_type_add_interface_static (my_type, MODEST_TYPE_ZOOMABLE,
146 &modest_zoomable_info);
147 g_type_add_interface_static (my_type, MODEST_TYPE_ISEARCH_VIEW,
148 &modest_isearch_view_info);
154 modest_mozembed_mime_part_view_class_init (ModestMozembedMimePartViewClass *klass)
156 GObjectClass *gobject_class;
157 gobject_class = (GObjectClass*) klass;
159 parent_class = g_type_class_peek_parent (klass);
160 gobject_class->finalize = modest_mozembed_mime_part_view_finalize;
161 klass->is_empty_func = modest_mozembed_mime_part_view_is_empty_default;
162 klass->get_zoom_func = modest_mozembed_mime_part_view_get_zoom_default;
163 klass->set_zoom_func = modest_mozembed_mime_part_view_set_zoom_default;
164 klass->zoom_minus_func = modest_mozembed_mime_part_view_zoom_minus_default;
165 klass->zoom_plus_func = modest_mozembed_mime_part_view_zoom_plus_default;
166 klass->search_func = modest_mozembed_mime_part_view_search_default;
167 klass->search_next_func = modest_mozembed_mime_part_view_search_next_default;
168 klass->get_selection_area_func = modest_mozembed_mime_part_view_get_selection_area_default;
170 g_type_class_add_private (gobject_class, sizeof(ModestMozembedMimePartViewPrivate));
175 modest_mozembed_mime_part_view_init (ModestMozembedMimePartView *self)
177 ModestMozembedMimePartViewPrivate *priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (self);
179 priv->current_zoom = 1.0;
180 priv->last_search = NULL;
185 modest_mozembed_mime_part_view_finalize (GObject *obj)
187 ModestMozembedMimePartViewPrivate *priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (obj);
189 g_free (priv->last_search);
190 priv->last_search = NULL;
192 G_OBJECT_CLASS (parent_class)->finalize (obj);
198 is_empty (ModestMozembedMimePartView *self)
200 /* TODO: not implemented yet */
205 set_zoom (ModestMozembedMimePartView *self, gdouble zoom)
207 ModestMozembedMimePartViewPrivate *priv;
209 g_return_if_fail (MODEST_IS_MOZEMBED_MIME_PART_VIEW (self));
211 priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (self);
212 priv->current_zoom = zoom;
213 gtk_moz_embed_set_zoom_level (GTK_MOZ_EMBED(self), (gint) (zoom*100), NULL);
215 gtk_widget_queue_resize (GTK_WIDGET (self));
219 get_zoom (ModestMozembedMimePartView *self)
221 ModestMozembedMimePartViewPrivate *priv;
223 g_return_val_if_fail (MODEST_IS_MOZEMBED_MIME_PART_VIEW (self), 1.0);
225 priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (self);
227 return priv->current_zoom;
231 search (ModestMozembedMimePartView *self,
234 ModestMozembedMimePartViewPrivate *priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (self);
235 if (priv->last_search != NULL) {
236 g_free (priv->last_search);
238 priv->last_search = g_strdup (string);
240 return gtk_moz_embed_find_text (GTK_MOZ_EMBED (self), string, FALSE, FALSE,
245 search_next (ModestMozembedMimePartView *self)
247 ModestMozembedMimePartViewPrivate *priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (self);
248 return gtk_moz_embed_find_text (GTK_MOZ_EMBED (self), priv->last_search, FALSE, FALSE,
253 get_selection_area (ModestMozembedMimePartView *self,
255 gint *width, gint *height)
257 /* TODO: Implement incremental search */
263 /* MODEST MIME PART VIEW IMPLEMENTATION */
266 modest_mime_part_view_init (gpointer g, gpointer iface_data)
268 ModestMimePartViewIface *klass = (ModestMimePartViewIface *)g;
270 klass->is_empty_func = modest_mozembed_mime_part_view_is_empty;
276 modest_mozembed_mime_part_view_is_empty (ModestMimePartView *self)
278 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->is_empty_func (self);
282 modest_mozembed_mime_part_view_is_empty_default (ModestMimePartView *self)
284 return is_empty (MODEST_MOZEMBED_MIME_PART_VIEW (self));
288 /* MODEST ZOOMABLE IMPLEMENTATION */
290 modest_zoomable_init (gpointer g, gpointer iface_data)
292 ModestZoomableIface *klass = (ModestZoomableIface *)g;
294 klass->get_zoom_func = modest_mozembed_mime_part_view_get_zoom;
295 klass->set_zoom_func = modest_mozembed_mime_part_view_set_zoom;
296 klass->zoom_minus_func = modest_mozembed_mime_part_view_zoom_minus;
297 klass->zoom_plus_func = modest_mozembed_mime_part_view_zoom_plus;
303 modest_mozembed_mime_part_view_get_zoom (ModestZoomable *self)
305 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->get_zoom_func (self);
309 modest_mozembed_mime_part_view_get_zoom_default (ModestZoomable *self)
311 return get_zoom (MODEST_MOZEMBED_MIME_PART_VIEW (self));
315 modest_mozembed_mime_part_view_set_zoom (ModestZoomable *self, gdouble value)
317 MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->set_zoom_func (self, value);
321 modest_mozembed_mime_part_view_set_zoom_default (ModestZoomable *self, gdouble value)
323 set_zoom (MODEST_MOZEMBED_MIME_PART_VIEW (self), value);
327 modest_mozembed_mime_part_view_zoom_minus (ModestZoomable *self)
329 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->zoom_minus_func (self);
333 modest_mozembed_mime_part_view_zoom_minus_default (ModestZoomable *self)
335 /* operation not supported in ModestMozembedMimePartView */
340 modest_mozembed_mime_part_view_zoom_plus (ModestZoomable *self)
342 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->zoom_plus_func (self);
346 modest_mozembed_mime_part_view_zoom_plus_default (ModestZoomable *self)
348 /* operation not supported in ModestMozembedMimePartView */
352 /* ISEARCH VIEW IMPLEMENTATION */
354 modest_isearch_view_init (gpointer g, gpointer iface_data)
356 ModestISearchViewIface *klass = (ModestISearchViewIface *)g;
358 klass->search_func = modest_mozembed_mime_part_view_search;
359 klass->search_next_func = modest_mozembed_mime_part_view_search_next;
360 klass->get_selection_area_func = modest_mozembed_mime_part_view_get_selection_area;
366 modest_mozembed_mime_part_view_search (ModestISearchView *self, const gchar *string)
368 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->search_func (self, string);
372 modest_mozembed_mime_part_view_search_default (ModestISearchView *self, const gchar *string)
374 return search (MODEST_MOZEMBED_MIME_PART_VIEW (self), string);
378 modest_mozembed_mime_part_view_search_next(ModestISearchView *self)
380 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->search_next_func (self);
384 modest_mozembed_mime_part_view_search_next_default (ModestISearchView *self)
386 return search_next (MODEST_MOZEMBED_MIME_PART_VIEW (self));
390 modest_mozembed_mime_part_view_get_selection_area (ModestISearchView *self, gint *x, gint *y,
391 gint *width, gint *height)
393 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->get_selection_area_func (self, x, y, width, height);
397 modest_mozembed_mime_part_view_get_selection_area_default (ModestISearchView *self, gint *x, gint *y,
398 gint *width, gint *height)
400 return get_selection_area (MODEST_MOZEMBED_MIME_PART_VIEW (self), x, y, width, height);