1 // The definition of the Qt specific subclass of ScintillaBase.
2 //
3 // Copyright (c) 2021 Riverbank Computing Limited <info@riverbankcomputing.com>
4 //
5 // This file is part of QScintilla.
6 //
7 // This file may be used under the terms of the GNU General Public License
8 // version 3.0 as published by the Free Software Foundation and appearing in
9 // the file LICENSE included in the packaging of this file.  Please review the
10 // following information to ensure the GNU General Public License version 3.0
11 // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 //
13 // If you do not wish to use this file under the terms of the GPL version 3.0
14 // then you may purchase a commercial license.  For more information contact
15 // info@riverbankcomputing.com.
16 //
17 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 
20 
21 #ifndef SCINTILLAQT_H
22 #define	SCINTILLAQT_H
23 
24 
25 #include <QClipboard>
26 #include <QObject>
27 
28 #include <Qsci/qsciglobal.h>
29 
30 // These are needed because Scintilla class header files don't manage their own
31 // dependencies properly.
32 #include <algorithm>
33 #include <assert.h>
34 #include <ctype.h>
35 #include <memory>
36 #include <stdexcept>
37 #include <stdlib.h>
38 #include <string>
39 #include <map>
40 #include <vector>
41 #include "ILexer.h"
42 #include "ILoader.h"
43 #include "Platform.h"
44 #include "Scintilla.h"
45 #include "SplitVector.h"
46 #include "Partitioning.h"
47 #include "Position.h"
48 #include "UniqueString.h"
49 #include "CellBuffer.h"
50 #include "CharClassify.h"
51 #include "RunStyles.h"
52 #include "CaseFolder.h"
53 #include "Decoration.h"
54 #include "Document.h"
55 #include "Style.h"
56 #include "XPM.h"
57 #include "LineMarker.h"
58 #include "Indicator.h"
59 #include "ViewStyle.h"
60 #include "KeyMap.h"
61 #include "ContractionState.h"
62 #include "Selection.h"
63 #include "PositionCache.h"
64 #include "EditModel.h"
65 #include "MarginView.h"
66 #include "EditView.h"
67 #include "Editor.h"
68 #include "AutoComplete.h"
69 #include "CallTip.h"
70 #include "LexAccessor.h"
71 #include "Accessor.h"
72 
73 #include "ScintillaBase.h"
74 
75 
76 QT_BEGIN_NAMESPACE
77 class QMimeData;
78 class QPaintEvent;
79 QT_END_NAMESPACE
80 
81 class QsciScintillaBase;
82 class QsciSciCallTip;
83 class QsciSciPopup;
84 
85 
86 // This is an internal class but it is referenced by a public class so it has
87 // to have a Qsci prefix rather than being put in the Scintilla namespace.
88 // (However the reason for avoiding this no longer applies.)
89 class QsciScintillaQt : public QObject, public Scintilla::ScintillaBase
90 {
91     Q_OBJECT
92 
93 	friend class QsciScintillaBase;
94 	friend class QsciSciCallTip;
95 	friend class QsciSciPopup;
96 
97 public:
98 	QsciScintillaQt(QsciScintillaBase *qsb_);
99 	virtual ~QsciScintillaQt();
100 
101 	virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam,
102             sptr_t lParam);
103 
104 protected:
105     void timerEvent(QTimerEvent *e);
106 
107 private slots:
108     void onIdle();
109     void onSelectionChanged();
110 
111 private:
112 	void Initialise();
113 	void Finalise();
114     bool SetIdle(bool on);
115 	void StartDrag();
116 	sptr_t DefWndProc(unsigned int, uptr_t, sptr_t);
117 	void SetMouseCapture(bool on);
118 	bool HaveMouseCapture();
119 	void SetVerticalScrollPos();
120 	void SetHorizontalScrollPos();
121 	bool ModifyScrollBars(Sci::Line nMax, Sci::Line nPage);
122 	void ReconfigureScrollBars();
123 	void NotifyChange();
124 	void NotifyParent(SCNotification scn);
125 	void CopyToClipboard(const Scintilla::SelectionText &selectedText);
126 	void Copy();
127 	void Paste();
128 	void CreateCallTipWindow(Scintilla::PRectangle rc);
129 	void AddToPopUp(const char *label, int cmd = 0, bool enabled = true);
130 	void ClaimSelection();
131 	void UnclaimSelection();
132 	static sptr_t DirectFunction(QsciScintillaQt *sci, unsigned int iMessage,
133             uptr_t wParam,sptr_t lParam);
134 
135 	QMimeData *mimeSelection(const Scintilla::SelectionText &text) const;
136 	void paintEvent(QPaintEvent *e);
137     void pasteFromClipboard(QClipboard::Mode mode);
138 
139     // tickPlatform is the last of the TickReason members.
140     int timers[tickPlatform + 1];
141     bool FineTickerAvailable();
142     void FineTickerCancel(TickReason reason);
143     bool FineTickerRunning(TickReason reason);
144     void FineTickerStart(TickReason reason, int ms, int tolerance);
145 
146     int vMax, hMax, vPage, hPage;
147     bool capturedMouse;
148     QsciScintillaBase *qsb;
149 };
150 
151 #endif
152