Ticket #8555: ticket_8555.patch
File ticket_8555.patch, 16.8 KB (added by , 12 years ago) |
---|
-
src/apps/aboutsystem/HyperTextView.cpp
From 8d33f35cb56c4791d97fa925de088ef14eeff3f7 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 1/5] Italicized links on mouse over (Ticket #8555) * Added MouseEnter and MouseLeave events. * Added helper function to retrieve text offset positions. * Eating mouse button events. Signed-off-by: Adam Hartford <adam.s.hartford@gmail.com> --- 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 -
src/apps/aboutsystem/HyperTextView.h
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 -
src/apps/aboutsystem/HyperTextActions.cpp
-- 1.7.7.2 From 05beb8fd3ecc569b6bab23c8f35b78af9d205d74 Mon Sep 17 00:00:00 2001 From: Adam Hartford <adam.s.hartford@gmail.com> Date: Sat, 30 Jun 2012 09:57:34 -0400 Subject: [PATCH 2/5] Underline links. Lines drawn manually. (Ticket #8555) --- src/apps/aboutsystem/HyperTextActions.cpp | 20 +++++++++++++ src/apps/aboutsystem/HyperTextActions.h | 4 +++ src/apps/aboutsystem/HyperTextView.cpp | 43 +++++++++++++++++++++++------ src/apps/aboutsystem/HyperTextView.h | 6 +++- 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/apps/aboutsystem/HyperTextActions.cpp b/src/apps/aboutsystem/HyperTextActions.cpp index 5c8770c..498a1fc 100644
a b 10 10 #include <Roster.h> 11 11 12 12 13 static const rgb_color kDarkGrey = { 100, 100, 100, 255 }; 14 static const rgb_color kLinkBlue = { 80, 80, 200, 255 }; 15 16 13 17 // #pragma mark - URLAction 14 18 15 19 … … URLAction::Clicked(HyperTextView* view, BPoint where, BMessage* message) 39 43 } 40 44 41 45 46 const rgb_color 47 URLAction::GetUnderlineColor() 48 { 49 return kLinkBlue; 50 } 51 52 42 53 // #pragma mark - OpenFileAction 43 54 44 55 … … OpenFileAction::Clicked(HyperTextView* view, BPoint where, BMessage* message) 72 83 } else 73 84 be_roster->Launch(&ref); 74 85 } 86 87 88 const rgb_color 89 OpenFileAction::GetUnderlineColor() 90 { 91 return kDarkGrey; 92 } 93 94 -
src/apps/aboutsystem/HyperTextActions.h
diff --git a/src/apps/aboutsystem/HyperTextActions.h b/src/apps/aboutsystem/HyperTextActions.h index 4f32b38..4bd2819 100644
a b public: 17 17 18 18 virtual void Clicked(HyperTextView* view, BPoint where, 19 19 BMessage* message); 20 21 virtual const rgb_color GetUnderlineColor(); 20 22 private: 21 23 BString fURL; 22 24 }; … … public: 29 31 30 32 virtual void Clicked(HyperTextView* view, BPoint where, 31 33 BMessage* message); 34 35 virtual const rgb_color GetUnderlineColor(); 32 36 private: 33 37 BString fFile; 34 38 }; -
src/apps/aboutsystem/HyperTextView.cpp
diff --git a/src/apps/aboutsystem/HyperTextView.cpp b/src/apps/aboutsystem/HyperTextView.cpp index 134ef70..dc33d09 100644
a b 16 16 // #pragma mark - HyperTextAction 17 17 18 18 19 static const rgb_color kDarkGrey = { 100, 100, 100, 255 }; 20 21 19 22 HyperTextAction::HyperTextAction() 20 23 { 21 24 } … … HyperTextAction::MouseEnter(HyperTextView* view, BPoint where, 45 48 int32 startOffset, int32 endOffset, BMessage* message) 46 49 { 47 50 BFont font(be_plain_font); 48 font.SetFace(B_ ITALIC_FACE);51 font.SetFace(B_UNDERSCORE_FACE); 49 52 view->SetFontAndColor(startOffset, endOffset, &font); 50 53 } 51 54 … … HyperTextAction::MouseLeave(HyperTextView* view, BPoint where, 57 60 BFont font(be_plain_font); 58 61 font.SetFace(B_REGULAR_FACE); 59 62 view->SetFontAndColor(startOffset, endOffset, &font); 60 } 63 } 64 65 const rgb_color 66 HyperTextAction::GetUnderlineColor() 67 { 68 return kDarkGrey; 69 } 61 70 62 71 63 72 // #pragma mark - HyperTextView … … HyperTextView::~HyperTextView() 131 140 132 141 133 142 void 143 HyperTextView::Draw(BRect updateRect) 144 { 145 // TODO: Remove code to draw lines once B_UNDERSCORE_FACE is working. 146 147 BTextView::Draw(updateRect); 148 149 if (fActiveInfo != NULL) { 150 BRegion textRegion; 151 GetTextRegion(fActiveInfo->startOffset, fActiveInfo->endOffset, 152 &textRegion); 153 154 BRect frame = textRegion.Frame(); 155 SetHighColor(fActiveInfo->action->GetUnderlineColor()); 156 StrokeLine(frame.LeftBottom(), frame.RightBottom()); 157 } 158 } 159 160 161 void 134 162 HyperTextView::MouseDown(BPoint where) 135 163 { 136 164 // We eat all mouse button events. … … HyperTextView::MouseMoved(BPoint where, uint32 transit, 167 195 } else if (fActiveInfo != info) { 168 196 // This is the scenario where mouse moves from one action directly 169 197 // into another. 170 action->MouseEnter(this, where, info->startOffset, info->endOffset,171 message);172 198 fActiveInfo->action->MouseLeave(this, where, fActiveInfo->startOffset, 173 199 fActiveInfo->endOffset, message); 174 fActiveInfo = info; 200 action->MouseEnter(this, where, info->startOffset, info->endOffset, 201 message); 202 fActiveInfo = info; 175 203 } 176 204 return; 177 205 } else if (fActiveInfo != NULL) { … … HyperTextAction* 228 256 HyperTextView::_ActionAt(const BPoint& where) const 229 257 { 230 258 const ActionInfo* info = _ActionInfoAt(where); 231 if (info != NULL) {259 if (info != NULL) 232 260 return info->action; 233 }234 261 235 262 return NULL; 236 263 } … … HyperTextView::_ActionInfoAt(const BPoint& where) const 255 282 256 283 return NULL; 257 284 } 258 259 -
src/apps/aboutsystem/HyperTextView.h
diff --git a/src/apps/aboutsystem/HyperTextView.h b/src/apps/aboutsystem/HyperTextView.h index f413e2f..d702a81 100644
a b public: 30 30 virtual void MouseLeave(HyperTextView* view, BPoint where, 31 31 int32 startOffset, int32 endOffset, 32 32 BMessage* message); 33 virtual const rgb_color GetUnderlineColor(); 33 34 }; 34 35 35 36 … … public: 44 45 | B_PULSE_NEEDED); 45 46 virtual ~HyperTextView(); 46 47 48 virtual void Draw(BRect udateRect); 47 49 virtual void MouseDown(BPoint where); 48 50 virtual void MouseUp(BPoint where); 49 51 virtual void MouseMoved(BPoint where, uint32 transit, … … private: 65 67 class ActionInfoList; 66 68 67 69 ActionInfoList* fActionInfos; 68 70 69 71 const ActionInfo* _ActionInfoAt(const BPoint& where) const; 70 72 71 73 const ActionInfo* fActiveInfo; 72 74 }; 73 75 -
src/apps/aboutsystem/HyperTextView.h
-- 1.7.7.2 From 500b567d165098084b0eb2d0688adf7266d603ad Mon Sep 17 00:00:00 2001 From: Adam Hartford <adam.s.hartford@gmail.com> Date: Sat, 30 Jun 2012 10:11:33 -0400 Subject: [PATCH 3/5] Fixed typo: udateRect to updateRect. --- src/apps/aboutsystem/HyperTextView.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/apps/aboutsystem/HyperTextView.h b/src/apps/aboutsystem/HyperTextView.h index d702a81..320261d 100644
a b public: 45 45 | B_PULSE_NEEDED); 46 46 virtual ~HyperTextView(); 47 47 48 virtual void Draw(BRect u dateRect);48 virtual void Draw(BRect updateRect); 49 49 virtual void MouseDown(BPoint where); 50 50 virtual void MouseUp(BPoint where); 51 51 virtual void MouseMoved(BPoint where, uint32 transit, -
src/apps/aboutsystem/HyperTextActions.cpp
-- 1.7.7.2 From 42d78ee4f6140824fb04123323e7d32391b74dc5 Mon Sep 17 00:00:00 2001 From: Adam Hartford <adam.s.hartford@gmail.com> Date: Sun, 1 Jul 2012 22:20:12 -0400 Subject: [PATCH 4/5] Handle underlines for wrapping text. --- src/apps/aboutsystem/HyperTextActions.cpp | 2 - src/apps/aboutsystem/HyperTextView.cpp | 56 ++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/apps/aboutsystem/HyperTextActions.cpp b/src/apps/aboutsystem/HyperTextActions.cpp index 498a1fc..b1d1d04 100644
a b OpenFileAction::GetUnderlineColor() 90 90 { 91 91 return kDarkGrey; 92 92 } 93 94 -
src/apps/aboutsystem/HyperTextView.cpp
diff --git a/src/apps/aboutsystem/HyperTextView.cpp b/src/apps/aboutsystem/HyperTextView.cpp index dc33d09..437bf53 100644
a b 5 5 6 6 #include "HyperTextView.h" 7 7 8 #include <math.h> 9 8 10 #include <Cursor.h> 11 #include <Debug.h> 9 12 #include <Message.h> 10 13 #include <Region.h> 11 14 #include <Window.h> … … 17 20 18 21 19 22 static const rgb_color kDarkGrey = { 100, 100, 100, 255 }; 23 static const float kCharWidth = 4.5; 20 24 21 25 22 26 HyperTextAction::HyperTextAction() … … HyperTextAction::~HyperTextAction() 30 34 31 35 32 36 void 33 HyperTextAction::MouseOver(HyperTextView* view, BPoint where, BMessage* message) 37 HyperTextAction::MouseOver(HyperTextView* view, BPoint where, 38 BMessage* message) 34 39 { 35 40 BCursor linkCursor(B_CURSOR_ID_FOLLOW_LINK); 36 41 view->SetViewCursor(&linkCursor); … … HyperTextView::Draw(BRect updateRect) 153 158 154 159 BRect frame = textRegion.Frame(); 155 160 SetHighColor(fActiveInfo->action->GetUnderlineColor()); 156 StrokeLine(frame.LeftBottom(), frame.RightBottom()); 161 162 PRINT_OBJECT(frame); 163 164 int currLine = LineAt(frame.LeftTop()); 165 float lineHeight = LineHeight(currLine); 166 167 if (frame.Height() > lineHeight) { 168 // Draw multiple lines if link wraps. 169 170 int numLines = (int)ceil(frame.Height() / lineHeight); 171 BPoint start = BPoint(frame.LeftTop()); 172 BPoint end = BPoint(frame.RightTop()); 173 174 for (int i = 0; i < numLines; i++) { 175 start.y += lineHeight; 176 end.y += lineHeight; 177 178 if (i == 0) { 179 // Start first line at proper character. 180 start.x = PointAt(fActiveInfo->startOffset).x; 181 182 for (int i = fActiveInfo->startOffset; 183 i <= fActiveInfo->endOffset; i++) { 184 // If this character starts on a new line, 185 // end the underline at the previous character. 186 if (PointAt(i).y > frame.LeftTop().y) { 187 // Pad the ending point a bit. 188 end.x = PointAt(i - 1).x + kCharWidth; 189 break; 190 } 191 } 192 } else if (i == numLines - 1) { 193 // End last line at proper character. 194 start.x = frame.LeftTop().x; 195 end.x = PointAt(fActiveInfo->endOffset).x; 196 } else { 197 start.x = frame.LeftTop().x; 198 end.x = frame.RightTop().x; 199 } 200 201 StrokeLine(start, end); 202 } 203 } else 204 StrokeLine(frame.LeftBottom(), frame.RightBottom()); 157 205 } 158 206 } 159 207 … … HyperTextView::MouseMoved(BPoint where, uint32 transit, 195 243 } else if (fActiveInfo != info) { 196 244 // This is the scenario where mouse moves from one action directly 197 245 // into another. 198 fActiveInfo->action->MouseLeave(this, where, fActiveInfo->startOffset,199 fActiveInfo-> endOffset, message);246 fActiveInfo->action->MouseLeave(this, where, 247 fActiveInfo->startOffset, fActiveInfo->endOffset, message); 200 248 action->MouseEnter(this, where, info->startOffset, info->endOffset, 201 249 message); 202 250 fActiveInfo = info; -
src/apps/aboutsystem/HyperTextView.cpp
-- 1.7.7.2 From 0f696bfe26bd1c66b84d689f1a1c63beeb13641c Mon Sep 17 00:00:00 2001 From: Adam Hartford <adam.s.hartford@gmail.com> Date: Mon, 2 Jul 2012 21:36:15 -0400 Subject: [PATCH 5/5] Draw underlines correctly for wrapping links. --- src/apps/aboutsystem/HyperTextView.cpp | 68 ++++++++++---------------------- 1 files changed, 21 insertions(+), 47 deletions(-) diff --git a/src/apps/aboutsystem/HyperTextView.cpp b/src/apps/aboutsystem/HyperTextView.cpp index 437bf53..216976f 100644
a b HyperTextView::Draw(BRect updateRect) 152 152 BTextView::Draw(updateRect); 153 153 154 154 if (fActiveInfo != NULL) { 155 BRegion textRegion;156 GetTextRegion(fActiveInfo->startOffset, fActiveInfo->endOffset,157 &textRegion);158 159 BRect frame = textRegion.Frame();160 155 SetHighColor(fActiveInfo->action->GetUnderlineColor()); 161 156 162 PRINT_OBJECT(frame); 163 164 int currLine = LineAt(frame.LeftTop()); 165 float lineHeight = LineHeight(currLine); 166 167 if (frame.Height() > lineHeight) { 168 // Draw multiple lines if link wraps. 169 170 int numLines = (int)ceil(frame.Height() / lineHeight); 171 BPoint start = BPoint(frame.LeftTop()); 172 BPoint end = BPoint(frame.RightTop()); 173 174 for (int i = 0; i < numLines; i++) { 175 start.y += lineHeight; 176 end.y += lineHeight; 177 178 if (i == 0) { 179 // Start first line at proper character. 180 start.x = PointAt(fActiveInfo->startOffset).x; 181 182 for (int i = fActiveInfo->startOffset; 183 i <= fActiveInfo->endOffset; i++) { 184 // If this character starts on a new line, 185 // end the underline at the previous character. 186 if (PointAt(i).y > frame.LeftTop().y) { 187 // Pad the ending point a bit. 188 end.x = PointAt(i - 1).x + kCharWidth; 189 break; 190 } 191 } 192 } else if (i == numLines - 1) { 193 // End last line at proper character. 194 start.x = frame.LeftTop().x; 195 end.x = PointAt(fActiveInfo->endOffset).x; 196 } else { 197 start.x = frame.LeftTop().x; 198 end.x = frame.RightTop().x; 199 } 200 201 StrokeLine(start, end); 157 BPoint start; 158 BPoint end; 159 160 for (int i = fActiveInfo->startOffset; 161 i < fActiveInfo->endOffset; i++) { 162 163 float lineHeight = LineHeight(LineAt(i)); 164 165 start = PointAt(i); 166 if (i + 1 <= fActiveInfo->endOffset) 167 end = PointAt(i + 1); 168 169 start.y += lineHeight; 170 end.y += lineHeight; 171 172 if (start.y != end.y) { 173 end = start; 174 end.x += kCharWidth; 202 175 } 203 } else 204 StrokeLine(frame.LeftBottom(), frame.RightBottom()); 176 177 StrokeLine(start, end); 178 } 205 179 } 206 180 } 207 181