aboutsummaryrefslogtreecommitdiff
path: root/dw
diff options
context:
space:
mode:
Diffstat (limited to 'dw')
-rw-r--r--dw/fltkplatform.cc46
-rw-r--r--dw/fltkplatform.hh15
-rw-r--r--dw/image.cc8
-rw-r--r--dw/layout.hh5
-rw-r--r--dw/platform.hh5
-rw-r--r--dw/style.cc6
-rw-r--r--dw/style.hh11
7 files changed, 89 insertions, 7 deletions
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 () { }
};