[3d27dc6] | 1 | /*
|
---|
| 2 | * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
|
---|
| 3 | * Distributed under the terms of the MIT license.
|
---|
| 4 | */
|
---|
| 5 | #ifndef HYPER_TEXT_VIEW_H
|
---|
| 6 | #define HYPER_TEXT_VIEW_H
|
---|
| 7 |
|
---|
| 8 | #include <TextView.h>
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | // TODO: The current implementation works correctly only for insertions at the
|
---|
| 12 | // end of the text. It doesn't keep track of any other insertions or deletions.
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | class HyperTextView;
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | class HyperTextAction {
|
---|
| 19 | public:
|
---|
| 20 | HyperTextAction(int32 event);
|
---|
| 21 | virtual ~HyperTextAction();
|
---|
| 22 |
|
---|
| 23 | virtual void MouseOver(HyperTextView* view, BPoint where,
|
---|
| 24 | int32 startOffset, int32 endOffset,
|
---|
| 25 | BMessage* message);
|
---|
| 26 | virtual void MouseAway(HyperTextView* view, BPoint where,
|
---|
| 27 | int32 startOffset, int32 endOffset,
|
---|
| 28 | BMessage* message);
|
---|
| 29 | virtual void Clicked(HyperTextView* view, BPoint where,
|
---|
| 30 | BMessage* message);
|
---|
| 31 | private:
|
---|
| 32 | int32 fMessage;
|
---|
| 33 | };
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | class HyperTextView : public BTextView {
|
---|
| 37 | public:
|
---|
| 38 | HyperTextView(const char* name,
|
---|
| 39 | uint32 flags = B_WILL_DRAW
|
---|
| 40 | | B_PULSE_NEEDED);
|
---|
| 41 | HyperTextView(BRect frame, const char* name,
|
---|
| 42 | BRect textRect, uint32 resizeMask,
|
---|
| 43 | uint32 flags = B_WILL_DRAW
|
---|
| 44 | | B_PULSE_NEEDED);
|
---|
| 45 | virtual ~HyperTextView();
|
---|
| 46 |
|
---|
| 47 | virtual void MouseDown(BPoint where);
|
---|
| 48 | virtual void MouseUp(BPoint where);
|
---|
| 49 | virtual void MouseMoved(BPoint where, uint32 transit,
|
---|
| 50 | const BMessage* dragMessage);
|
---|
| 51 |
|
---|
[3d333fd] | 52 | virtual bool HasHeightForWidth() override;
|
---|
| 53 | virtual void GetHeightForWidth(float width, float* min,
|
---|
| 54 | float* max, float* preferred) override;
|
---|
| 55 |
|
---|
[3d27dc6] | 56 | void SetText(const char* text);
|
---|
| 57 |
|
---|
| 58 | void AddHyperTextAction(int32 startOffset,
|
---|
| 59 | int32 endOffset, HyperTextAction* action);
|
---|
| 60 |
|
---|
| 61 | void InsertHyperText(const char* inText,
|
---|
| 62 | HyperTextAction* action,
|
---|
| 63 | const text_run_array* inRuns = NULL);
|
---|
| 64 | void InsertHyperText(const char* inText,
|
---|
| 65 | int32 inLength, HyperTextAction* action,
|
---|
| 66 | const text_run_array* inRuns = NULL);
|
---|
| 67 | private:
|
---|
| 68 | struct ActionInfo;
|
---|
| 69 | class ActionInfoList;
|
---|
| 70 |
|
---|
| 71 | HyperTextAction* _ActionAt(const BPoint& where) const;
|
---|
| 72 | const ActionInfo* _ActionInfoAt(const BPoint& where) const;
|
---|
| 73 |
|
---|
| 74 | private:
|
---|
| 75 | ActionInfoList* fActionInfos;
|
---|
| 76 | const ActionInfo* fLastActionInfo;
|
---|
| 77 | };
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | #endif // HYPER_TEXT_VIEW_H
|
---|