diff options
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | dillorc | 6 | ||||
-rw-r--r-- | dw/fltkplatform.cc | 46 | ||||
-rw-r--r-- | dw/fltkplatform.hh | 15 | ||||
-rw-r--r-- | dw/image.cc | 8 | ||||
-rw-r--r-- | dw/layout.hh | 5 | ||||
-rw-r--r-- | dw/platform.hh | 5 | ||||
-rw-r--r-- | dw/style.cc | 6 | ||||
-rw-r--r-- | dw/style.hh | 11 | ||||
-rw-r--r-- | src/html.cc | 29 | ||||
-rw-r--r-- | src/styleengine.cc | 4 |
11 files changed, 112 insertions, 24 deletions
@@ -33,6 +33,7 @@ dillo-2.2 [??] - By default, do not use proxy for localhost (BUG 921). - Fix scrolling for text search. - Added 'save' key action (not bound by default). + - Tooltips Patches: corvid ----------------------------------------------------------------------------- @@ -61,11 +61,7 @@ # Minimum font size in pixels #font_min_size=6 -# Show tooltip popup for images? -# Note: We use the "title" attribute and not "alt". -# More info at: http://bugzilla.mozilla.org/show_bug.cgi?id=25537 -# *** NOT HOOKED UP YET *** -# +# Show tooltip popup for title attributes #show_tooltip=YES # Set this to YES if you want to limit the word wrap width to the viewport diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc index 4ceca58d..e4d9a874 100644 --- a/dw/fltkplatform.cc +++ b/dw/fltkplatform.cc @@ -25,6 +25,8 @@ #include <fltk/run.h> #include <fltk/events.h> #include <fltk/Monitor.h> +#include <fltk/InvisibleBox.h> +#include <fltk/Tooltip.h> #include <fltk/utf.h> #include <stdio.h> @@ -143,6 +145,45 @@ FltkColor * FltkColor::create (int col) return color; } +::fltk::Widget *FltkTooltip::widget = NULL; + +FltkTooltip::FltkTooltip (const char *text) : Tooltip(text) +{ + /* ::fltk::Tooltip really, really wants a Widget */ + if (!widget) + widget = new ::fltk::InvisibleBox(1, 1, 0, 0, NULL); + shown = false; +} + +FltkTooltip::~FltkTooltip () +{ + if (shown) + ::fltk::Tooltip::exit(); +} + +FltkTooltip *FltkTooltip::create (const char *text) +{ + return new FltkTooltip(text); +} + +void FltkTooltip::onEnter() +{ + Rectangle rect; + widget->get_absolute_rect(&rect); + ::fltk::Tooltip::enter(widget, rect, str); + shown = true; +} + +void FltkTooltip::onLeave() +{ + ::fltk::Tooltip::exit(); + shown = false; +} + +void FltkTooltip::onMotion() +{ +} + void FltkView::addFltkWidget (::fltk::Widget *widget, core::Allocation *allocation) { @@ -384,6 +425,11 @@ core::style::Color *FltkPlatform::createColor (int color) return FltkColor::create (color); } +core::style::Tooltip *FltkPlatform::createTooltip (const char *text) +{ + return FltkTooltip::create (text); +} + void FltkPlatform::copySelection(const char *text) { fltk::copy(text, strlen(text), false); diff --git a/dw/fltkplatform.hh b/dw/fltkplatform.hh index 253f1bbd..d83f34ea 100644 --- a/dw/fltkplatform.hh +++ b/dw/fltkplatform.hh @@ -43,6 +43,20 @@ public: static FltkColor *create(int color); }; +class FltkTooltip: public core::style::Tooltip +{ +private: + FltkTooltip (const char *text); + ~FltkTooltip (); + bool shown; + static ::fltk::Widget *widget; +public: + static FltkTooltip *create(const char *text); + void onEnter(); + void onLeave(); + void onMotion(); +}; + /** * \brief This interface adds some more methods for all flkt-based views. @@ -136,6 +150,7 @@ public: core::style::Font *createFont (core::style::FontAttrs *attrs, bool tryEverything); core::style::Color *createColor (int color); + core::style::Tooltip *createTooltip (const char *text); core::Imgbuf *createImgbuf (core::Imgbuf::Type type, int width, int height); diff --git a/dw/image.cc b/dw/image.cc index e200e5b9..4230d115 100644 --- a/dw/image.cc +++ b/dw/image.cc @@ -226,20 +226,28 @@ void Image::enterNotifyImpl (core::EventCrossing *event) { // BUG: this is wrong for image maps, but the cursor position is unknown. currLink = getStyle()->x_link; + core::style::Tooltip *tooltip = getStyle()->x_tooltip; if (currLink != -1) { (void) emitLinkEnter (currLink, -1, -1, -1); } + if (tooltip) { + tooltip->onEnter(); + } } void Image::leaveNotifyImpl (core::EventCrossing *event) { + core::style::Tooltip *tooltip = getStyle()->x_tooltip; clicking = false; if (currLink != -1) { currLink = -1; (void) emitLinkEnter (-1, -1, -1, -1); } + if (tooltip) { + tooltip->onLeave(); + } } /* diff --git a/dw/layout.hh b/dw/layout.hh index b9ba46e5..bd7e191d 100644 --- a/dw/layout.hh +++ b/dw/layout.hh @@ -237,6 +237,11 @@ public: return platform->createColor (color); } + inline style::Tooltip *createTooltip (const char *text) + { + return platform->createTooltip (text); + } + inline Imgbuf *createImgbuf (Imgbuf::Type type, int width, int height) { return platform->createImgbuf (type, width, height); diff --git a/dw/platform.hh b/dw/platform.hh index 144f5d5f..d31fb6f9 100644 --- a/dw/platform.hh +++ b/dw/platform.hh @@ -124,6 +124,11 @@ public: */ virtual style::Color *createColor (int color) = 0; + /** + * \brief Create a tooltip + */ + virtual style::Tooltip *createTooltip (const char *text) = 0; + /* * -------------------- * Image Buffers diff --git a/dw/style.cc b/dw/style.cc index ae118043..b284964f 100644 --- a/dw/style.cc +++ b/dw/style.cc @@ -65,7 +65,6 @@ void StyleAttrs::initValues () void StyleAttrs::resetValues () { x_img = -1; - x_tooltip = NULL; valign = VALIGN_BASELINE; textAlignChar = '.'; @@ -410,6 +409,11 @@ Color *Color::create (Layout *layout, int col) return layout->createColor (col); } +Tooltip *Tooltip::create (Layout *layout, const char *text) +{ + return layout->createTooltip (text); +} + // ---------------------------------------------------------------------- static void drawTriangle (View *view, Color *color, Color::Shading shading, diff --git a/dw/style.hh b/dw/style.hh index 8d0b9df7..e21cacc1 100644 --- a/dw/style.hh +++ b/dw/style.hh @@ -524,19 +524,18 @@ class Tooltip: public TooltipAttrs private: int refCount; +protected: Tooltip (const char *text): TooltipAttrs(text) { refCount = 0; } public: - inline Tooltip *create (Layout *layout, const char *text) - { return new Tooltip (text); } - + static Tooltip *create (dw::core::Layout *layout, const char *text); inline void ref () { refCount++; } inline void unref () { if (--refCount == 0) delete this; } - inline void onEnter () { } - inline void onLeave () { } - inline void onMotion () { } + inline virtual void onEnter () { } + inline virtual void onLeave () { } + inline virtual void onMotion () { } }; diff --git a/src/html.cc b/src/html.cc index b2a3c543..6450caa3 100644 --- a/src/html.cc +++ b/src/html.cc @@ -1944,13 +1944,17 @@ static void Html_tag_open_font(DilloHtml *html, const char *tag, int tagsize) */ static void Html_tag_open_abbr(DilloHtml *html, const char *tag, int tagsize) { -// DwTooltip *tooltip; -// const char *attrbuf; -// -// if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "title"))) { -// tooltip = a_Dw_tooltip_new_no_ref(attrbuf); -// HTML_SET_TOP_ATTR(html, x_tooltip, tooltip); -// } + const char *attrbuf; + + if (prefs.show_tooltip && + (attrbuf = a_Html_get_attr(html, tag, tagsize, "title"))) { + CssPropertyList props; + char *tooltip_str = dStrdup(attrbuf); + + props.set (PROPERTY_X_TOOLTIP, CSS_TYPE_STRING, tooltip_str); + html->styleEngine->setNonCssHints (&props); + dFree(tooltip_str); + } } /* @@ -1984,11 +1988,13 @@ DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, int space, border, w = 0, h = 0; bool load_now; CssPropertyList props; + char *tooltip_str = NULL; -// if (prefs.show_tooltip && -// (attrbuf = a_Html_get_attr(html, tag, tagsize, "title"))) -// style_attrs->x_tooltip = a_Dw_tooltip_new_no_ref(attrbuf); - + if (prefs.show_tooltip && + (attrbuf = a_Html_get_attr(html, tag, tagsize, "title"))) { + tooltip_str = dStrdup(attrbuf); + props.set (PROPERTY_X_TOOLTIP, CSS_TYPE_STRING, tooltip_str); + } alt_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "alt", NULL); if ((!alt_ptr || !*alt_ptr) && !prefs.load_images) { dFree(alt_ptr); @@ -2104,6 +2110,7 @@ DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, if (load_now) Html_load_image(html->bw, url, Image); + dFree(tooltip_str); dFree(width_ptr); dFree(height_ptr); dFree(alt_ptr); diff --git a/src/styleengine.cc b/src/styleengine.cc index a54fdeb3..d97aba5c 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -438,7 +438,9 @@ void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) { case PROPERTY_X_IMG: attrs->x_img = p->value.intVal; break; - + case PROPERTY_X_TOOLTIP: + attrs->x_tooltip = Tooltip::create(layout, p->value.strVal); + break; default: break; } |