summaryrefslogtreecommitdiff
path: root/plugins/NewStory/src/webpage.cpp
blob: f4b9be0c99f44a891f19caf4f62045cd9d58f696 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
Copyright (c) 2005 Victor Pavlychko (nullbyte@sotline.net.ua)
Copyright (C) 2012-24 Miranda NG team (https://miranda-ng.org)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "stdafx.h"
#include "TxDIB.h"

/////////////////////////////////////////////////////////////////////////////////////////
// Litehtml interface

CRITICAL_SECTION cairo_font::m_sync;

cairo_surface_t *dib_to_surface(CTxDIB &img)
{
	cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, img.getWidth(), img.getHeight());
	unsigned char *dst = cairo_image_surface_get_data(surface);
	unsigned char *src = (unsigned char *)img.getBits();
	int line_size = img.getWidth() * 4;
	int dst_offset = img.getWidth() * (img.getHeight() - 1) * 4;
	int src_offset = 0;
	for (int i = 0; i < img.getHeight(); i++, src_offset += line_size, dst_offset -= line_size) {
		memcpy(dst + dst_offset, src + src_offset, line_size);
	}
	cairo_surface_mark_dirty(surface);
	return surface;
}

litehtml::string NSWebPage::resolve_color(const litehtml::string &color) const
{
	char buf[20];

	if (color == "NSText") {
		mir_snprintf(buf, "#%02X%02X%02X", GetRValue(clText), GetGValue(clText), GetBValue(clText));
		return buf;
	}

	return windows_container::resolve_color(color);
}

void NSWebPage::on_image_loaded(const wchar_t *file, const wchar_t *url, bool redraw_only)
{
	if (!mir_wstrncmp(file, L"file://", 7))
		file += 7;

	CTxDIB img;
	if (img.load(file)) {
		cairo_surface_t *surface = dib_to_surface(img);
		m_images.add_image(T2Utf(url).get(), surface);

		PostMessage(ctrl.m_hwnd, NSM_IMAGE_LOADED, redraw_only, 0);
	}
}

////////////////////////////////////////////////////////////////////////////////

cairo_surface_t* NSWebPage::get_image(const std::string &url)
{
	return m_images.get_image(url);
}

void NSWebPage::get_client_rect(litehtml::position &pos) const
{
	pos = litehtml::size(ctrl.cachedWindowWidth, ctrl.cachedWindowHeight);

}

void NSWebPage::import_css(litehtml::string &, const litehtml::string &, litehtml::string &)
{
}

void NSWebPage::load_image(const char *src, const char */*baseUrl*/, bool redraw_on_ready)
{
	Utf2T wszUrl(src);
	if (m_images.reserve(src))
		on_image_loaded(wszUrl, wszUrl, redraw_on_ready);
}

void NSWebPage::on_anchor_click(const char *pszUtl, const litehtml::element::ptr &)
{
	Utils_OpenUrl(pszUtl);
}

void NSWebPage::set_base_url(const char *)
{
}

void NSWebPage::set_caption(const char *)
{
}

void NSWebPage::set_clip(const litehtml::position &, const litehtml::border_radiuses &)
{
}

void NSWebPage::set_cursor(const char *pszCursor)
{
	if (!mir_strcmp(pszCursor, "pointer"))
		SetCursor(LoadCursor(NULL, IDC_HAND));
	else
		SetCursor(LoadCursor(NULL, IDC_ARROW));
}