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.
31 #include <gtkmozembed_glue.cpp>
34 #include <widgets/modest-mozembed-mime-part-view.h>
36 #include <tny-stream.h>
37 #include <tny-mime-part-view.h>
38 #include <tny-gtk-text-buffer-stream.h>
39 #include <tny-moz-embed-html-mime-part-view.h>
40 #include <modest-text-utils.h>
41 #include <widgets/modest-mime-part-view.h>
42 #include <widgets/modest-zoomable.h>
44 /* gobject structure methods */
45 static void modest_mozembed_mime_part_view_class_init (ModestMozembedMimePartViewClass *klass);
46 static void modest_mime_part_view_init (gpointer g, gpointer iface_data);
47 static void modest_zoomable_init (gpointer g, gpointer iface_data);
48 static void modest_isearch_view_init (gpointer g, gpointer iface_data);
49 static void modest_mozembed_mime_part_view_init (ModestMozembedMimePartView *self);
50 static void modest_mozembed_mime_part_view_finalize (GObject *self);
52 /* ModestMimePartView implementation */
53 static gboolean modest_mozembed_mime_part_view_is_empty (ModestMimePartView *self);
54 static gboolean modest_mozembed_mime_part_view_is_empty_default (ModestMimePartView *self);
55 /* ModestZoomable implementation */
56 static gdouble modest_mozembed_mime_part_view_get_zoom (ModestZoomable *self);
57 static void modest_mozembed_mime_part_view_set_zoom (ModestZoomable *self, gdouble value);
58 static gboolean modest_mozembed_mime_part_view_zoom_minus (ModestZoomable *self);
59 static gboolean modest_mozembed_mime_part_view_zoom_plus (ModestZoomable *self);
60 static gdouble modest_mozembed_mime_part_view_get_zoom_default (ModestZoomable *self);
61 static void modest_mozembed_mime_part_view_set_zoom_default (ModestZoomable *self, gdouble value);
62 static gboolean modest_mozembed_mime_part_view_zoom_minus_default (ModestZoomable *self);
63 static gboolean modest_mozembed_mime_part_view_zoom_plus_default (ModestZoomable *self);
64 /* ModestISearchView implementation */
65 static gboolean modest_mozembed_mime_part_view_search (ModestISearchView *self, const gchar *string);
66 static gboolean modest_mozembed_mime_part_view_search_next (ModestISearchView *self);
67 static gboolean modest_mozembed_mime_part_view_get_selection_area (ModestISearchView *self, gint *x, gint *y,
68 gint *width, gint *height);
69 static gboolean modest_mozembed_mime_part_view_search_default (ModestISearchView *self, const gchar *string);
70 static gboolean modest_mozembed_mime_part_view_search_next_default (ModestISearchView *self);
71 static gboolean modest_mozembed_mime_part_view_get_selection_area_default (ModestISearchView *self, gint *x, gint *y,
72 gint *width, gint *height);
76 static gboolean is_empty (ModestMozembedMimePartView *self);
77 static void set_zoom (ModestMozembedMimePartView *self, gdouble zoom);
78 static gdouble get_zoom (ModestMozembedMimePartView *self);
79 static gboolean search (ModestMozembedMimePartView *self, const gchar *string);
80 static gboolean search_next (ModestMozembedMimePartView *self);
81 static gboolean get_selection_area (ModestMozembedMimePartView *self, gint *x, gint *y,
82 gint *width, gint *height);
84 typedef struct _ModestMozembedMimePartViewPrivate ModestMozembedMimePartViewPrivate;
85 struct _ModestMozembedMimePartViewPrivate {
90 #define MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
91 MODEST_TYPE_MOZEMBED_MIME_PART_VIEW, \
92 ModestMozembedMimePartViewPrivate))
94 static GtkMozEmbedClass *parent_class = NULL;
97 modest_mozembed_mime_part_view_new ()
99 return GTK_WIDGET(g_object_new (MODEST_TYPE_MOZEMBED_MIME_PART_VIEW, NULL));
102 /* GOBJECT IMPLEMENTATION */
104 modest_mozembed_mime_part_view_get_type (void)
106 static GType my_type = 0;
108 static const GTypeInfo my_info = {
109 sizeof(ModestMozembedMimePartViewClass),
110 NULL, /* base init */
111 NULL, /* base finalize */
112 (GClassInitFunc) modest_mozembed_mime_part_view_class_init,
113 NULL, /* class finalize */
114 NULL, /* class data */
115 sizeof(ModestMozembedMimePartView),
117 (GInstanceInitFunc) modest_mozembed_mime_part_view_init,
121 static const GInterfaceInfo modest_mime_part_view_info =
123 (GInterfaceInitFunc) modest_mime_part_view_init, /* interface_init */
124 NULL, /* interface_finalize */
125 NULL /* interface_data */
128 static const GInterfaceInfo modest_zoomable_info =
130 (GInterfaceInitFunc) modest_zoomable_init, /* interface_init */
131 NULL, /* interface_finalize */
132 NULL /* interface_data */
135 static const GInterfaceInfo modest_isearch_view_info =
137 (GInterfaceInitFunc) modest_isearch_view_init, /* interface_init */
138 NULL, /* interface_finalize */
139 NULL /* interface_data */
142 my_type = g_type_register_static (TNY_TYPE_MOZ_EMBED_HTML_MIME_PART_VIEW,
143 "ModestMozembedMimePartView",
144 &my_info, GTypeFlags(0));
146 g_type_add_interface_static (my_type, MODEST_TYPE_MIME_PART_VIEW,
147 &modest_mime_part_view_info);
149 g_type_add_interface_static (my_type, MODEST_TYPE_ZOOMABLE,
150 &modest_zoomable_info);
151 g_type_add_interface_static (my_type, MODEST_TYPE_ISEARCH_VIEW,
152 &modest_isearch_view_info);
158 modest_mozembed_mime_part_view_class_init (ModestMozembedMimePartViewClass *klass)
160 GObjectClass *gobject_class;
161 gobject_class = (GObjectClass*) klass;
163 parent_class = (GtkMozEmbedClass*) g_type_class_peek_parent (klass);
164 gobject_class->finalize = modest_mozembed_mime_part_view_finalize;
165 klass->is_empty_func = modest_mozembed_mime_part_view_is_empty_default;
166 klass->get_zoom_func = modest_mozembed_mime_part_view_get_zoom_default;
167 klass->set_zoom_func = modest_mozembed_mime_part_view_set_zoom_default;
168 klass->zoom_minus_func = modest_mozembed_mime_part_view_zoom_minus_default;
169 klass->zoom_plus_func = modest_mozembed_mime_part_view_zoom_plus_default;
170 klass->search_func = modest_mozembed_mime_part_view_search_default;
171 klass->search_next_func = modest_mozembed_mime_part_view_search_next_default;
172 klass->get_selection_area_func = modest_mozembed_mime_part_view_get_selection_area_default;
174 g_type_class_add_private (gobject_class, sizeof(ModestMozembedMimePartViewPrivate));
179 modest_mozembed_mime_part_view_init (ModestMozembedMimePartView *self)
181 ModestMozembedMimePartViewPrivate *priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (self);
183 priv->current_zoom = 1.0;
184 priv->last_search = NULL;
189 modest_mozembed_mime_part_view_finalize (GObject *obj)
191 ModestMozembedMimePartViewPrivate *priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (obj);
193 g_free (priv->last_search);
194 priv->last_search = NULL;
196 G_OBJECT_CLASS (parent_class)->finalize (obj);
202 is_empty (ModestMozembedMimePartView *self)
204 /* TODO: not implemented yet */
209 set_zoom (ModestMozembedMimePartView *self, gdouble zoom)
211 ModestMozembedMimePartViewPrivate *priv;
213 g_return_if_fail (MODEST_IS_MOZEMBED_MIME_PART_VIEW (self));
215 priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (self);
216 priv->current_zoom = zoom;
217 gtk_moz_embed_set_zoom_level (GTK_MOZ_EMBED(self), (gint) (zoom*100), NULL);
219 gtk_widget_queue_resize (GTK_WIDGET (self));
223 get_zoom (ModestMozembedMimePartView *self)
225 ModestMozembedMimePartViewPrivate *priv;
227 g_return_val_if_fail (MODEST_IS_MOZEMBED_MIME_PART_VIEW (self), 1.0);
229 priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (self);
231 return priv->current_zoom;
235 search (ModestMozembedMimePartView *self,
238 ModestMozembedMimePartViewPrivate *priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (self);
239 if (priv->last_search != NULL) {
240 g_free (priv->last_search);
242 priv->last_search = g_strdup (string);
244 return gtk_moz_embed_find_text (GTK_MOZ_EMBED (self), string, FALSE, FALSE,
249 search_next (ModestMozembedMimePartView *self)
251 ModestMozembedMimePartViewPrivate *priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (self);
252 return gtk_moz_embed_find_text (GTK_MOZ_EMBED (self), priv->last_search, FALSE, FALSE,
257 get_selection_area (ModestMozembedMimePartView *self,
259 gint *width, gint *height)
261 /* TODO: Implement incremental search */
267 /* MODEST MIME PART VIEW IMPLEMENTATION */
270 modest_mime_part_view_init (gpointer g, gpointer iface_data)
272 ModestMimePartViewIface *klass = (ModestMimePartViewIface *)g;
274 klass->is_empty_func = modest_mozembed_mime_part_view_is_empty;
280 modest_mozembed_mime_part_view_is_empty (ModestMimePartView *self)
282 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->is_empty_func (self);
286 modest_mozembed_mime_part_view_is_empty_default (ModestMimePartView *self)
288 return is_empty (MODEST_MOZEMBED_MIME_PART_VIEW (self));
292 /* MODEST ZOOMABLE IMPLEMENTATION */
294 modest_zoomable_init (gpointer g, gpointer iface_data)
296 ModestZoomableIface *klass = (ModestZoomableIface *)g;
298 klass->get_zoom_func = modest_mozembed_mime_part_view_get_zoom;
299 klass->set_zoom_func = modest_mozembed_mime_part_view_set_zoom;
300 klass->zoom_minus_func = modest_mozembed_mime_part_view_zoom_minus;
301 klass->zoom_plus_func = modest_mozembed_mime_part_view_zoom_plus;
307 modest_mozembed_mime_part_view_get_zoom (ModestZoomable *self)
309 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->get_zoom_func (self);
313 modest_mozembed_mime_part_view_get_zoom_default (ModestZoomable *self)
315 return get_zoom (MODEST_MOZEMBED_MIME_PART_VIEW (self));
319 modest_mozembed_mime_part_view_set_zoom (ModestZoomable *self, gdouble value)
321 MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->set_zoom_func (self, value);
325 modest_mozembed_mime_part_view_set_zoom_default (ModestZoomable *self, gdouble value)
327 set_zoom (MODEST_MOZEMBED_MIME_PART_VIEW (self), value);
331 modest_mozembed_mime_part_view_zoom_minus (ModestZoomable *self)
333 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->zoom_minus_func (self);
337 modest_mozembed_mime_part_view_zoom_minus_default (ModestZoomable *self)
339 /* operation not supported in ModestMozembedMimePartView */
344 modest_mozembed_mime_part_view_zoom_plus (ModestZoomable *self)
346 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->zoom_plus_func (self);
350 modest_mozembed_mime_part_view_zoom_plus_default (ModestZoomable *self)
352 /* operation not supported in ModestMozembedMimePartView */
356 /* ISEARCH VIEW IMPLEMENTATION */
358 modest_isearch_view_init (gpointer g, gpointer iface_data)
360 ModestISearchViewIface *klass = (ModestISearchViewIface *)g;
362 klass->search_func = modest_mozembed_mime_part_view_search;
363 klass->search_next_func = modest_mozembed_mime_part_view_search_next;
364 klass->get_selection_area_func = modest_mozembed_mime_part_view_get_selection_area;
370 modest_mozembed_mime_part_view_search (ModestISearchView *self, const gchar *string)
372 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->search_func (self, string);
376 modest_mozembed_mime_part_view_search_default (ModestISearchView *self, const gchar *string)
378 return search (MODEST_MOZEMBED_MIME_PART_VIEW (self), string);
382 modest_mozembed_mime_part_view_search_next(ModestISearchView *self)
384 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->search_next_func (self);
388 modest_mozembed_mime_part_view_search_next_default (ModestISearchView *self)
390 return search_next (MODEST_MOZEMBED_MIME_PART_VIEW (self));
394 modest_mozembed_mime_part_view_get_selection_area (ModestISearchView *self, gint *x, gint *y,
395 gint *width, gint *height)
397 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->get_selection_area_func (self, x, y, width, height);
401 modest_mozembed_mime_part_view_get_selection_area_default (ModestISearchView *self, gint *x, gint *y,
402 gint *width, gint *height)
404 return get_selection_area (MODEST_MOZEMBED_MIME_PART_VIEW (self), x, y, width, height);