changeset 1340:37f26396a31b

some tooltips
author corvid <corvid@lavabit.com>
date Sat, 03 Oct 2009 02:22:31 +0000
parents aa08f6648d44
children e595098a0de9
files ChangeLog dillorc dw/fltkplatform.cc dw/fltkplatform.hh dw/image.cc dw/layout.hh dw/platform.hh dw/style.cc dw/style.hh src/html.cc src/styleengine.cc
diffstat 11 files changed, 113 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Sep 29 19:26:08 2009 +0100
+++ b/ChangeLog	Sat Oct 03 02:22:31 2009 +0000
@@ -33,6 +33,7 @@
  - 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
 
 -----------------------------------------------------------------------------
--- a/dillorc	Tue Sep 29 19:26:08 2009 +0100
+++ b/dillorc	Sat Oct 03 02:22:31 2009 +0000
@@ -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
--- a/dw/fltkplatform.cc	Tue Sep 29 19:26:08 2009 +0100
+++ b/dw/fltkplatform.cc	Sat Oct 03 02:22:31 2009 +0000
@@ -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 @@
    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 @@
    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);
--- a/dw/fltkplatform.hh	Tue Sep 29 19:26:08 2009 +0100
+++ b/dw/fltkplatform.hh	Sat Oct 03 02:22:31 2009 +0000
@@ -43,6 +43,20 @@
    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 @@
    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);
 
--- a/dw/image.cc	Tue Sep 29 19:26:08 2009 +0100
+++ b/dw/image.cc	Sat Oct 03 02:22:31 2009 +0000
@@ -226,20 +226,28 @@
 {
    // 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();
+   }
 }
 
 /*
--- a/dw/layout.hh	Tue Sep 29 19:26:08 2009 +0100
+++ b/dw/layout.hh	Sat Oct 03 02:22:31 2009 +0000
@@ -237,6 +237,11 @@
       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);
--- a/dw/platform.hh	Tue Sep 29 19:26:08 2009 +0100
+++ b/dw/platform.hh	Sat Oct 03 02:22:31 2009 +0000
@@ -124,6 +124,11 @@
     */
    virtual style::Color *createColor (int color) = 0;
 
+   /**
+    * \brief Create a tooltip
+    */
+   virtual style::Tooltip *createTooltip (const char *text) = 0;
+
    /*
     * --------------------
     *    Image Buffers
--- a/dw/style.cc	Tue Sep 29 19:26:08 2009 +0100
+++ b/dw/style.cc	Sat Oct 03 02:22:31 2009 +0000
@@ -65,7 +65,6 @@
 void StyleAttrs::resetValues ()
 {
    x_img = -1;
-   x_tooltip = NULL;
 
    valign = VALIGN_BASELINE;
    textAlignChar = '.';
@@ -410,6 +409,11 @@
    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,
--- a/dw/style.hh	Tue Sep 29 19:26:08 2009 +0100
+++ b/dw/style.hh	Sat Oct 03 02:22:31 2009 +0000
@@ -524,19 +524,18 @@
 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 () { }
 };
 
 
--- a/src/html.cc	Tue Sep 29 19:26:08 2009 +0100
+++ b/src/html.cc	Sat Oct 03 02:22:31 2009 +0000
@@ -1944,13 +1944,17 @@
  */
 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 @@
    int space, border, w = 0, h = 0;
    bool load_now;
    CssPropertyList props;
-
-// if (prefs.show_tooltip &&
-//     (attrbuf = a_Html_get_attr(html, tag, tagsize, "title")))
-//    style_attrs->x_tooltip = a_Dw_tooltip_new_no_ref(attrbuf);
-
+   char *tooltip_str = NULL;
+
+   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 @@
    if (load_now)
       Html_load_image(html->bw, url, Image);
 
+   dFree(tooltip_str);
    dFree(width_ptr);
    dFree(height_ptr);
    dFree(alt_ptr);
--- a/src/styleengine.cc	Tue Sep 29 19:26:08 2009 +0100
+++ b/src/styleengine.cc	Sat Oct 03 02:22:31 2009 +0000
@@ -438,7 +438,9 @@
          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;
       }