1 /*
2  * Claws Mail -- A GTK+ based, lightweight, and fast e-mail client
3  * Copyright(C) 2019 the Claws Mail Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write tothe Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16  */
17 
18 #include <gtk/gtk.h>
19 #include <glib.h>
20 #include <gio/gio.h>
21 
22 #include "procmime.h"
23 
24 #include "container_linux.h"
25 
26 struct pango_font
27 {
28 	PangoFontDescription *font;
29 	bool underline;
30 	bool strikethrough;
31 };
32 
33 class lh_widget : public container_linux
34 {
35 	public:
36 		lh_widget();
37 		~lh_widget();
38 
39 		GtkWidget *get_widget() const;
40 
41 		/* Methods that litehtml calls */
42 		void set_caption(const litehtml::tchar_t* caption);
43 		void set_base_url(const litehtml::tchar_t* base_url);
44 		void on_anchor_click(const litehtml::tchar_t* url, const litehtml::element::ptr& el);
45 		void set_cursor(const litehtml::tchar_t* cursor);
46 		void import_css(litehtml::tstring& text, const litehtml::tstring& url, litehtml::tstring& baseurl);
47 		void get_client_rect(litehtml::position& client) const;
get_default_font_name()48 		inline const litehtml::tchar_t *get_default_font_name() const { return m_font_name; };
49 
get_default_font_size()50 		inline int get_default_font_size() const { return m_font_size; };
51 		litehtml::uint_ptr create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm);
52 		void delete_font(litehtml::uint_ptr hFont);
53 		int text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont);
54 		void draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos);
55 
56 		void draw(cairo_t *cr);
57 		void redraw(gboolean force_render);
58 		void open_html(const gchar *contents);
59 		void clear();
60 		void update_cursor(const litehtml::tchar_t* cursor);
61 		void update_font();
62 		void print();
63 
64 		const litehtml::tchar_t *get_href_at(litehtml::element::ptr element) const;
65 		const litehtml::tchar_t *get_href_at(const gint x, const gint y) const;
66 		void popup_context_menu(const litehtml::tchar_t *url, GdkEventButton *event);
67 		const litehtml::tstring fullurl(const litehtml::tchar_t *url) const;
68 
69 		void set_partinfo(MimeInfo *partinfo);
70 		GdkPixbuf *get_local_image(const litehtml::tstring url) const;
71 
72 		litehtml::document::ptr m_html;
73 		litehtml::tstring m_clicked_url;
74 		litehtml::tstring m_base_url;
75 
76 	private:
77 		void paint_white();
78 
79 		gint m_rendered_width;
80 		GtkWidget *m_drawing_area;
81 		GtkWidget *m_scrolled_window;
82 		GtkWidget *m_viewport;
83 		GtkWidget *m_context_menu;
84 		litehtml::context m_context;
85 		gint m_height;
86 		litehtml::element::ptr m_over_element;
87 		gboolean m_showing_url;
88 		MimeInfo *m_partinfo;
89 
90 		litehtml::tchar_t *m_font_name;
91 		int m_font_size;
92 };
93