| 67 | void |
| 68 | TTextControl::MouseDown(BPoint mousePosition) |
| 69 | { |
| 70 | if(_VisibleLabelBounds().Contains(mousePosition)) |
| 71 | _HandleLabelClicked(Text()); |
| 72 | else |
| 73 | BTextControl::MouseDown(mousePosition); |
| 74 | } |
| 75 | |
| 76 | void |
| 77 | TTextControl::MouseMoved(BPoint mousePosition, uint32 transit, const BMessage* dragMessage) |
| 78 | { |
| 79 | if (_VisibleLabelBounds().Contains(mousePosition)) { |
| 80 | BCursor linkCursor(B_CURSOR_ID_FOLLOW_LINK); |
| 81 | SetViewCursor(&linkCursor, true); |
| 82 | } else |
| 83 | SetViewCursor(B_CURSOR_SYSTEM_DEFAULT, true); |
| 84 | |
| 85 | BTextControl::MouseMoved(mousePosition, transit, dragMessage); |
| 86 | } |
| 87 | |
| 88 | |
| 110 | |
| 111 | |
| 112 | void |
| 113 | TTextControl::_HandleLabelClicked(const char *text) |
| 114 | { |
| 115 | BString argument(text); |
| 116 | |
| 117 | if (BString(gFields[F_URL].name).Append(":") == Label()) { |
| 118 | |
| 119 | if (argument.IFindFirst("www") == 0) |
| 120 | argument.Prepend("http://"); |
| 121 | else if (argument.IFindFirst("ftp") == 0) |
| 122 | argument.Prepend("ftp://"); |
| 123 | |
| 124 | const char *args[] = {argument.String(), 0}; |
| 125 | |
| 126 | if (argument.IFindFirst("http://") == 0 |
| 127 | || argument.IFindFirst("ftp://") == 0 |
| 128 | || argument.IFindFirst("https://") == 0) { |
| 129 | BString mimeType = B_URL_MIME; |
| 130 | mimeType.Append(argument, argument.FindFirst(':')); |
| 131 | if (!BMimeType::IsValid(mimeType.String())) |
| 132 | return; |
| 133 | be_roster->Launch(mimeType.String(), 1, const_cast<char **>(args)); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | if (BString(gFields[F_EMAIL].name).Append(":") == Label()) { |
| 138 | if (argument.IFindFirst("mailto:") != 0 && argument != "") |
| 139 | argument.Prepend("mailto:"); |
| 140 | |
| 141 | // TODO: Could check for possible e-mail patterns. |
| 142 | if (argument != "") { |
| 143 | const char *args[] = {argument.String(), 0}; |
| 144 | be_roster->Launch("text/x-email", 1, const_cast<char **>(args)); |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | |
| 150 | BRect |
| 151 | TTextControl::_VisibleLabelBounds() const |
| 152 | { |
| 153 | // TODO: Could actually check current alignment of the label. |
| 154 | // The code below works only for right aligned labels. |
| 155 | BRect bounds(Bounds()); |
| 156 | bounds.right = Divider(); |
| 157 | bounds.left = bounds.right - StringWidth(Label()); |
| 158 | return bounds; |
| 159 | } |