From 8bd8964052892e8272797f1b59269e125a290af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 1 Sep 2008 09:29:11 +0000 Subject: [PATCH] Display the hand cursor over clickable URLs and other HyperTextView actions. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27263 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/aboutsystem/HyperTextView.cpp | 58 +++++++++++++++++++++----- src/apps/aboutsystem/HyperTextView.h | 6 +++ 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/apps/aboutsystem/HyperTextView.cpp b/src/apps/aboutsystem/HyperTextView.cpp index 3537c7425c..a06910810f 100644 --- a/src/apps/aboutsystem/HyperTextView.cpp +++ b/src/apps/aboutsystem/HyperTextView.cpp @@ -5,6 +5,7 @@ #include "HyperTextView.h" +#include #include #include #include @@ -25,6 +26,13 @@ HyperTextAction::~HyperTextAction() } +void +HyperTextAction::MouseOver(HyperTextView* view, BPoint where, BMessage* message) +{ + view->SetViewCursor(B_CURSOR_SYSTEM_DEFAULT); +} + + void HyperTextAction::Clicked(HyperTextView* view, BPoint where, BMessage* message) { @@ -106,19 +114,27 @@ HyperTextView::MouseUp(BPoint where) { BMessage* message = Window()->CurrentMessage(); - int32 offset = OffsetAt(where); + HyperTextAction* action = _ActionAt(where); + if (action != NULL) + action->Clicked(this, where, message); +} - ActionInfo pointer(offset, offset + 1, NULL); - const ActionInfo* action = fActionInfos->BinarySearch(pointer, - ActionInfo::CompareEqualIfIntersecting); - if (action != NULL) { - // verify that the text region was hit - BRegion textRegion; - GetTextRegion(action->startOffset, action->endOffset, &textRegion); - if (textRegion.Contains(where)) - action->action->Clicked(this, where, message); +void +HyperTextView::MouseMoved(BPoint where, uint32 transit, + const BMessage* dragMessage) +{ + BMessage* message = Window()->CurrentMessage(); + + uint32 buttons; + HyperTextAction* action; + if (message->FindInt32("buttons", (int32*)&buttons) == B_OK + && buttons == 0 && (action = _ActionAt(where)) != NULL) { + action->MouseOver(this, where, message); + return; } + + BTextView::MouseMoved(where, transit, dragMessage); } @@ -160,3 +176,25 @@ HyperTextView::InsertHyperText(const char* inText, int32 inLength, AddHyperTextAction(startOffset, endOffset, action); } + + +HyperTextAction* +HyperTextView::_ActionAt(const BPoint& where) const +{ + int32 offset = OffsetAt(where); + + ActionInfo pointer(offset, offset + 1, NULL); + + const ActionInfo* action = fActionInfos->BinarySearch(pointer, + ActionInfo::CompareEqualIfIntersecting); + if (action != NULL) { + // verify that the text region was hit + BRegion textRegion; + GetTextRegion(action->startOffset, action->endOffset, &textRegion); + if (textRegion.Contains(where)) + return action->action; + } + + return NULL; +} + diff --git a/src/apps/aboutsystem/HyperTextView.h b/src/apps/aboutsystem/HyperTextView.h index 57f5c1f669..865d256296 100644 --- a/src/apps/aboutsystem/HyperTextView.h +++ b/src/apps/aboutsystem/HyperTextView.h @@ -20,6 +20,8 @@ public: HyperTextAction(); virtual ~HyperTextAction(); + virtual void MouseOver(HyperTextView* view, BPoint where, + BMessage* message); virtual void Clicked(HyperTextView* view, BPoint where, BMessage* message); }; @@ -35,6 +37,8 @@ public: virtual void MouseDown(BPoint where); virtual void MouseUp(BPoint where); + virtual void MouseMoved(BPoint where, uint32 transit, + const BMessage* dragMessage); void AddHyperTextAction(int32 startOffset, int32 endOffset, HyperTextAction* action); @@ -46,6 +50,8 @@ public: int32 inLength, HyperTextAction* action, const text_run_array* inRuns = NULL); private: + HyperTextAction* _ActionAt(const BPoint& where) const; + struct ActionInfo; class ActionInfoList;