2021-08-01 06:56:07 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
|
|
* All rights reserved. Distributed under the terms of the MIT license.
|
|
|
|
*/
|
|
|
|
#ifndef _URL_TEXT_VIEW_H
|
|
|
|
#define _URL_TEXT_VIEW_H
|
|
|
|
|
|
|
|
#include <TextView.h>
|
|
|
|
#include <Url.h>
|
|
|
|
|
|
|
|
class BPopUpMenu;
|
|
|
|
|
|
|
|
|
|
|
|
/*! TextView that highlights and allows selecting of URLs― also provides a
|
|
|
|
* right-click pop-up menu with internet search options */
|
|
|
|
class UrlTextView : public BTextView {
|
|
|
|
public:
|
|
|
|
UrlTextView(const char* name);
|
|
|
|
UrlTextView(const char* name, const BFont* initialFont,
|
|
|
|
const rgb_color* initialColor, uint32 flags);
|
|
|
|
|
|
|
|
|
|
|
|
virtual void MessageReceived(BMessage* msg);
|
|
|
|
|
|
|
|
virtual void MouseDown(BPoint where);
|
|
|
|
virtual void MouseUp(BPoint where);
|
|
|
|
virtual void MouseMoved(BPoint where, uint32 code, const BMessage* drag);
|
|
|
|
|
|
|
|
virtual void Select(int32 startOffset, int32 endOffset);
|
|
|
|
|
2021-08-11 16:28:13 -05:00
|
|
|
// Only differs in that it changes font face and color of any URLs
|
2021-08-01 17:04:52 -05:00
|
|
|
void Insert(const char* text, const text_run_array* runs = NULL);
|
|
|
|
void SetText(const char* text, const text_run_array* runs = NULL);
|
|
|
|
|
2021-08-01 06:56:07 -05:00
|
|
|
BString WordAt(BPoint point);
|
|
|
|
void FindWordAround(int32 offset, int32* start, int32* end,
|
|
|
|
BString* _word = NULL);
|
|
|
|
const char* GetLine(int32 line);
|
|
|
|
|
2021-08-11 16:28:13 -05:00
|
|
|
BUrl UrlAt(BPoint point);
|
|
|
|
|
2021-08-01 06:56:07 -05:00
|
|
|
bool OverText(BPoint where);
|
|
|
|
bool OverUrl(BPoint where);
|
|
|
|
|
|
|
|
private:
|
|
|
|
BPopUpMenu* _RightClickPopUp(BPoint where);
|
|
|
|
|
|
|
|
bool _FindUrlString(BString text, int32* start, int32* end,
|
|
|
|
int32 offset);
|
|
|
|
|
2021-08-11 16:28:13 -05:00
|
|
|
// Checks if char is allowed in a url, as per rfc3986
|
|
|
|
bool _IsValidUrlChar(char c);
|
|
|
|
|
2021-08-01 06:56:07 -05:00
|
|
|
// For safe-keeping
|
2021-08-11 16:28:13 -05:00
|
|
|
text_run_array fNormalRun;
|
2021-08-01 06:56:07 -05:00
|
|
|
text_run_array fUrlRun;
|
|
|
|
BCursor* fUrlCursor;
|
|
|
|
|
|
|
|
// Information between MouseDown and MouseUp
|
|
|
|
BUrl fLastClicked;
|
|
|
|
bool fMouseDown;
|
|
|
|
bool fSelecting;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _URL_TEXT_VIEW_H
|