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 {
85 #define MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
86 MODEST_TYPE_MOZEMBED_MIME_PART_VIEW, \
87 ModestMozembedMimePartViewPrivate))
89 static GtkMozEmbedClass *parent_class = NULL;
92 modest_mozembed_mime_part_view_new ()
94 return g_object_new (MODEST_TYPE_MOZEMBED_MIME_PART_VIEW, NULL);
97 /* GOBJECT IMPLEMENTATION */
99 modest_mozembed_mime_part_view_get_type (void)
101 static GType my_type = 0;
103 static const GTypeInfo my_info = {
104 sizeof(ModestMozembedMimePartViewClass),
105 NULL, /* base init */
106 NULL, /* base finalize */
107 (GClassInitFunc) modest_mozembed_mime_part_view_class_init,
108 NULL, /* class finalize */
109 NULL, /* class data */
110 sizeof(ModestMozembedMimePartView),
112 (GInstanceInitFunc) modest_mozembed_mime_part_view_init,
116 static const GInterfaceInfo modest_mime_part_view_info =
118 (GInterfaceInitFunc) modest_mime_part_view_init, /* interface_init */
119 NULL, /* interface_finalize */
120 NULL /* interface_data */
123 static const GInterfaceInfo modest_zoomable_info =
125 (GInterfaceInitFunc) modest_zoomable_init, /* interface_init */
126 NULL, /* interface_finalize */
127 NULL /* interface_data */
130 static const GInterfaceInfo modest_isearch_view_info =
132 (GInterfaceInitFunc) modest_isearch_view_init, /* interface_init */
133 NULL, /* interface_finalize */
134 NULL /* interface_data */
137 my_type = g_type_register_static (TNY_TYPE_MOZ_EMBED_HTML_MIME_PART_VIEW,
138 "ModestMozembedMimePartView",
141 g_type_add_interface_static (my_type, MODEST_TYPE_MIME_PART_VIEW,
142 &modest_mime_part_view_info);
144 g_type_add_interface_static (my_type, MODEST_TYPE_ZOOMABLE,
145 &modest_zoomable_info);
146 g_type_add_interface_static (my_type, MODEST_TYPE_ISEARCH_VIEW,
147 &modest_isearch_view_info);
153 modest_mozembed_mime_part_view_class_init (ModestMozembedMimePartViewClass *klass)
155 GObjectClass *gobject_class;
156 gobject_class = (GObjectClass*) klass;
158 parent_class = g_type_class_peek_parent (klass);
159 gobject_class->finalize = modest_mozembed_mime_part_view_finalize;
160 klass->is_empty_func = modest_mozembed_mime_part_view_is_empty_default;
161 klass->get_zoom_func = modest_mozembed_mime_part_view_get_zoom_default;
162 klass->set_zoom_func = modest_mozembed_mime_part_view_set_zoom_default;
163 klass->zoom_minus_func = modest_mozembed_mime_part_view_zoom_minus_default;
164 klass->zoom_plus_func = modest_mozembed_mime_part_view_zoom_plus_default;
165 klass->search_func = modest_mozembed_mime_part_view_search_default;
166 klass->search_next_func = modest_mozembed_mime_part_view_search_next_default;
167 klass->get_selection_area_func = modest_mozembed_mime_part_view_get_selection_area_default;
169 g_type_class_add_private (gobject_class, sizeof(ModestMozembedMimePartViewPrivate));
174 modest_mozembed_mime_part_view_init (ModestMozembedMimePartView *self)
176 ModestMozembedMimePartViewPrivate *priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (self);
178 priv->current_zoom = 1.0;
183 modest_mozembed_mime_part_view_finalize (GObject *obj)
185 G_OBJECT_CLASS (parent_class)->finalize (obj);
191 is_empty (ModestMozembedMimePartView *self)
193 /* TODO: not implemented yet */
198 set_zoom (ModestMozembedMimePartView *self, gdouble zoom)
200 ModestMozembedMimePartViewPrivate *priv;
202 g_return_if_fail (MODEST_IS_MOZEMBED_MIME_PART_VIEW (self));
204 priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (self);
205 priv->current_zoom = zoom;
206 gtk_moz_embed_set_zoom_level (GTK_MOZ_EMBED(self), (gint) (zoom*100), NULL);
208 gtk_widget_queue_resize (GTK_WIDGET (self));
212 get_zoom (ModestMozembedMimePartView *self)
214 ModestMozembedMimePartViewPrivate *priv;
216 g_return_val_if_fail (MODEST_IS_MOZEMBED_MIME_PART_VIEW (self), 1.0);
218 priv = MODEST_MOZEMBED_MIME_PART_VIEW_GET_PRIVATE (self);
220 return priv->current_zoom;
224 search (ModestMozembedMimePartView *self,
227 /* TODO: Implement incremental search */
232 search_next (ModestMozembedMimePartView *self)
234 /* TODO: Implement incremental search */
239 get_selection_area (ModestMozembedMimePartView *self,
241 gint *width, gint *height)
243 /* TODO: Implement incremental search */
249 /* MODEST MIME PART VIEW IMPLEMENTATION */
252 modest_mime_part_view_init (gpointer g, gpointer iface_data)
254 ModestMimePartViewIface *klass = (ModestMimePartViewIface *)g;
256 klass->is_empty_func = modest_mozembed_mime_part_view_is_empty;
262 modest_mozembed_mime_part_view_is_empty (ModestMimePartView *self)
264 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->is_empty_func (self);
268 modest_mozembed_mime_part_view_is_empty_default (ModestMimePartView *self)
270 return is_empty (MODEST_MOZEMBED_MIME_PART_VIEW (self));
274 /* MODEST ZOOMABLE IMPLEMENTATION */
276 modest_zoomable_init (gpointer g, gpointer iface_data)
278 ModestZoomableIface *klass = (ModestZoomableIface *)g;
280 klass->get_zoom_func = modest_mozembed_mime_part_view_get_zoom;
281 klass->set_zoom_func = modest_mozembed_mime_part_view_set_zoom;
282 klass->zoom_minus_func = modest_mozembed_mime_part_view_zoom_minus;
283 klass->zoom_plus_func = modest_mozembed_mime_part_view_zoom_plus;
289 modest_mozembed_mime_part_view_get_zoom (ModestZoomable *self)
291 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->get_zoom_func (self);
295 modest_mozembed_mime_part_view_get_zoom_default (ModestZoomable *self)
297 return get_zoom (MODEST_MOZEMBED_MIME_PART_VIEW (self));
301 modest_mozembed_mime_part_view_set_zoom (ModestZoomable *self, gdouble value)
303 MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->set_zoom_func (self, value);
307 modest_mozembed_mime_part_view_set_zoom_default (ModestZoomable *self, gdouble value)
309 set_zoom (MODEST_MOZEMBED_MIME_PART_VIEW (self), value);
313 modest_mozembed_mime_part_view_zoom_minus (ModestZoomable *self)
315 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->zoom_minus_func (self);
319 modest_mozembed_mime_part_view_zoom_minus_default (ModestZoomable *self)
321 /* operation not supported in ModestMozembedMimePartView */
326 modest_mozembed_mime_part_view_zoom_plus (ModestZoomable *self)
328 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->zoom_plus_func (self);
332 modest_mozembed_mime_part_view_zoom_plus_default (ModestZoomable *self)
334 /* operation not supported in ModestMozembedMimePartView */
338 /* ISEARCH VIEW IMPLEMENTATION */
340 modest_isearch_view_init (gpointer g, gpointer iface_data)
342 ModestISearchViewIface *klass = (ModestISearchViewIface *)g;
344 klass->search_func = modest_mozembed_mime_part_view_search;
345 klass->search_next_func = modest_mozembed_mime_part_view_search_next;
346 klass->get_selection_area_func = modest_mozembed_mime_part_view_get_selection_area;
352 modest_mozembed_mime_part_view_search (ModestISearchView *self, const gchar *string)
354 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->search_func (self, string);
358 modest_mozembed_mime_part_view_search_default (ModestISearchView *self, const gchar *string)
360 return search (MODEST_MOZEMBED_MIME_PART_VIEW (self), string);
364 modest_mozembed_mime_part_view_search_next(ModestISearchView *self)
366 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->search_next_func (self);
370 modest_mozembed_mime_part_view_search_next_default (ModestISearchView *self)
372 return search_next (MODEST_MOZEMBED_MIME_PART_VIEW (self));
376 modest_mozembed_mime_part_view_get_selection_area (ModestISearchView *self, gint *x, gint *y,
377 gint *width, gint *height)
379 return MODEST_MOZEMBED_MIME_PART_VIEW_GET_CLASS (self)->get_selection_area_func (self, x, y, width, height);
383 modest_mozembed_mime_part_view_get_selection_area_default (ModestISearchView *self, gint *x, gint *y,
384 gint *width, gint *height)
386 return get_selection_area (MODEST_MOZEMBED_MIME_PART_VIEW (self), x, y, width, height);