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

View File

@ -5,6 +5,7 @@
#include "HyperTextView.h"
#include <Cursor.h>
#include <Message.h>
#include <Region.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
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;
}

View File

@ -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;