1 | // |
2 | // Copyright (c) 1990-2011, Scientific Toolworks, Inc. |
3 | // |
4 | // The License.txt file describes the conditions under which this software may be distributed. |
5 | // |
6 | // Author: Jason Haslam |
7 | // |
8 | // Additions Copyright (c) 2011 Archaeopteryx Software, Inc. d/b/a Wingware |
9 | // @file ScintillaEditBase.h - Qt widget that wraps ScintillaQt and provides events and scrolling |
10 | |
11 | |
12 | #ifndef SCINTILLAEDITBASE_H |
13 | #define SCINTILLAEDITBASE_H |
14 | |
15 | #include <cstddef> |
16 | |
17 | #include <string_view> |
18 | #include <vector> |
19 | #include <optional> |
20 | #include <memory> |
21 | |
22 | #include "ScintillaTypes.h" |
23 | #include "Debugging.h" |
24 | #include "Geometry.h" |
25 | #include "ScintillaMessages.h" |
26 | #include "ScintillaStructures.h" |
27 | #include "Platform.h" |
28 | #include "Scintilla.h" |
29 | |
30 | #include <QAbstractScrollArea> |
31 | #include <QMimeData> |
32 | #include <QElapsedTimer> |
33 | |
34 | namespace Scintilla::Internal { |
35 | |
36 | class ScintillaQt; |
37 | class SurfaceImpl; |
38 | |
39 | } |
40 | |
41 | #ifndef EXPORT_IMPORT_API |
42 | #ifdef WIN32 |
43 | #ifdef MAKING_LIBRARY |
44 | #define EXPORT_IMPORT_API __declspec(dllexport) |
45 | #else |
46 | // Defining dllimport upsets moc |
47 | #define EXPORT_IMPORT_API __declspec(dllimport) |
48 | //#define EXPORT_IMPORT_API |
49 | #endif |
50 | #else |
51 | #define EXPORT_IMPORT_API |
52 | #endif |
53 | #endif |
54 | |
55 | class EXPORT_IMPORT_API ScintillaEditBase : public QAbstractScrollArea { |
56 | Q_OBJECT |
57 | |
58 | public: |
59 | explicit ScintillaEditBase(QWidget *parent = 0); |
60 | virtual ~ScintillaEditBase(); |
61 | |
62 | virtual sptr_t send( |
63 | unsigned int iMessage, |
64 | uptr_t wParam = 0, |
65 | sptr_t lParam = 0) const; |
66 | |
67 | virtual sptr_t sends( |
68 | unsigned int iMessage, |
69 | uptr_t wParam = 0, |
70 | const char *s = 0) const; |
71 | |
72 | public slots: |
73 | // Scroll events coming from GUI to be sent to Scintilla. |
74 | void scrollHorizontal(int value); |
75 | void scrollVertical(int value); |
76 | |
77 | // Emit Scintilla notifications as signals. |
78 | void notifyParent(Scintilla::NotificationData scn); |
79 | void event_command(Scintilla::uptr_t wParam, Scintilla::sptr_t lParam); |
80 | |
81 | signals: |
82 | void horizontalScrolled(int value); |
83 | void verticalScrolled(int value); |
84 | void horizontalRangeChanged(int max, int page); |
85 | void verticalRangeChanged(int max, int page); |
86 | void notifyChange(); |
87 | void linesAdded(Scintilla::Position linesAdded); |
88 | |
89 | // Clients can use this hook to add additional |
90 | // formats (e.g. rich text) to the MIME data. |
91 | void aboutToCopy(QMimeData *data); |
92 | |
93 | // Scintilla Notifications |
94 | void styleNeeded(Scintilla::Position position); |
95 | void charAdded(int ch); |
96 | void savePointChanged(bool dirty); |
97 | void modifyAttemptReadOnly(); |
98 | void key(int key); |
99 | void doubleClick(Scintilla::Position position, Scintilla::Position line); |
100 | void updateUi(Scintilla::Update updated); |
101 | void modified(Scintilla::ModificationFlags type, Scintilla::Position position, Scintilla::Position length, Scintilla::Position linesAdded, |
102 | const QByteArray &text, Scintilla::Position line, Scintilla::FoldLevel foldNow, Scintilla::FoldLevel foldPrev); |
103 | void macroRecord(Scintilla::Message message, Scintilla::uptr_t wParam, Scintilla::sptr_t lParam); |
104 | void marginClicked(Scintilla::Position position, Scintilla::KeyMod modifiers, int margin); |
105 | void textAreaClicked(Scintilla::Position line, int modifiers); |
106 | void needShown(Scintilla::Position position, Scintilla::Position length); |
107 | void painted(); |
108 | void userListSelection(); // Wants some args. |
109 | void uriDropped(const QString &uri); |
110 | void dwellStart(int x, int y); |
111 | void dwellEnd(int x, int y); |
112 | void zoom(int zoom); |
113 | void hotSpotClick(Scintilla::Position position, Scintilla::KeyMod modifiers); |
114 | void hotSpotDoubleClick(Scintilla::Position position, Scintilla::KeyMod modifiers); |
115 | void callTipClick(); |
116 | void autoCompleteSelection(Scintilla::Position position, const QString &text); |
117 | void autoCompleteCancelled(); |
118 | void focusChanged(bool focused); |
119 | |
120 | // Base notifications for compatibility with other Scintilla implementations |
121 | void notify(Scintilla::NotificationData *pscn); |
122 | void command(Scintilla::uptr_t wParam, Scintilla::sptr_t lParam); |
123 | |
124 | // GUI event notifications needed under Qt |
125 | void buttonPressed(QMouseEvent *event); |
126 | void buttonReleased(QMouseEvent *event); |
127 | void keyPressed(QKeyEvent *event); |
128 | void resized(); |
129 | |
130 | protected: |
131 | bool event(QEvent *event) override; |
132 | void paintEvent(QPaintEvent *event) override; |
133 | void wheelEvent(QWheelEvent *event) override; |
134 | void focusInEvent(QFocusEvent *event) override; |
135 | void focusOutEvent(QFocusEvent *event) override; |
136 | void resizeEvent(QResizeEvent *event) override; |
137 | void keyPressEvent(QKeyEvent *event) override; |
138 | void mousePressEvent(QMouseEvent *event) override; |
139 | void mouseReleaseEvent(QMouseEvent *event) override; |
140 | void mouseDoubleClickEvent(QMouseEvent *event) override; |
141 | void mouseMoveEvent(QMouseEvent *event) override; |
142 | void (QContextMenuEvent *event) override; |
143 | void dragEnterEvent(QDragEnterEvent *event) override; |
144 | void dragLeaveEvent(QDragLeaveEvent *event) override; |
145 | void dragMoveEvent(QDragMoveEvent *event) override; |
146 | void dropEvent(QDropEvent *event) override; |
147 | void inputMethodEvent(QInputMethodEvent *event) override; |
148 | QVariant inputMethodQuery(Qt::InputMethodQuery query) const override; |
149 | void scrollContentsBy(int, int) override {} |
150 | |
151 | private: |
152 | Scintilla::Internal::ScintillaQt *sqt; |
153 | |
154 | QElapsedTimer time; |
155 | |
156 | int preeditPos; |
157 | QString preeditString; |
158 | |
159 | int wheelDelta; |
160 | |
161 | static bool IsHangul(const QChar qchar); |
162 | void MoveImeCarets(int offset); |
163 | void DrawImeIndicator(int indicator, int len); |
164 | static Scintilla::KeyMod ModifiersOfKeyboard(); |
165 | }; |
166 | |
167 | #endif /* SCINTILLAEDITBASE_H */ |
168 | |