From 83580696439302a7fb3111b9de4508f49d35edc8 Mon Sep 17 00:00:00 2001
From: Adam Hartford <adam.s.hartford@gmail.com>
Date: Sun, 17 Jun 2012 09:11:28 +0000
Subject: [PATCH] Italicized links on mouse over (Ticket #8555)
* Added MouseEnter and MouseLeave events.
* Added helper function to retrieve text offset positions.
* Eating mouse button events.
---
src/apps/aboutsystem/HyperTextView.cpp | 61 ++++++++++++++++++++++++++++----
src/apps/aboutsystem/HyperTextView.h | 10 +++++
2 files changed, 64 insertions(+), 7 deletions(-)
diff --git a/src/apps/aboutsystem/HyperTextView.cpp b/src/apps/aboutsystem/HyperTextView.cpp
index d1bc4e6..134ef70 100644
a
|
b
|
HyperTextAction::Clicked(HyperTextView* view, BPoint where, BMessage* message)
|
40 | 40 | } |
41 | 41 | |
42 | 42 | |
| 43 | void |
| 44 | HyperTextAction::MouseEnter(HyperTextView* view, BPoint where, |
| 45 | int32 startOffset, int32 endOffset, BMessage* message) |
| 46 | { |
| 47 | BFont font(be_plain_font); |
| 48 | font.SetFace(B_ITALIC_FACE); |
| 49 | view->SetFontAndColor(startOffset, endOffset, &font); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | void |
| 54 | HyperTextAction::MouseLeave(HyperTextView* view, BPoint where, |
| 55 | int32 startOffset, int32 endOffset, BMessage* message) |
| 56 | { |
| 57 | BFont font(be_plain_font); |
| 58 | font.SetFace(B_REGULAR_FACE); |
| 59 | view->SetFontAndColor(startOffset, endOffset, &font); |
| 60 | } |
| 61 | |
| 62 | |
43 | 63 | // #pragma mark - HyperTextView |
44 | 64 | |
45 | 65 | |
… |
… |
void
|
114 | 134 | HyperTextView::MouseDown(BPoint where) |
115 | 135 | { |
116 | 136 | // We eat all mouse button events. |
117 | | |
118 | | BTextView::MouseDown(where); |
119 | 137 | } |
120 | 138 | |
121 | 139 | |
… |
… |
HyperTextView::MouseUp(BPoint where)
|
127 | 145 | HyperTextAction* action = _ActionAt(where); |
128 | 146 | if (action != NULL) |
129 | 147 | action->Clicked(this, where, message); |
130 | | |
131 | | BTextView::MouseUp(where); |
132 | 148 | } |
133 | 149 | |
134 | 150 | |
… |
… |
HyperTextView::MouseMoved(BPoint where, uint32 transit,
|
139 | 155 | BMessage* message = Window()->CurrentMessage(); |
140 | 156 | |
141 | 157 | uint32 buttons; |
142 | | HyperTextAction* action; |
| 158 | const ActionInfo* info = _ActionInfoAt(where); |
143 | 159 | if (message->FindInt32("buttons", (int32*)&buttons) == B_OK |
144 | | && buttons == 0 && (action = _ActionAt(where)) != NULL) { |
| 160 | && buttons == 0 && info != NULL) { |
| 161 | HyperTextAction* action = info->action; |
145 | 162 | action->MouseOver(this, where, message); |
| 163 | if (fActiveInfo == NULL) { |
| 164 | fActiveInfo = info; |
| 165 | action->MouseEnter(this, where, info->startOffset, info->endOffset, |
| 166 | message); |
| 167 | } else if (fActiveInfo != info) { |
| 168 | // This is the scenario where mouse moves from one action directly |
| 169 | // into another. |
| 170 | action->MouseEnter(this, where, info->startOffset, info->endOffset, |
| 171 | message); |
| 172 | fActiveInfo->action->MouseLeave(this, where, fActiveInfo->startOffset, |
| 173 | fActiveInfo->endOffset, message); |
| 174 | fActiveInfo = info; |
| 175 | } |
146 | 176 | return; |
| 177 | } else if (fActiveInfo != NULL) { |
| 178 | fActiveInfo->action->MouseLeave(this, where, fActiveInfo->startOffset, |
| 179 | fActiveInfo->endOffset, message); |
| 180 | fActiveInfo = NULL; |
147 | 181 | } |
148 | 182 | |
149 | 183 | BTextView::MouseMoved(where, transit, dragMessage); |
… |
… |
HyperTextView::InsertHyperText(const char* inText, int32 inLength,
|
193 | 227 | HyperTextAction* |
194 | 228 | HyperTextView::_ActionAt(const BPoint& where) const |
195 | 229 | { |
| 230 | const ActionInfo* info = _ActionInfoAt(where); |
| 231 | if (info != NULL) { |
| 232 | return info->action; |
| 233 | } |
| 234 | |
| 235 | return NULL; |
| 236 | } |
| 237 | |
| 238 | |
| 239 | const HyperTextView::ActionInfo* |
| 240 | HyperTextView::_ActionInfoAt(const BPoint& where) const |
| 241 | { |
196 | 242 | int32 offset = OffsetAt(where); |
197 | 243 | |
198 | 244 | ActionInfo pointer(offset, offset + 1, NULL); |
… |
… |
HyperTextView::_ActionAt(const BPoint& where) const
|
204 | 250 | BRegion textRegion; |
205 | 251 | GetTextRegion(action->startOffset, action->endOffset, &textRegion); |
206 | 252 | if (textRegion.Contains(where)) |
207 | | return action->action; |
| 253 | return action; |
208 | 254 | } |
209 | 255 | |
210 | 256 | return NULL; |
211 | 257 | } |
212 | 258 | |
| 259 | |
diff --git a/src/apps/aboutsystem/HyperTextView.h b/src/apps/aboutsystem/HyperTextView.h
index b9d6c2a..f413e2f 100644
a
|
b
|
public:
|
24 | 24 | BMessage* message); |
25 | 25 | virtual void Clicked(HyperTextView* view, BPoint where, |
26 | 26 | BMessage* message); |
| 27 | virtual void MouseEnter(HyperTextView* view, BPoint where, |
| 28 | int32 startOffset, int32 endOffset, |
| 29 | BMessage* message); |
| 30 | virtual void MouseLeave(HyperTextView* view, BPoint where, |
| 31 | int32 startOffset, int32 endOffset, |
| 32 | BMessage* message); |
27 | 33 | }; |
28 | 34 | |
29 | 35 | |
… |
… |
private:
|
59 | 65 | class ActionInfoList; |
60 | 66 | |
61 | 67 | ActionInfoList* fActionInfos; |
| 68 | |
| 69 | const ActionInfo* _ActionInfoAt(const BPoint& where) const; |
| 70 | |
| 71 | const ActionInfo* fActiveInfo; |
62 | 72 | }; |
63 | 73 | |
64 | 74 | |