diff options
Diffstat (limited to 'dw')
-rw-r--r-- | dw/image.cc | 13 | ||||
-rw-r--r-- | dw/layout.cc | 104 | ||||
-rw-r--r-- | dw/layout.hh | 90 | ||||
-rw-r--r-- | dw/selection.cc | 11 | ||||
-rw-r--r-- | dw/textblock.cc | 4 | ||||
-rw-r--r-- | dw/widget.cc | 106 | ||||
-rw-r--r-- | dw/widget.hh | 114 |
7 files changed, 207 insertions, 235 deletions
diff --git a/dw/image.cc b/dw/image.cc index 4230d115..d68ef94a 100644 --- a/dw/image.cc +++ b/dw/image.cc @@ -229,7 +229,7 @@ void Image::enterNotifyImpl (core::EventCrossing *event) core::style::Tooltip *tooltip = getStyle()->x_tooltip; if (currLink != -1) { - (void) emitLinkEnter (currLink, -1, -1, -1); + (void) layout->emitLinkEnter (this, currLink, -1, -1, -1); } if (tooltip) { tooltip->onEnter(); @@ -243,7 +243,7 @@ void Image::leaveNotifyImpl (core::EventCrossing *event) if (currLink != -1) { currLink = -1; - (void) emitLinkEnter (-1, -1, -1, -1); + (void) layout->emitLinkEnter (this, -1, -1, -1, -1); } if (tooltip) { tooltip->onLeave(); @@ -286,11 +286,11 @@ bool Image::motionNotifyImpl (core::EventMotion *event) /* \todo Using MAP/AREA styles would probably be best */ setCursor(newLink == -1 ? getStyle()->cursor : core::style::CURSOR_POINTER); - (void) emitLinkEnter (newLink, -1, -1, -1); + (void) layout->emitLinkEnter (this, newLink, -1, -1, -1); } } else if (isMap && currLink != -1) { /* server-side image map */ - (void) emitLinkEnter (currLink, -1, x, y); + (void) layout->emitLinkEnter (this, currLink, -1, x, y); } } return true; @@ -303,7 +303,8 @@ bool Image::buttonPressImpl (core::EventButton *event) currLink = mapList? mapList->link (mapKey, contentX(event),contentY(event)): getStyle()->x_link; if (event->button == 3){ - (void)emitLinkPress(currLink, getStyle()->x_img, -1,-1,event); + (void)layout->emitLinkPress(this, currLink, getStyle()->x_img, -1, -1, + event); ret = true; } else if (event->button == 1 || currLink != -1){ clicking = true; @@ -320,7 +321,7 @@ bool Image::buttonReleaseImpl (core::EventButton *event) int x = isMap ? contentX(event) : -1; int y = isMap ? contentY(event) : -1; clicking = false; - emitLinkClick (currLink, getStyle()->x_img, x, y, event); + layout->emitLinkClick (this, currLink, getStyle()->x_img, x, y, event); return true; } return false; diff --git a/dw/layout.cc b/dw/layout.cc index 75598166..e1f79223 100644 --- a/dw/layout.cc +++ b/dw/layout.cc @@ -66,6 +66,110 @@ void Layout::Emitter::emitCanvasSizeChanged (int width, emitVoid (CANVAS_SIZE_CHANGED, 3, argv); } +// ---------------------------------------------------------------------- + +bool Layout::LinkReceiver::enter (Widget *widget, int link, int img, + int x, int y) +{ + return false; +} + +bool Layout::LinkReceiver::press (Widget *widget, int link, int img, + int x, int y, EventButton *event) +{ + return false; +} + +bool Layout::LinkReceiver::release (Widget *widget, int link, int img, + int x, int y, EventButton *event) +{ + return false; +} + +bool Layout::LinkReceiver::click (Widget *widget, int link, int img, + int x, int y, EventButton *event) +{ + return false; +} + +// ---------------------------------------------------------------------- + +bool Layout::LinkEmitter::emitToReceiver (lout::signal::Receiver *receiver, + int signalNo, int argc, + lout::object::Object **argv) +{ + LinkReceiver *linkReceiver = (LinkReceiver*)receiver; + + switch (signalNo) { + case ENTER: + return linkReceiver->enter ((Widget*)argv[0], + ((Integer*)argv[1])->getValue (), + ((Integer*)argv[2])->getValue (), + ((Integer*)argv[3])->getValue (), + ((Integer*)argv[4])->getValue ()); + + case PRESS: + return linkReceiver->press ((Widget*)argv[0], + ((Integer*)argv[1])->getValue (), + ((Integer*)argv[2])->getValue (), + ((Integer*)argv[3])->getValue (), + ((Integer*)argv[4])->getValue (), + (EventButton*)argv[5]); + + case RELEASE: + return linkReceiver->release ((Widget*)argv[0], + ((Integer*)argv[1])->getValue (), + ((Integer*)argv[2])->getValue (), + ((Integer*)argv[3])->getValue (), + ((Integer*)argv[4])->getValue (), + (EventButton*)argv[5]); + + case CLICK: + return linkReceiver->click ((Widget*)argv[0], + ((Integer*)argv[1])->getValue (), + ((Integer*)argv[2])->getValue (), + ((Integer*)argv[3])->getValue (), + ((Integer*)argv[4])->getValue (), + (EventButton*)argv[5]); + + default: + misc::assertNotReached (); + } + return false; +} + +bool Layout::LinkEmitter::emitEnter (Widget *widget, int link, int img, + int x, int y) +{ + Integer ilink (link), iimg (img), ix (x), iy (y); + Object *argv[5] = { widget, &ilink, &iimg, &ix, &iy }; + return emitBool (ENTER, 5, argv); +} + +bool Layout::LinkEmitter::emitPress (Widget *widget, int link, int img, + int x, int y, EventButton *event) +{ + Integer ilink (link), iimg (img), ix (x), iy (y); + Object *argv[6] = { widget, &ilink, &iimg, &ix, &iy, event }; + return emitBool (PRESS, 6, argv); +} + +bool Layout::LinkEmitter::emitRelease (Widget *widget, int link, int img, + int x, int y, EventButton *event) +{ + Integer ilink (link), iimg (img), ix (x), iy (y); + Object *argv[6] = { widget, &ilink, &iimg, &ix, &iy, event }; + return emitBool (RELEASE, 6, argv); +} + +bool Layout::LinkEmitter::emitClick (Widget *widget, int link, int img, + int x, int y, EventButton *event) +{ + Integer ilink (link), iimg (img), ix (x), iy (y); + Object *argv[6] = { widget, &ilink, &iimg, &ix, &iy, event }; + return emitBool (CLICK, 6, argv); +} + // --------------------------------------------------------------------- Layout::Anchor::~Anchor () diff --git a/dw/layout.hh b/dw/layout.hh index bfc61afd..39311c38 100644 --- a/dw/layout.hh +++ b/dw/layout.hh @@ -29,6 +29,78 @@ public: virtual void canvasSizeChanged (int width, int ascent, int descent); }; + class LinkReceiver: public lout::signal::Receiver + { + public: + /** + * \brief Called, when a link is entered, left, or the position has + * changed. + * + * When a link is entered, this method is called with the respective + * arguments. When a link is left, this method is called with all + * three arguments (\em link, \em x, \em y) set to -1. + * + * When coordinates are supported, a change of the coordinates also + * causes emitting this signal. + */ + virtual bool enter (Widget *widget, int link, int img, int x, int y); + + /** + * \brief Called, when the user has pressed the mouse button on a + * link (but not yet released). + * + * The causing event is passed as \em event. + */ + virtual bool press (Widget *widget, int link, int img, int x, int y, + EventButton *event); + + /** + * \brief Called, when the user has released the mouse button on a + * link. + * + * The causing event is passed as \em event. + */ + virtual bool release (Widget *widget, int link, int img, int x, int y, + EventButton *event); + + /** + * \brief Called, when the user has clicked on a link. + * + * For mouse interaction, this is equivalent to "press" and "release" + * on the same link. In this case, \em event contains the "release" + * event. + * + * + * When activating links via keyboard is supported, only a "clicked" + * signal will be emitted, and \em event will be NULL. + */ + virtual bool click (Widget *widget, int link, int img, int x, int y, + EventButton *event); + }; + + class LinkEmitter: public lout::signal::Emitter + { + private: + enum { ENTER, PRESS, RELEASE, CLICK }; + + protected: + bool emitToReceiver (lout::signal::Receiver *receiver, int signalNo, + int argc, lout::object::Object **argv); + + public: + inline void connectLink (LinkReceiver *receiver) { connect (receiver); } + + bool emitEnter (Widget *widget, int link, int img, int x, int y); + bool emitPress (Widget *widget, int link, int img, int x, int y, + EventButton *event); + bool emitRelease (Widget *widget, int link, int img, int x, int y, + EventButton *event); + bool emitClick (Widget *widget, int link, int img, int x, int y, + EventButton *event); + }; + + LinkEmitter linkEmitter; + private: class Emitter: public lout::signal::Emitter { @@ -141,6 +213,24 @@ public: Layout (Platform *platform); ~Layout (); + inline void connectLink (LinkReceiver *receiver) + { linkEmitter.connectLink (receiver); } + + inline bool emitLinkEnter (Widget *w, int link, int img, int x, int y) + { return linkEmitter.emitEnter (w, link, img, x, y); } + + inline bool emitLinkPress (Widget *w, int link, int img, + int x, int y, EventButton *event) + { return linkEmitter.emitPress (w, link, img, x, y, event); } + + inline bool emitLinkRelease (Widget *w, int link, int img, + int x, int y, EventButton *event) + { return linkEmitter.emitRelease (w, link, img, x, y, event); } + + inline bool emitLinkClick (Widget *w, int link, int img, + int x, int y, EventButton *event) + { return linkEmitter.emitClick (w, link, img, x, y, event); } + lout::misc::ZoneAllocator *textZone; void addWidget (Widget *widget); diff --git a/dw/selection.cc b/dw/selection.cc index 08d3bf00..275eddaa 100644 --- a/dw/selection.cc +++ b/dw/selection.cc @@ -118,8 +118,7 @@ bool SelectionState::buttonPress (Iterator *it, int charPos, int linkNo, if (linkNo != -1) { // link handling if (event) { - // return value is ignored - itWidget->emitLinkPress (linkNo, -1, -1, -1, event); + (void) layout->emitLinkPress (itWidget, linkNo, -1, -1, -1, event); resetLink (); linkState = LINK_PRESSED; linkButton = event->button; @@ -162,7 +161,7 @@ bool SelectionState::buttonPress (Iterator *it, int charPos, int linkNo, } else { if (event && event->button == 3) { // menu popup - itWidget->emitLinkPress (-1, -1, -1, -1, event); + layout->emitLinkPress (itWidget, -1, -1, -1, -1, event); ret = true; } } @@ -182,14 +181,12 @@ bool SelectionState::buttonRelease (Iterator *it, int charPos, int linkNo, // link handling ret = true; if (linkNo != -1) - // return value is ignored - itWidget->emitLinkRelease (linkNo, -1, -1, -1, event); + (void) layout->emitLinkRelease (itWidget, linkNo, -1, -1, -1, event); // The link where the user clicked the mouse button? if (linkNo == linkNumber) { resetLink (); - // return value is ignored - itWidget->emitLinkClick (linkNo, -1, -1, -1, event); + (void) layout->emitLinkClick (itWidget, linkNo, -1, -1, -1, event); } else { if (event->button == 1) // Reset links and switch to selection mode. The selection diff --git a/dw/textblock.cc b/dw/textblock.cc index 365d9b14..13709042 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -548,7 +548,7 @@ bool Textblock::motionNotifyImpl (core::EventMotion *event) hoverTooltip->onMotion (); if (hoverLink != linkOld) - return emitLinkEnter (hoverLink, -1, -1, -1); + return layout->emitLinkEnter (this, hoverLink, -1, -1, -1); else return hoverLink != -1; } @@ -561,7 +561,7 @@ void Textblock::enterNotifyImpl (core::EventCrossing *event) void Textblock::leaveNotifyImpl (core::EventCrossing *event) { hoverLink = -1; - (void) emitLinkEnter (hoverLink, -1, -1, -1); + (void) layout->emitLinkEnter (this, hoverLink, -1, -1, -1); if (hoverTooltip) { hoverTooltip->onLeave(); hoverTooltip = NULL; diff --git a/dw/widget.cc b/dw/widget.cc index 0555b571..531a25f3 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -127,112 +127,6 @@ void Widget::EventEmitter::emitLeaveNotify (Widget *widget, // ---------------------------------------------------------------------- -bool Widget::LinkReceiver::enter (Widget *widget, int link, int img, - int x, int y) -{ - return false; -} - -bool Widget::LinkReceiver::press (Widget *widget, int link, int img, - int x, int y, EventButton *event) -{ - return false; -} - -bool Widget::LinkReceiver::release (Widget *widget, int link, int img, - int x, int y, EventButton *event) -{ - return false; -} - -bool Widget::LinkReceiver::click (Widget *widget, int link, int img, - int x, int y, EventButton *event) -{ - return false; -} - - -bool Widget::LinkEmitter::emitToReceiver (lout::signal::Receiver *receiver, - int signalNo, int argc, - lout::object::Object **argv) -{ - LinkReceiver *linkReceiver = (LinkReceiver*)receiver; - - switch (signalNo) { - case ENTER: - return linkReceiver->enter ((Widget*)argv[0], - ((Integer*)argv[1])->getValue (), - ((Integer*)argv[2])->getValue (), - ((Integer*)argv[3])->getValue (), - ((Integer*)argv[4])->getValue ()); - - case PRESS: - return linkReceiver->press ((Widget*)argv[0], - ((Integer*)argv[1])->getValue (), - ((Integer*)argv[2])->getValue (), - ((Integer*)argv[3])->getValue (), - ((Integer*)argv[4])->getValue (), - (EventButton*)argv[5]); - - case RELEASE: - return linkReceiver->release ((Widget*)argv[0], - ((Integer*)argv[1])->getValue (), - ((Integer*)argv[2])->getValue (), - ((Integer*)argv[3])->getValue (), - ((Integer*)argv[4])->getValue (), - (EventButton*)argv[5]); - - case CLICK: - return linkReceiver->click ((Widget*)argv[0], - ((Integer*)argv[1])->getValue (), - ((Integer*)argv[2])->getValue (), - ((Integer*)argv[3])->getValue (), - ((Integer*)argv[4])->getValue (), - (EventButton*)argv[5]); - - default: - misc::assertNotReached (); - } - - /* Compiler happiness. */ - return false; -} - -bool Widget::LinkEmitter::emitEnter (Widget *widget, int link, int img, - int x, int y) -{ - Integer ilink (link), iimg (img), ix (x), iy (y); - Object *argv[5] = { widget, &ilink, &iimg, &ix, &iy }; - return emitBool (ENTER, 5, argv); -} - -bool Widget::LinkEmitter::emitPress (Widget *widget, int link, int img, - int x, int y, EventButton *event) -{ - Integer ilink (link), iimg (img), ix (x), iy (y); - Object *argv[6] = { widget, &ilink, &iimg, &ix, &iy, event }; - return emitBool (PRESS, 6, argv); -} - -bool Widget::LinkEmitter::emitRelease (Widget *widget, int link, int img, - int x, int y, EventButton *event) -{ - Integer ilink (link), iimg (img), ix (x), iy (y); - Object *argv[6] = { widget, &ilink, &iimg, &ix, &iy, event }; - return emitBool (RELEASE, 6, argv); -} - -bool Widget::LinkEmitter::emitClick (Widget *widget, int link, int img, - int x, int y, EventButton *event) -{ - Integer ilink (link), iimg (img), ix (x), iy (y); - Object *argv[6] = { widget, &ilink, &iimg, &ix, &iy, event }; - return emitBool (CLICK, 6, argv); -} - - -// ---------------------------------------------------------------------- - int Widget::CLASS_ID = -1; Widget::Widget () diff --git a/dw/widget.hh b/dw/widget.hh index 56f115f6..b21415bb 100644 --- a/dw/widget.hh +++ b/dw/widget.hh @@ -35,80 +35,6 @@ public: virtual void leaveNotify (Widget *widget, EventCrossing *event); }; - /** - * \brief This receiver is for signals related to HTML pages. - * - * The \em link argument to all signals defines a number, which has - * been passed before, e.g. by setting dw::core::style::Style::x_link. - * When defining this number (e.g in dw::core::style::Style::x_link), - * and when receiving the signal, the caller must interpret these numbers - * in a consistent way. In the HTML link block, this number is an index - * to an array of URLs. - * - * \em link = -1 represents an undefined link. - * - * The \em img argument to all signals defines a number which has - * been passed before, e.g. by setting dw::core::style::Style::x_img. - * When defining this number (e.g in dw::core::style::Style::x_img), - * and when receiving the signal, the caller must interpret these numbers - * in a consistent way. In the HTML link block, this number is an index - * to an array of structures containing image information. - * - * \em img = -1 represents an undefined image. - * - * \em x and \em y define the coordinates within the link area. They are - * only used for server-side image maps, see dw::Image. - * - * \sa dw::Image, dw::Textblock - */ - class LinkReceiver: public lout::signal::Receiver - { - public: - /** - * \brief Called, when a link is entered, left, or the position has - * changed. - * - * When a link is entered, this method is called with the respective - * arguments. When a link is left, this method is called with all - * three arguments (\em link, \em x, \em y) set to -1. - * - * When coordinates are supported, a change of the coordinates also - * causes emitting this signal. - */ - virtual bool enter (Widget *widget, int link, int img, int x, int y); - - /** - * \brief Called, when the user has pressed the mouse button on a - * link (but not yet released). - * - * The causing event is passed as \em event. - */ - virtual bool press (Widget *widget, int link, int img, int x, int y, - EventButton *event); - - /** - * \brief Called, when the user has released the mouse button on a - * link. - * - * The causing event is passed as \em event. - */ - virtual bool release (Widget *widget, int link, int img, int x, int y, - EventButton *event); - - /** - * \brief Called, when the user has clicked on a link. - * - * For mouse interaction, this is equivalent to "press" and "release" - * on the same link. In this case, \em event contains the "release" - * event. - * - * When activating links via keyboard is supported, only a "clicked" - * signal will be emitted, and \em event will be NULL. - */ - virtual bool click (Widget *widget, int link, int img, int x, int y, - EventButton *event); - }; - private: class EventEmitter: public lout::signal::Emitter { @@ -131,27 +57,6 @@ private: void emitLeaveNotify (Widget *widget, EventCrossing *event); }; - class LinkEmitter: public lout::signal::Emitter - { - private: - enum { ENTER, PRESS, RELEASE, CLICK }; - - protected: - bool emitToReceiver (lout::signal::Receiver *receiver, int signalNo, - int argc, lout::object::Object **argv); - - public: - inline void connectLink (LinkReceiver *receiver) { connect (receiver); } - - bool emitEnter (Widget *widget, int link, int img, int x, int y); - bool emitPress (Widget *widget, int link, int img, int x, int y, - EventButton *event); - bool emitRelease (Widget *widget, int link, int img, int x, int y, - EventButton *event); - bool emitClick (Widget *widget, int link, int img, int x, int y, - EventButton *event); - }; - EventEmitter eventEmitter; style::Style *style; @@ -248,7 +153,6 @@ public: int parentRef; protected: - LinkEmitter linkEmitter; /** * \brief The current allocation: size and position, always relative to the @@ -373,24 +277,6 @@ public: inline void connectEvent (EventReceiver *receiver) { eventEmitter.connectEvent (receiver); } - inline void connectLink (LinkReceiver *receiver) - { linkEmitter.connectLink (receiver); } - - inline bool emitLinkEnter (int link, int img, int x, int y) - { return linkEmitter.emitEnter (this, link, img, x, y); } - - inline bool emitLinkPress (int link, int img, - int x, int y, EventButton *event) - { return linkEmitter.emitPress (this, link, img, x, y, event); } - - inline bool emitLinkRelease (int link, int img, - int x, int y, EventButton *event) - { return linkEmitter.emitRelease (this, link, img, x, y, event); } - - inline bool emitLinkClick (int link, int img, - int x, int y, EventButton *event) - { return linkEmitter.emitClick (this, link, img, x, y, event); } - inline bool usesHints () { return flags & USES_HINTS; } inline bool hasContents () { return flags & HAS_CONTENTS; } |