This commit is contained in:
parent
ae62afb2f0
commit
e2c19d33dc
@ -5,8 +5,9 @@
|
||||
|
||||
cairo_container::cairo_container(void)
|
||||
{
|
||||
m_temp_dib.create(1, 1, true);
|
||||
m_font_link = NULL;
|
||||
m_temp_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 2, 2);
|
||||
m_temp_cr = cairo_create(m_temp_surface);
|
||||
m_font_link = NULL;
|
||||
CoCreateInstance(CLSID_CMultiLanguage, NULL, CLSCTX_ALL, IID_IMLangFontLink2, (void**) &m_font_link);
|
||||
}
|
||||
|
||||
@ -17,6 +18,8 @@ cairo_container::~cairo_container(void)
|
||||
{
|
||||
m_font_link->Release();
|
||||
}
|
||||
cairo_surface_destroy(m_temp_surface);
|
||||
cairo_destroy(m_temp_cr);
|
||||
}
|
||||
|
||||
litehtml::uint_ptr cairo_container::create_font( const wchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm )
|
||||
@ -35,15 +38,17 @@ litehtml::uint_ptr cairo_container::create_font( const wchar_t* faceName, int si
|
||||
|
||||
if(fm)
|
||||
{
|
||||
cairo_dev cr(&m_temp_dib);
|
||||
cairo_save(m_temp_cr);
|
||||
|
||||
cairo_font_metrics cfm;
|
||||
fnt->get_metrics(cr, &cfm);
|
||||
fnt->get_metrics(m_temp_cr, &cfm);
|
||||
|
||||
fm->ascent = cfm.ascent;
|
||||
fm->descent = cfm.descent;
|
||||
fm->height = cfm.height;
|
||||
fm->x_height = cfm.x_height;
|
||||
|
||||
cairo_restore(m_temp_cr);
|
||||
}
|
||||
|
||||
return (litehtml::uint_ptr) fnt;
|
||||
@ -61,15 +66,19 @@ void cairo_container::delete_font( litehtml::uint_ptr hFont )
|
||||
int cairo_container::text_width( const wchar_t* text, litehtml::uint_ptr hFont )
|
||||
{
|
||||
cairo_font* fnt = (cairo_font*) hFont;
|
||||
cairo_dev cr(&m_temp_dib);
|
||||
|
||||
return fnt->text_width(cr, text);
|
||||
|
||||
cairo_save(m_temp_cr);
|
||||
int ret = fnt->text_width(m_temp_cr, text);
|
||||
cairo_restore(m_temp_cr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void cairo_container::draw_text( litehtml::uint_ptr hdc, const wchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos )
|
||||
{
|
||||
cairo_font* fnt = (cairo_font*) hFont;
|
||||
cairo_dev cr(get_dib(hdc));
|
||||
cairo_t* cr = (cairo_t*) hdc;
|
||||
cairo_save(cr);
|
||||
|
||||
apply_clip(cr);
|
||||
|
||||
cairo_font_metrics cfm;
|
||||
@ -78,15 +87,18 @@ void cairo_container::draw_text( litehtml::uint_ptr hdc, const wchar_t* text, li
|
||||
int x = pos.left();
|
||||
int y = pos.bottom() - cfm.descent;
|
||||
|
||||
cr.set_color(color);
|
||||
set_color(cr, color);
|
||||
fnt->show_text(cr, x, y, text);
|
||||
|
||||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
void cairo_container::fill_rect( litehtml::uint_ptr hdc, const litehtml::position& pos, const litehtml::web_color color, const litehtml::css_border_radius& radius )
|
||||
{
|
||||
if(hdc)
|
||||
{
|
||||
cairo_dev cr( get_dib(hdc) );
|
||||
cairo_t* cr = (cairo_t*) hdc;
|
||||
cairo_save(cr);
|
||||
apply_clip(cr);
|
||||
|
||||
if(radius.top_left_x.val())
|
||||
@ -118,8 +130,9 @@ void cairo_container::fill_rect( litehtml::uint_ptr hdc, const litehtml::positio
|
||||
cairo_arc(cr, pos.left() + radius.bottom_left_x.val(), pos.bottom() - radius.bottom_left_x.val(), radius.bottom_left_x.val(), M_PI / 2.0, M_PI);
|
||||
}
|
||||
|
||||
cr.set_color(color);
|
||||
set_color(cr, color);
|
||||
cairo_fill(cr);
|
||||
cairo_restore(cr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,12 +162,12 @@ void cairo_container::draw_list_marker( litehtml::uint_ptr hdc, litehtml::list_s
|
||||
{
|
||||
case litehtml::list_style_type_circle:
|
||||
{
|
||||
draw_ellipse(get_dib(hdc), draw_x, draw_y, draw_width, draw_height, color, 1);
|
||||
draw_ellipse((cairo_t*) hdc, draw_x, draw_y, draw_width, draw_height, color, 1);
|
||||
}
|
||||
break;
|
||||
case litehtml::list_style_type_disc:
|
||||
{
|
||||
fill_ellipse(get_dib(hdc), draw_x, draw_y, draw_width, draw_height, color);
|
||||
fill_ellipse((cairo_t*) hdc, draw_x, draw_y, draw_width, draw_height, color);
|
||||
}
|
||||
break;
|
||||
case litehtml::list_style_type_square:
|
||||
@ -194,7 +207,8 @@ void cairo_container::get_image_size( const wchar_t* src, const wchar_t* baseurl
|
||||
|
||||
void cairo_container::draw_image( litehtml::uint_ptr hdc, const wchar_t* src, const wchar_t* baseurl, const litehtml::position& pos )
|
||||
{
|
||||
cairo_dev cr(get_dib(hdc));
|
||||
cairo_t* cr = (cairo_t*) hdc;
|
||||
cairo_save(cr);
|
||||
apply_clip(cr);
|
||||
|
||||
std::wstring url;
|
||||
@ -202,13 +216,15 @@ void cairo_container::draw_image( litehtml::uint_ptr hdc, const wchar_t* src, co
|
||||
images_map::iterator img = m_images.find(url.c_str());
|
||||
if(img != m_images.end())
|
||||
{
|
||||
cr.draw_image(img->second, pos.x, pos.y, pos.width, pos.height);
|
||||
draw_txdib(cr, img->second, pos.x, pos.y, pos.width, pos.height);
|
||||
}
|
||||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
void cairo_container::draw_background( litehtml::uint_ptr hdc, const wchar_t* image, const wchar_t* baseurl, const litehtml::position& draw_pos, const litehtml::css_position& bg_pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment )
|
||||
{
|
||||
cairo_dev cr(get_dib(hdc));
|
||||
cairo_t* cr = (cairo_t*) hdc;
|
||||
cairo_save(cr);
|
||||
apply_clip(cr);
|
||||
|
||||
cairo_rectangle(cr, draw_pos.x, draw_pos.y, draw_pos.width, draw_pos.height);
|
||||
@ -257,7 +273,7 @@ void cairo_container::draw_background( litehtml::uint_ptr hdc, const wchar_t* im
|
||||
switch(repeat)
|
||||
{
|
||||
case litehtml::background_repeat_no_repeat:
|
||||
cr.draw_image(bgbmp, bg_x, bg_y, bgbmp->getWidth(), bgbmp->getHeight());
|
||||
draw_txdib(cr, bgbmp, bg_x, bg_y, bgbmp->getWidth(), bgbmp->getHeight());
|
||||
break;
|
||||
|
||||
case litehtml::background_repeat_repeat_x:
|
||||
@ -282,6 +298,7 @@ void cairo_container::draw_background( litehtml::uint_ptr hdc, const wchar_t* im
|
||||
cairo_pattern_destroy(pattern);
|
||||
cairo_surface_destroy(img);
|
||||
}
|
||||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
void cairo_container::add_path_arc(cairo_t* cr, double x, double y, double rx, double ry, double a1, double a2, bool neg)
|
||||
@ -312,7 +329,8 @@ void cairo_container::add_path_arc(cairo_t* cr, double x, double y, double rx, d
|
||||
|
||||
void cairo_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::css_borders& borders, const litehtml::position& draw_pos )
|
||||
{
|
||||
cairo_dev cr(get_dib(hdc));
|
||||
cairo_t* cr = (cairo_t*) hdc;
|
||||
cairo_save(cr);
|
||||
apply_clip(cr);
|
||||
|
||||
int bdr_top = 0;
|
||||
@ -340,7 +358,7 @@ void cairo_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::css_
|
||||
// draw right border
|
||||
if(bdr_right)
|
||||
{
|
||||
cr.set_color(borders.right.color);
|
||||
set_color(cr, borders.right.color);
|
||||
|
||||
double r_top = borders.radius.top_right_x.val();
|
||||
double r_bottom = borders.radius.bottom_right_x.val();
|
||||
@ -405,7 +423,7 @@ void cairo_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::css_
|
||||
// draw bottom border
|
||||
if(bdr_bottom)
|
||||
{
|
||||
cr.set_color(borders.bottom.color);
|
||||
set_color(cr, borders.bottom.color);
|
||||
|
||||
double r_left = borders.radius.bottom_left_x.val();
|
||||
double r_right = borders.radius.bottom_right_x.val();
|
||||
@ -470,7 +488,7 @@ void cairo_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::css_
|
||||
// draw top border
|
||||
if(bdr_top)
|
||||
{
|
||||
cr.set_color(borders.top.color);
|
||||
set_color(cr, borders.top.color);
|
||||
|
||||
double r_left = borders.radius.top_left_x.val();
|
||||
double r_right = borders.radius.top_right_x.val();
|
||||
@ -535,7 +553,7 @@ void cairo_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::css_
|
||||
// draw left border
|
||||
if(bdr_left)
|
||||
{
|
||||
cr.set_color(borders.left.color);
|
||||
set_color(cr, borders.left.color);
|
||||
|
||||
double r_top = borders.radius.top_left_x.val();
|
||||
double r_bottom = borders.radius.bottom_left_x.val();
|
||||
@ -596,6 +614,7 @@ void cairo_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::css_
|
||||
|
||||
cairo_fill(cr);
|
||||
}
|
||||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
wchar_t cairo_container::toupper( const wchar_t c )
|
||||
@ -647,35 +666,39 @@ void cairo_container::apply_clip( cairo_t* cr )
|
||||
}
|
||||
}
|
||||
|
||||
void cairo_container::draw_ellipse( simpledib::dib* dib, int x, int y, int width, int height, const litehtml::web_color& color, int line_width )
|
||||
void cairo_container::draw_ellipse( cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color, int line_width )
|
||||
{
|
||||
if(!dib) return;
|
||||
if(!cr) return;
|
||||
cairo_save(cr);
|
||||
|
||||
cairo_dev cr(dib);
|
||||
apply_clip(cr);
|
||||
|
||||
cairo_translate (cr, x + width / 2.0, y + height / 2.0);
|
||||
cairo_scale (cr, width / 2.0, height / 2.0);
|
||||
cairo_arc (cr, 0, 0, 1, 0, 2 * M_PI);
|
||||
|
||||
cr.set_color(color);
|
||||
set_color(cr, color);
|
||||
cairo_set_line_width(cr, line_width);
|
||||
cairo_stroke(cr);
|
||||
|
||||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
void cairo_container::fill_ellipse( simpledib::dib* dib, int x, int y, int width, int height, const litehtml::web_color& color )
|
||||
void cairo_container::fill_ellipse( cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color )
|
||||
{
|
||||
if(!dib) return;
|
||||
if(!cr) return;
|
||||
cairo_save(cr);
|
||||
|
||||
cairo_dev cr(dib);
|
||||
apply_clip(cr);
|
||||
|
||||
cairo_translate (cr, x + width / 2.0, y + height / 2.0);
|
||||
cairo_scale (cr, width / 2.0, height / 2.0);
|
||||
cairo_arc (cr, 0, 0, 1, 0, 2 * M_PI);
|
||||
|
||||
cr.set_color(color);
|
||||
set_color(cr, color);
|
||||
cairo_fill(cr);
|
||||
|
||||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
void cairo_container::clear_images()
|
||||
@ -695,6 +718,38 @@ const wchar_t* cairo_container::get_default_font_name()
|
||||
return L"Times New Roman";
|
||||
}
|
||||
|
||||
void cairo_container::draw_txdib( cairo_t* cr, CTxDIB* bmp, int x, int y, int cx, int cy )
|
||||
{
|
||||
cairo_save(cr);
|
||||
|
||||
cairo_matrix_t flib_m;
|
||||
cairo_matrix_init(&flib_m, 1, 0, 0, -1, 0, 0);
|
||||
|
||||
cairo_surface_t* img = NULL;
|
||||
|
||||
CTxDIB rbmp;
|
||||
|
||||
if(cx != bmp->getWidth() || cy != bmp->getHeight())
|
||||
{
|
||||
bmp->resample(cx, cy, &rbmp);
|
||||
img = cairo_image_surface_create_for_data((unsigned char*) rbmp.getBits(), CAIRO_FORMAT_ARGB32, rbmp.getWidth(), rbmp.getHeight(), rbmp.getWidth() * 4);
|
||||
cairo_matrix_translate(&flib_m, 0, -rbmp.getHeight());
|
||||
cairo_matrix_translate(&flib_m, x, -y);
|
||||
} else
|
||||
{
|
||||
img = cairo_image_surface_create_for_data((unsigned char*) bmp->getBits(), CAIRO_FORMAT_ARGB32, bmp->getWidth(), bmp->getHeight(), bmp->getWidth() * 4);
|
||||
cairo_matrix_translate(&flib_m, 0, -bmp->getHeight());
|
||||
cairo_matrix_translate(&flib_m, x, -y);
|
||||
}
|
||||
|
||||
cairo_transform(cr, &flib_m);
|
||||
cairo_set_source_surface(cr, img, 0, 0);
|
||||
cairo_paint(cr);
|
||||
|
||||
cairo_restore(cr);
|
||||
cairo_surface_destroy(img);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cairo_dev::cairo_dev( simpledib::dib* dib )
|
||||
|
@ -35,7 +35,8 @@ class cairo_container : public litehtml::document_container
|
||||
typedef std::map<std::wstring, CTxDIB*> images_map;
|
||||
|
||||
protected:
|
||||
simpledib::dib m_temp_dib;
|
||||
cairo_surface_t* m_temp_surface;
|
||||
cairo_t* m_temp_cr;
|
||||
images_map m_images;
|
||||
litehtml::position::vector m_clips;
|
||||
IMLangFontLink2* m_font_link;
|
||||
@ -72,14 +73,17 @@ public:
|
||||
virtual void make_url( LPCWSTR url, LPCWSTR basepath, std::wstring& out ) = 0;
|
||||
virtual CTxDIB* get_image(LPCWSTR url) = 0;
|
||||
virtual void get_client_rect(litehtml::position& client) = 0;
|
||||
void clear_images();
|
||||
|
||||
protected:
|
||||
virtual void draw_ellipse(simpledib::dib* dib, int x, int y, int width, int height, const litehtml::web_color& color, int line_width);
|
||||
virtual void fill_ellipse(simpledib::dib* dib, int x, int y, int width, int height, const litehtml::web_color& color);
|
||||
virtual void draw_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color, int line_width);
|
||||
virtual void fill_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color);
|
||||
|
||||
private:
|
||||
simpledib::dib* get_dib(litehtml::uint_ptr hdc) { return (simpledib::dib*) hdc; }
|
||||
void apply_clip(cairo_t* cr);
|
||||
void clear_images();
|
||||
void add_path_arc(cairo_t* cr, double x, double y, double rx, double ry, double a1, double a2, bool neg);
|
||||
|
||||
void set_color(cairo_t* cr, litehtml::web_color color) { cairo_set_source_rgba(cr, color.red / 255.0, color.green / 255.0, color.blue / 255.0, color.alpha / 255.0); }
|
||||
void draw_txdib(cairo_t* cr, CTxDIB* bmp, int x, int y, int cx, int cy);
|
||||
};
|
||||
|
@ -314,7 +314,7 @@ int litehtml::el_table::render( int x, int y, int max_width )
|
||||
m_pos.width = table_width;
|
||||
m_pos.height = top;
|
||||
|
||||
return min_table_width;
|
||||
return table_width;//min_table_width;
|
||||
}
|
||||
|
||||
bool litehtml::el_table::appendChild( litehtml::element* el )
|
||||
|
@ -32,12 +32,18 @@ litehtml::tooltips::tooltips(HINSTANCE hInst, litehtml::context* html_context)
|
||||
m_over_tool = 0;
|
||||
m_disabled = false;
|
||||
m_alpha = 255;
|
||||
m_cr = NULL;
|
||||
m_surface = NULL;
|
||||
|
||||
init_def_font();
|
||||
}
|
||||
|
||||
litehtml::tooltips::~tooltips(void)
|
||||
{
|
||||
DestroyWindow(m_hWnd);
|
||||
RemoveWindowSubclass(m_hWndParent, SubclassProc, (DWORD_PTR) this);
|
||||
if(m_surface) cairo_surface_destroy(m_surface);
|
||||
if(m_cr) cairo_destroy(m_cr);
|
||||
}
|
||||
|
||||
void litehtml::tooltips::make_url( LPCWSTR url, LPCWSTR basepath, std::wstring& out )
|
||||
@ -49,7 +55,7 @@ CTxDIB* litehtml::tooltips::get_image( LPCWSTR url )
|
||||
{
|
||||
if(m_callback)
|
||||
{
|
||||
return m_callback->ttcb_get_image(url);
|
||||
return m_callback->ttcb_get_image(m_show_tool, url);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -196,11 +202,13 @@ void litehtml::tooltips::create( HWND parent )
|
||||
}
|
||||
}
|
||||
|
||||
void litehtml::tooltips::show( unsigned int id )
|
||||
void litehtml::tooltips::show( unsigned int id, int top )
|
||||
{
|
||||
tool::map::iterator ti = m_tools.find(id);
|
||||
if(ti != m_tools.end())
|
||||
{
|
||||
m_show_tool = id;
|
||||
clear_images();
|
||||
if(m_html)
|
||||
{
|
||||
m_html = NULL;
|
||||
@ -222,42 +230,23 @@ void litehtml::tooltips::show( unsigned int id )
|
||||
}
|
||||
|
||||
int w = m_html->render(m_max_width);
|
||||
if(w != m_max_width)
|
||||
if(w < m_max_width)
|
||||
{
|
||||
m_html->render(w);
|
||||
}
|
||||
|
||||
tip_layout layout;
|
||||
calc_layout(&ti->second, &layout);
|
||||
calc_layout(&ti->second, &m_layout);
|
||||
create_dib(m_layout.width, m_layout.height);
|
||||
|
||||
m_dib.clear();
|
||||
m_dib.create(layout.width, layout.height, true);
|
||||
m_top = top;
|
||||
if(m_top)
|
||||
{
|
||||
scroll(0);
|
||||
}
|
||||
|
||||
draw_background(&layout);
|
||||
|
||||
litehtml::position clip(0, 0, m_dib.width(), m_dib.height());
|
||||
m_html->draw((litehtml::uint_ptr) &m_dib, layout.content_x, layout.content_y, NULL);
|
||||
|
||||
POINT ptDst;
|
||||
POINT ptSrc = {0, 0};
|
||||
SIZE size;
|
||||
|
||||
BLENDFUNCTION bf;
|
||||
bf.BlendOp = AC_SRC_OVER;
|
||||
bf.BlendFlags = 0;
|
||||
bf.AlphaFormat = AC_SRC_ALPHA;
|
||||
bf.SourceConstantAlpha = 255;
|
||||
|
||||
ptDst.x = layout.x;
|
||||
ptDst.y = layout.y;
|
||||
|
||||
size.cx = m_dib.width();
|
||||
size.cy = m_dib.height();
|
||||
|
||||
UpdateLayeredWindow(m_hWnd, NULL, &ptDst, &size, m_dib.hdc(), &ptSrc, 0, &bf, ULW_ALPHA);
|
||||
draw_window();
|
||||
ShowWindow(m_hWnd, SW_SHOWNA);
|
||||
|
||||
m_show_tool = id;
|
||||
if(m_hide_time)
|
||||
{
|
||||
SetTimer(m_hWnd, TIMER_HIDE_TIP, m_hide_time, NULL);
|
||||
@ -271,8 +260,8 @@ void litehtml::tooltips::hide()
|
||||
{
|
||||
m_show_tool = 0;
|
||||
ShowWindow(m_hWnd, SW_HIDE);
|
||||
stop_timers();
|
||||
}
|
||||
stop_timers();
|
||||
}
|
||||
|
||||
LRESULT CALLBACK litehtml::tooltips::SubclassProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData )
|
||||
@ -281,6 +270,19 @@ LRESULT CALLBACK litehtml::tooltips::SubclassProc( HWND hWnd, UINT uMsg, WPARAM
|
||||
|
||||
switch(uMsg)
|
||||
{
|
||||
case WM_MOUSEWHEEL:
|
||||
if(pThis->can_scroll())
|
||||
{
|
||||
if(pThis->scroll(-GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA * pThis->m_def_font_size * 5))
|
||||
{
|
||||
pThis->draw_window(TRUE);
|
||||
}
|
||||
return 0;
|
||||
} else
|
||||
{
|
||||
pThis->hide();
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONDOWN:
|
||||
case WM_LBUTTONDBLCLK:
|
||||
case WM_RBUTTONDOWN:
|
||||
@ -297,7 +299,6 @@ LRESULT CALLBACK litehtml::tooltips::SubclassProc( HWND hWnd, UINT uMsg, WPARAM
|
||||
case WM_SYSKEYDOWN:
|
||||
case WM_KILLFOCUS:
|
||||
case WM_CLOSE:
|
||||
case WM_MOUSEWHEEL:
|
||||
case WM_MOUSELEAVE:
|
||||
pThis->hide();
|
||||
break;
|
||||
@ -344,7 +345,7 @@ LRESULT CALLBACK litehtml::tooltips::SubclassProc( HWND hWnd, UINT uMsg, WPARAM
|
||||
|
||||
void litehtml::tooltips::draw_background(tip_layout* layout)
|
||||
{
|
||||
cairo_dev cr(&m_dib);
|
||||
cairo_save(m_cr);
|
||||
|
||||
COLORREF clr_bg = GetSysColor(COLOR_INFOBK);
|
||||
COLORREF clr_bdr = GetSysColor(COLOR_INFOTEXT);
|
||||
@ -352,13 +353,13 @@ void litehtml::tooltips::draw_background(tip_layout* layout)
|
||||
switch(m_style)
|
||||
{
|
||||
case tips_style_rounded:
|
||||
rounded_rect(cr, 0, 0, m_dib.width() - 5, m_dib.height() - 5, 8, 1);
|
||||
rounded_rect(m_cr, 0, 0, m_dib.width() - 5, m_dib.height() - 5, 8, 1);
|
||||
break;
|
||||
case tips_style_baloon:
|
||||
baloon(cr, 0, 0, m_dib.width() - 5, m_dib.height() - 5, layout->anchor_x - layout->x, layout->anchor_y - layout->y, layout->align, 8, 1);
|
||||
baloon(m_cr, 0, 0, m_dib.width() - 5, m_dib.height() - 5, layout->anchor_x - layout->x, layout->anchor_y - layout->y, layout->align, 8, 1);
|
||||
break;
|
||||
default:
|
||||
cairo_rectangle(cr, 0.5, 0.5, m_dib.width() - 1 - 5, m_dib.height() - 1 - 5);
|
||||
cairo_rectangle(m_cr, 0.5, 0.5, m_dib.width() - 1 - 5, m_dib.height() - 1 - 5);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -375,11 +376,11 @@ void litehtml::tooltips::draw_background(tip_layout* layout)
|
||||
{
|
||||
cairo_surface_t* bg_sf = cairo_image_surface_create_for_data((unsigned char*) dib_bg.bits(), CAIRO_FORMAT_ARGB32, dib_bg.width(), dib_bg.height(), dib_bg.width() * 4);
|
||||
|
||||
cairo_save(cr);
|
||||
cairo_clip_preserve(cr);
|
||||
cairo_set_source_surface(cr, bg_sf, 0, 0);
|
||||
cairo_paint(cr);
|
||||
cairo_restore(cr);
|
||||
cairo_save(m_cr);
|
||||
cairo_clip_preserve(m_cr);
|
||||
cairo_set_source_surface(m_cr, bg_sf, 0, 0);
|
||||
cairo_paint(m_cr);
|
||||
cairo_restore(m_cr);
|
||||
|
||||
clr_bdr = RGB(dib_bg.bits()[0].rgbRed, dib_bg.bits()[0].rgbGreen, dib_bg.bits()[0].rgbBlue);
|
||||
|
||||
@ -392,12 +393,12 @@ void litehtml::tooltips::draw_background(tip_layout* layout)
|
||||
|
||||
if(stdDraw)
|
||||
{
|
||||
cairo_set_source_rgb(cr, (double) GetRValue(clr_bg) / 255.0, (double) GetGValue(clr_bg) / 255.0, (double) GetBValue(clr_bg) / 255.0);
|
||||
cairo_fill_preserve(cr);
|
||||
cairo_set_source_rgb(m_cr, (double) GetRValue(clr_bg) / 255.0, (double) GetGValue(clr_bg) / 255.0, (double) GetBValue(clr_bg) / 255.0);
|
||||
cairo_fill_preserve(m_cr);
|
||||
}
|
||||
cairo_set_line_width(cr, 1);
|
||||
cairo_set_source_rgb(cr, (double) GetRValue(clr_bdr) / 255.0, (double) GetGValue(clr_bdr) / 255.0, (double) GetBValue(clr_bdr) / 255.0);
|
||||
cairo_stroke(cr);
|
||||
cairo_set_line_width(m_cr, 1);
|
||||
cairo_set_source_rgb(m_cr, (double) GetRValue(clr_bdr) / 255.0, (double) GetGValue(clr_bdr) / 255.0, (double) GetBValue(clr_bdr) / 255.0);
|
||||
cairo_stroke(m_cr);
|
||||
|
||||
int shadow_width = 10;
|
||||
int shadow_height = 10;
|
||||
@ -431,7 +432,6 @@ void litehtml::tooltips::draw_background(tip_layout* layout)
|
||||
|
||||
for(int i=0; i < sz; i++)
|
||||
{
|
||||
//pixels[i].rgbReserved = min(200, pixels[i].rgbReserved << 2);
|
||||
pixels[i].rgbRed = 0;
|
||||
pixels[i].rgbGreen = 0;
|
||||
pixels[i].rgbBlue = 0;
|
||||
@ -447,10 +447,10 @@ void litehtml::tooltips::draw_background(tip_layout* layout)
|
||||
cairo_paint(cr_shadow);
|
||||
fastbluralpha(shadow.bits(), shadow.width(), shadow.height(), 5);
|
||||
|
||||
cairo_set_operator(cr, CAIRO_OPERATOR_DEST_OVER);
|
||||
cairo_set_operator(m_cr, CAIRO_OPERATOR_DEST_OVER);
|
||||
|
||||
cairo_set_source_surface(cr, cr_shadow, 0, 0);
|
||||
cairo_paint(cr);
|
||||
cairo_set_source_surface(m_cr, cr_shadow, 0, 0);
|
||||
cairo_paint(m_cr);
|
||||
|
||||
cairo_surface_destroy(img_sf);
|
||||
|
||||
@ -479,6 +479,7 @@ void litehtml::tooltips::draw_background(tip_layout* layout)
|
||||
}
|
||||
}
|
||||
|
||||
cairo_restore(m_cr);
|
||||
}
|
||||
|
||||
int litehtml::tooltips::tip_width()
|
||||
@ -585,8 +586,10 @@ unsigned int litehtml::tooltips::find_tool( int x, int y )
|
||||
|
||||
void litehtml::tooltips::calc_layout( tool* t, tip_layout* layout )
|
||||
{
|
||||
layout->width = m_html->width();
|
||||
layout->height = m_html->height();
|
||||
layout->width = m_html->width();
|
||||
layout->height = m_html->height();
|
||||
layout->content_width = m_html->width();
|
||||
layout->content_height = m_html->height();
|
||||
|
||||
switch(m_style)
|
||||
{
|
||||
@ -615,6 +618,16 @@ void litehtml::tooltips::calc_layout( tool* t, tip_layout* layout )
|
||||
|
||||
calc_position(t->options & tool_opt_align_mask, &rc_tool, layout);
|
||||
|
||||
RECT rcDesktop;
|
||||
GetDesktopRect(&rcDesktop, m_hWndParent);
|
||||
|
||||
if(layout->y + layout->height > rcDesktop.bottom)
|
||||
{
|
||||
int margin = layout->height - m_html->height();
|
||||
layout->height = rcDesktop.bottom - layout->y;
|
||||
layout->content_height = layout->height - margin;
|
||||
}
|
||||
|
||||
switch(layout->align)
|
||||
{
|
||||
case tool_opt_align_top:
|
||||
@ -747,7 +760,7 @@ void litehtml::tooltips::calc_position( UINT align, LPRECT rc_tool, tip_layout*
|
||||
calc_position(tool_opt_align_bottom, rc_tool, layout, true);
|
||||
} else
|
||||
{
|
||||
if(rcDesktop.left - rcDesktop.left > rcDesktop.right - rc_tool->right)
|
||||
if(rc_tool->left - rcDesktop.left > rcDesktop.right - rc_tool->right)
|
||||
{
|
||||
calc_position(tool_opt_align_left, rc_tool, layout, true);
|
||||
} else
|
||||
@ -782,7 +795,7 @@ void litehtml::tooltips::calc_position( UINT align, LPRECT rc_tool, tip_layout*
|
||||
calc_position(tool_opt_align_top, rc_tool, layout, true);
|
||||
} else
|
||||
{
|
||||
if(rcDesktop.left - rcDesktop.left > rcDesktop.right - rc_tool->right)
|
||||
if(rc_tool->left - rcDesktop.left > rcDesktop.right - rc_tool->right)
|
||||
{
|
||||
calc_position(tool_opt_align_left, rc_tool, layout, true);
|
||||
} else
|
||||
@ -817,7 +830,7 @@ void litehtml::tooltips::calc_position( UINT align, LPRECT rc_tool, tip_layout*
|
||||
calc_position(tool_opt_align_right, rc_tool, layout, true);
|
||||
} else
|
||||
{
|
||||
if(rcDesktop.top - rcDesktop.top > rcDesktop.bottom - rc_tool->bottom)
|
||||
if(rc_tool->top - rcDesktop.top > rcDesktop.bottom - rc_tool->bottom)
|
||||
{
|
||||
calc_position(tool_opt_align_top, rc_tool, layout, true);
|
||||
} else
|
||||
@ -852,7 +865,7 @@ void litehtml::tooltips::calc_position( UINT align, LPRECT rc_tool, tip_layout*
|
||||
calc_position(tool_opt_align_left, rc_tool, layout, true);
|
||||
} else
|
||||
{
|
||||
if(rcDesktop.top - rcDesktop.top > rcDesktop.bottom - rc_tool->bottom)
|
||||
if(rc_tool->top - rcDesktop.top > rcDesktop.bottom - rc_tool->bottom)
|
||||
{
|
||||
calc_position(tool_opt_align_top, rc_tool, layout, true);
|
||||
} else
|
||||
@ -1177,6 +1190,90 @@ void litehtml::tooltips::update( unsigned int id )
|
||||
{
|
||||
if(id == m_show_tool && IsWindowVisible(m_hWnd))
|
||||
{
|
||||
show(id);
|
||||
show(id, m_top);
|
||||
}
|
||||
}
|
||||
|
||||
void litehtml::tooltips::create_dib( int width, int height )
|
||||
{
|
||||
if(m_surface) cairo_surface_destroy(m_surface);
|
||||
if(m_cr) cairo_destroy(m_cr);
|
||||
|
||||
m_dib.clear();
|
||||
m_dib.create(width, height, true);
|
||||
|
||||
m_surface = cairo_image_surface_create_for_data((unsigned char*) m_dib.bits(), CAIRO_FORMAT_ARGB32, m_dib.width(), m_dib.height(), m_dib.width() * 4);
|
||||
m_cr = cairo_create(m_surface);
|
||||
}
|
||||
|
||||
void litehtml::tooltips::draw_window(BOOL clr)
|
||||
{
|
||||
if(clr)
|
||||
{
|
||||
cairo_save(m_cr);
|
||||
|
||||
cairo_set_operator(m_cr, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_set_source_rgba(m_cr, 0, 0, 0, 0);
|
||||
cairo_paint(m_cr);
|
||||
|
||||
cairo_restore(m_cr);
|
||||
}
|
||||
|
||||
draw_background(&m_layout);
|
||||
|
||||
litehtml::position clip(m_layout.content_x, m_layout.content_y, m_html->width(), m_html->height());
|
||||
cairo_save(m_cr);
|
||||
cairo_rectangle(m_cr, m_layout.content_x, m_layout.content_y, m_layout.content_width, m_layout.content_height);
|
||||
cairo_clip(m_cr);
|
||||
m_html->draw((litehtml::uint_ptr) m_cr, m_layout.content_x, m_layout.content_y - m_top, &clip);
|
||||
cairo_restore(m_cr);
|
||||
|
||||
POINT ptDst;
|
||||
POINT ptSrc = {0, 0};
|
||||
SIZE size;
|
||||
|
||||
BLENDFUNCTION bf;
|
||||
bf.BlendOp = AC_SRC_OVER;
|
||||
bf.BlendFlags = 0;
|
||||
bf.AlphaFormat = AC_SRC_ALPHA;
|
||||
bf.SourceConstantAlpha = 255;
|
||||
|
||||
ptDst.x = m_layout.x;
|
||||
ptDst.y = m_layout.y;
|
||||
|
||||
size.cx = m_dib.width();
|
||||
size.cy = m_dib.height();
|
||||
|
||||
UpdateLayeredWindow(m_hWnd, NULL, &ptDst, &size, m_dib.hdc(), &ptSrc, 0, &bf, ULW_ALPHA);
|
||||
}
|
||||
|
||||
BOOL litehtml::tooltips::scroll( int dx )
|
||||
{
|
||||
if(IsWindow(m_hWnd) && IsWindowVisible(m_hWnd))
|
||||
{
|
||||
int new_top = m_top + dx;
|
||||
if(new_top < 0) new_top = 0;
|
||||
if(new_top > m_html->height() - m_layout.content_height)
|
||||
{
|
||||
new_top = m_html->height() - m_layout.content_height;
|
||||
}
|
||||
if(new_top != m_top)
|
||||
{
|
||||
m_top = new_top;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL litehtml::tooltips::can_scroll()
|
||||
{
|
||||
if(IsWindow(m_hWnd) && IsWindowVisible(m_hWnd))
|
||||
{
|
||||
if(m_html->height() > m_layout.content_height)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ namespace litehtml
|
||||
class tooltips_callback
|
||||
{
|
||||
public:
|
||||
virtual CTxDIB* ttcb_get_image(LPCWSTR url) = 0;
|
||||
virtual CTxDIB* ttcb_get_image(unsigned int id, LPCWSTR url) = 0;
|
||||
virtual void ttcb_get_text(unsigned int id, std::wstring& text) = 0;
|
||||
};
|
||||
|
||||
@ -37,6 +37,8 @@ namespace litehtml
|
||||
int height;
|
||||
int content_x;
|
||||
int content_y;
|
||||
int content_height;
|
||||
int content_width;
|
||||
int anchor_x;
|
||||
int anchor_y;
|
||||
UINT align;
|
||||
@ -88,13 +90,16 @@ namespace litehtml
|
||||
|
||||
class tooltips : public cairo_container
|
||||
{
|
||||
simpledib::dib m_dib;
|
||||
cairo_t* m_cr;
|
||||
cairo_surface_t* m_surface;
|
||||
|
||||
HINSTANCE m_hInst;
|
||||
HWND m_hWnd;
|
||||
HWND m_hWndParent;
|
||||
tooltips_callback* m_callback;
|
||||
tool::map m_tools;
|
||||
litehtml::document::ptr m_html;
|
||||
simpledib::dib m_dib;
|
||||
litehtml::context* m_html_context;
|
||||
int m_max_width;
|
||||
int m_show_time;
|
||||
@ -107,6 +112,8 @@ namespace litehtml
|
||||
int m_def_font_size;
|
||||
bool m_disabled;
|
||||
BYTE m_alpha;
|
||||
tip_layout m_layout;
|
||||
int m_top;
|
||||
public:
|
||||
tooltips(HINSTANCE hInst, litehtml::context* html_context);
|
||||
virtual ~tooltips(void);
|
||||
@ -114,7 +121,8 @@ namespace litehtml
|
||||
void add_tool(unsigned int id, const wchar_t* text, HWND ctl, LPCRECT rc_tool, UINT options);
|
||||
void clear();
|
||||
void create(HWND parent);
|
||||
void show(unsigned int id);
|
||||
void show(unsigned int id, int top = 0);
|
||||
|
||||
void hide();
|
||||
void set_style(tips_style style) { m_style = style; }
|
||||
void disable(bool val);
|
||||
@ -159,5 +167,9 @@ namespace litehtml
|
||||
void fastbluralpha(LPRGBQUAD pixels, int width, int height, int radius);
|
||||
void finish_shadow(simpledib::dib& dib);
|
||||
void init_def_font();
|
||||
void create_dib(int width, int height);
|
||||
void draw_window(BOOL clr = FALSE);
|
||||
BOOL scroll(int dx);
|
||||
BOOL can_scroll();
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user