From 86286ac373c9d3e1ec36638a973a16007e4d4479 Mon Sep 17 00:00:00 2001
From: Sambuddha Basu <sambuddhabasu1@gmail.com>
Date: Wed, 4 Feb 2015 15:11:24 +0530
Subject: [PATCH] Ticket 8555 Underline links on mouse over. B_UNDERSCORE_FACE
is not implemented so B_ITALIC_FACE has been used
Made required changes according to the coding guidelines
---
src/apps/aboutsystem/HyperTextView.cpp | 60 +++++++++++++++++++++++++++++-----
src/apps/aboutsystem/HyperTextView.h | 7 ++++
2 files changed, 58 insertions(+), 9 deletions(-)
diff --git a/src/apps/aboutsystem/HyperTextView.cpp b/src/apps/aboutsystem/HyperTextView.cpp
index d1bc4e6..f7a0fc3 100644
a
|
b
|
HyperTextAction::~HyperTextAction()
|
27 | 27 | |
28 | 28 | |
29 | 29 | void |
30 | | HyperTextAction::MouseOver(HyperTextView* view, BPoint where, BMessage* message) |
| 30 | HyperTextAction::MouseOver(HyperTextView* view, BPoint where, int32 startOffset, |
| 31 | int32 endOffset, BMessage* message) |
31 | 32 | { |
32 | 33 | BCursor linkCursor(B_CURSOR_ID_FOLLOW_LINK); |
33 | 34 | view->SetViewCursor(&linkCursor); |
| 35 | |
| 36 | BFont font; |
| 37 | view->GetFont(&font); |
| 38 | font.SetFace(B_ITALIC_FACE); |
| 39 | view->SetFontAndColor(startOffset, endOffset, &font, B_FONT_FACE); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | void |
| 44 | HyperTextAction::MouseAway(HyperTextView* view, BPoint where, int32 startOffset, |
| 45 | int32 endOffset, BMessage* message) |
| 46 | { |
| 47 | BFont font(be_plain_font); |
| 48 | view->SetFontAndColor(startOffset, endOffset, &font, B_FONT_FACE); |
34 | 49 | } |
35 | 50 | |
36 | 51 | |
… |
… |
HyperTextView::HyperTextView(const char* name, uint32 flags)
|
92 | 107 | BTextView(name, flags), |
93 | 108 | fActionInfos(new ActionInfoList(100, true)) |
94 | 109 | { |
| 110 | this->fLastActionInfo = NULL; |
95 | 111 | } |
96 | 112 | |
97 | 113 | |
… |
… |
HyperTextView::HyperTextView(BRect frame, const char* name, BRect textRect,
|
101 | 117 | BTextView(frame, name, textRect, resizeMask, flags), |
102 | 118 | fActionInfos(new ActionInfoList(100, true)) |
103 | 119 | { |
| 120 | this->fLastActionInfo = NULL; |
104 | 121 | } |
105 | 122 | |
106 | 123 | |
… |
… |
HyperTextView::MouseMoved(BPoint where, uint32 transit,
|
140 | 157 | |
141 | 158 | uint32 buttons; |
142 | 159 | HyperTextAction* action; |
143 | | if (message->FindInt32("buttons", (int32*)&buttons) == B_OK |
144 | | && buttons == 0 && (action = _ActionAt(where)) != NULL) { |
145 | | action->MouseOver(this, where, message); |
146 | | return; |
| 160 | const ActionInfo* actionInfo; |
| 161 | actionInfo = this->fLastActionInfo; |
| 162 | if (actionInfo != NULL) { |
| 163 | action = actionInfo->action; |
| 164 | if (action != NULL) { |
| 165 | action->MouseAway(this, where, actionInfo->startOffset, |
| 166 | actionInfo->endOffset, message); |
| 167 | this->fLastActionInfo = NULL; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | actionInfo = _ActionInfoAt(where); |
| 172 | if (actionInfo != NULL) { |
| 173 | action = actionInfo->action; |
| 174 | if (message->FindInt32("buttons", (int32*)&buttons) == B_OK |
| 175 | && buttons == 0 && action != NULL) { |
| 176 | this->fLastActionInfo = actionInfo; |
| 177 | action->MouseOver(this, where, actionInfo->startOffset, |
| 178 | actionInfo->endOffset, message); |
| 179 | return; |
| 180 | } |
147 | 181 | } |
148 | 182 | |
149 | 183 | BTextView::MouseMoved(where, transit, dragMessage); |
… |
… |
HyperTextView::InsertHyperText(const char* inText, int32 inLength,
|
190 | 224 | } |
191 | 225 | |
192 | 226 | |
193 | | HyperTextAction* |
194 | | HyperTextView::_ActionAt(const BPoint& where) const |
| 227 | const HyperTextView::ActionInfo* |
| 228 | HyperTextView::_ActionInfoAt(const BPoint& where) const |
195 | 229 | { |
196 | 230 | int32 offset = OffsetAt(where); |
197 | 231 | |
198 | 232 | ActionInfo pointer(offset, offset + 1, NULL); |
199 | 233 | |
200 | | const ActionInfo* action = fActionInfos->BinarySearch(pointer, |
| 234 | const ActionInfo* action = fActionInfos->BinarySearch(pointer, |
201 | 235 | ActionInfo::CompareEqualIfIntersecting); |
| 236 | return action; |
| 237 | } |
| 238 | |
| 239 | |
| 240 | HyperTextAction* |
| 241 | HyperTextView::_ActionAt(const BPoint& where) const |
| 242 | { |
| 243 | const ActionInfo* action = _ActionInfoAt(where); |
| 244 | |
202 | 245 | if (action != NULL) { |
203 | 246 | // verify that the text region was hit |
204 | 247 | BRegion textRegion; |
… |
… |
HyperTextView::_ActionAt(const BPoint& where) const
|
209 | 252 | |
210 | 253 | return NULL; |
211 | 254 | } |
212 | | |
diff --git a/src/apps/aboutsystem/HyperTextView.h b/src/apps/aboutsystem/HyperTextView.h
index b9d6c2a..0d8e66d 100644
a
|
b
|
public:
|
21 | 21 | virtual ~HyperTextAction(); |
22 | 22 | |
23 | 23 | virtual void MouseOver(HyperTextView* view, BPoint where, |
| 24 | int32 startOffset, int32 endOffset, |
| 25 | BMessage* message); |
| 26 | void MouseAway(HyperTextView* view, BPoint where, |
| 27 | int32 startOffset, int32 endOffset, |
24 | 28 | BMessage* message); |
25 | 29 | virtual void Clicked(HyperTextView* view, BPoint where, |
26 | 30 | BMessage* message); |
… |
… |
private:
|
58 | 62 | struct ActionInfo; |
59 | 63 | class ActionInfoList; |
60 | 64 | |
| 65 | const ActionInfo* _ActionInfoAt(const BPoint& where) const; |
| 66 | |
61 | 67 | ActionInfoList* fActionInfos; |
| 68 | const ActionInfo* fLastActionInfo; |
62 | 69 | }; |
63 | 70 | |
64 | 71 | |