AboutSystem: underline links on mouse over
Fixes #8555. Change-Id: Ib5ba32625062b6b3c180e8082e634fba9e8a70ec Reviewed-on: https://review.haiku-os.org/c/haiku/+/2364 Reviewed-by: Adrien Destugues <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
ef83008e79
commit
758dae382b
@@ -27,10 +27,30 @@ HyperTextAction::~HyperTextAction()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
HyperTextAction::MouseOver(HyperTextView* view, BPoint where, BMessage* message)
|
HyperTextAction::MouseOver(HyperTextView* view, BPoint where, int32 startOffset,
|
||||||
|
int32 endOffset, BMessage* message)
|
||||||
{
|
{
|
||||||
BCursor linkCursor(B_CURSOR_ID_FOLLOW_LINK);
|
BCursor linkCursor(B_CURSOR_ID_FOLLOW_LINK);
|
||||||
view->SetViewCursor(&linkCursor);
|
view->SetViewCursor(&linkCursor);
|
||||||
|
|
||||||
|
BFont font;
|
||||||
|
view->GetFont(&font);
|
||||||
|
font.SetFace(B_UNDERSCORE_FACE);
|
||||||
|
view->SetFontAndColor(startOffset, endOffset, &font, B_FONT_FACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
HyperTextAction::MouseAway(HyperTextView* view, BPoint where, int32 startOffset,
|
||||||
|
int32 endOffset, BMessage* message)
|
||||||
|
{
|
||||||
|
BCursor linkCursor(B_CURSOR_ID_SYSTEM_DEFAULT);
|
||||||
|
view->SetViewCursor(&linkCursor);
|
||||||
|
|
||||||
|
BFont font;
|
||||||
|
view->GetFont(&font);
|
||||||
|
font.SetFace(B_REGULAR_FACE);
|
||||||
|
view->SetFontAndColor(startOffset, endOffset, &font, B_FONT_FACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -90,7 +110,8 @@ public:
|
|||||||
HyperTextView::HyperTextView(const char* name, uint32 flags)
|
HyperTextView::HyperTextView(const char* name, uint32 flags)
|
||||||
:
|
:
|
||||||
BTextView(name, flags),
|
BTextView(name, flags),
|
||||||
fActionInfos(new ActionInfoList(100, true))
|
fActionInfos(new ActionInfoList(100, true)),
|
||||||
|
fLastActionInfo(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +120,8 @@ HyperTextView::HyperTextView(BRect frame, const char* name, BRect textRect,
|
|||||||
uint32 resizeMask, uint32 flags)
|
uint32 resizeMask, uint32 flags)
|
||||||
:
|
:
|
||||||
BTextView(frame, name, textRect, resizeMask, flags),
|
BTextView(frame, name, textRect, resizeMask, flags),
|
||||||
fActionInfos(new ActionInfoList(100, true))
|
fActionInfos(new ActionInfoList(100, true)),
|
||||||
|
fLastActionInfo(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,15 +160,37 @@ HyperTextView::MouseMoved(BPoint where, uint32 transit,
|
|||||||
{
|
{
|
||||||
BMessage* message = Window()->CurrentMessage();
|
BMessage* message = Window()->CurrentMessage();
|
||||||
|
|
||||||
uint32 buttons;
|
|
||||||
HyperTextAction* action;
|
HyperTextAction* action;
|
||||||
if (message->FindInt32("buttons", (int32*)&buttons) == B_OK
|
const ActionInfo* actionInfo = _ActionInfoAt(where);
|
||||||
&& buttons == 0 && (action = _ActionAt(where)) != NULL) {
|
if (actionInfo != fLastActionInfo) {
|
||||||
action->MouseOver(this, where, message);
|
// We moved to a different "action" zone, de-highlight the previous one
|
||||||
return;
|
if (fLastActionInfo != NULL) {
|
||||||
|
action = fLastActionInfo->action;
|
||||||
|
if (action != NULL) {
|
||||||
|
action->MouseAway(this, where, fLastActionInfo->startOffset,
|
||||||
|
fLastActionInfo->endOffset, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ... and highlight the new one
|
||||||
|
if (actionInfo != NULL) {
|
||||||
|
action = actionInfo->action;
|
||||||
|
if (action != NULL) {
|
||||||
|
action->MouseOver(this, where, actionInfo->startOffset,
|
||||||
|
actionInfo->endOffset, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fLastActionInfo = actionInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
BTextView::MouseMoved(where, transit, dragMessage);
|
int32 buttons = 0;
|
||||||
|
message->FindInt32("buttons", (int32*)&buttons);
|
||||||
|
if (actionInfo == NULL || buttons != 0) {
|
||||||
|
// This will restore the default mouse pointer, so do it only when not
|
||||||
|
// hovering a link, or when clicking
|
||||||
|
BTextView::MouseMoved(where, transit, dragMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -190,8 +234,8 @@ HyperTextView::InsertHyperText(const char* inText, int32 inLength,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HyperTextAction*
|
const HyperTextView::ActionInfo*
|
||||||
HyperTextView::_ActionAt(const BPoint& where) const
|
HyperTextView::_ActionInfoAt(const BPoint& where) const
|
||||||
{
|
{
|
||||||
int32 offset = OffsetAt(where);
|
int32 offset = OffsetAt(where);
|
||||||
|
|
||||||
@@ -199,6 +243,15 @@ HyperTextView::_ActionAt(const BPoint& where) const
|
|||||||
|
|
||||||
const ActionInfo* action = fActionInfos->BinarySearch(pointer,
|
const ActionInfo* action = fActionInfos->BinarySearch(pointer,
|
||||||
ActionInfo::CompareEqualIfIntersecting);
|
ActionInfo::CompareEqualIfIntersecting);
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
HyperTextAction*
|
||||||
|
HyperTextView::_ActionAt(const BPoint& where) const
|
||||||
|
{
|
||||||
|
const ActionInfo* action = _ActionInfoAt(where);
|
||||||
|
|
||||||
if (action != NULL) {
|
if (action != NULL) {
|
||||||
// verify that the text region was hit
|
// verify that the text region was hit
|
||||||
BRegion textRegion;
|
BRegion textRegion;
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ public:
|
|||||||
virtual ~HyperTextAction();
|
virtual ~HyperTextAction();
|
||||||
|
|
||||||
virtual void MouseOver(HyperTextView* view, BPoint where,
|
virtual void MouseOver(HyperTextView* view, BPoint where,
|
||||||
|
int32 startOffset, int32 endOffset,
|
||||||
|
BMessage* message);
|
||||||
|
virtual void MouseAway(HyperTextView* view, BPoint where,
|
||||||
|
int32 startOffset, int32 endOffset,
|
||||||
BMessage* message);
|
BMessage* message);
|
||||||
virtual void Clicked(HyperTextView* view, BPoint where,
|
virtual void Clicked(HyperTextView* view, BPoint where,
|
||||||
BMessage* message);
|
BMessage* message);
|
||||||
@@ -53,12 +57,15 @@ 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;
|
||||||
|
|
||||||
|
HyperTextAction* _ActionAt(const BPoint& where) const;
|
||||||
|
const ActionInfo* _ActionInfoAt(const BPoint& where) const;
|
||||||
|
|
||||||
|
private:
|
||||||
ActionInfoList* fActionInfos;
|
ActionInfoList* fActionInfos;
|
||||||
|
const ActionInfo* fLastActionInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user