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
This commit is contained in:
Stephan Aßmus
2008-09-01 09:29:11 +00:00
parent e03fa4888e
commit 8bd8964052
2 changed files with 54 additions and 10 deletions
+48 -10
View File
@@ -5,6 +5,7 @@
#include "HyperTextView.h" #include "HyperTextView.h"
#include <Cursor.h>
#include <Message.h> #include <Message.h>
#include <Region.h> #include <Region.h>
#include <Window.h> #include <Window.h>
@@ -25,6 +26,13 @@ HyperTextAction::~HyperTextAction()
} }
void
HyperTextAction::MouseOver(HyperTextView* view, BPoint where, BMessage* message)
{
view->SetViewCursor(B_CURSOR_SYSTEM_DEFAULT);
}
void void
HyperTextAction::Clicked(HyperTextView* view, BPoint where, BMessage* message) HyperTextAction::Clicked(HyperTextView* view, BPoint where, BMessage* message)
{ {
@@ -106,19 +114,27 @@ HyperTextView::MouseUp(BPoint where)
{ {
BMessage* message = Window()->CurrentMessage(); 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, void
ActionInfo::CompareEqualIfIntersecting); HyperTextView::MouseMoved(BPoint where, uint32 transit,
if (action != NULL) { const BMessage* dragMessage)
// verify that the text region was hit {
BRegion textRegion; BMessage* message = Window()->CurrentMessage();
GetTextRegion(action->startOffset, action->endOffset, &textRegion);
if (textRegion.Contains(where)) uint32 buttons;
action->action->Clicked(this, where, message); 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); 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;
}
+6
View File
@@ -20,6 +20,8 @@ public:
HyperTextAction(); HyperTextAction();
virtual ~HyperTextAction(); virtual ~HyperTextAction();
virtual void MouseOver(HyperTextView* view, BPoint where,
BMessage* message);
virtual void Clicked(HyperTextView* view, BPoint where, virtual void Clicked(HyperTextView* view, BPoint where,
BMessage* message); BMessage* message);
}; };
@@ -35,6 +37,8 @@ public:
virtual void MouseDown(BPoint where); virtual void MouseDown(BPoint where);
virtual void MouseUp(BPoint where); virtual void MouseUp(BPoint where);
virtual void MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage);
void AddHyperTextAction(int32 startOffset, void AddHyperTextAction(int32 startOffset,
int32 endOffset, HyperTextAction* action); int32 endOffset, HyperTextAction* action);
@@ -46,6 +50,8 @@ public:
int32 inLength, HyperTextAction* action, int32 inLength, HyperTextAction* action,
const text_run_array* inRuns = NULL); const text_run_array* inRuns = NULL);
private: private:
HyperTextAction* _ActionAt(const BPoint& where) const;
struct ActionInfo; struct ActionInfo;
class ActionInfoList; class ActionInfoList;