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 ScintillaQt.h - Qt specific subclass of ScintillaBase
10
11#ifndef SCINTILLAQT_H
12#define SCINTILLAQT_H
13
14#include <cstddef>
15#include <cstdlib>
16#include <cstdint>
17#include <cassert>
18#include <cstring>
19#include <cctype>
20#include <cstdio>
21#include <ctime>
22#include <cmath>
23#include <stdexcept>
24#include <string>
25#include <string_view>
26#include <vector>
27#include <map>
28#include <set>
29#include <optional>
30#include <algorithm>
31#include <memory>
32
33#include "ScintillaTypes.h"
34#include "ScintillaMessages.h"
35#include "ScintillaStructures.h"
36#include "Scintilla.h"
37#include "Debugging.h"
38#include "Geometry.h"
39#include "Platform.h"
40#include "ILoader.h"
41#include "ILexer.h"
42#include "CharacterCategoryMap.h"
43#include "Position.h"
44#include "UniqueString.h"
45#include "SplitVector.h"
46#include "Partitioning.h"
47#include "RunStyles.h"
48#include "ContractionState.h"
49#include "CellBuffer.h"
50#include "CallTip.h"
51#include "KeyMap.h"
52#include "Indicator.h"
53#include "LineMarker.h"
54#include "Style.h"
55#include "AutoComplete.h"
56#include "ViewStyle.h"
57#include "CharClassify.h"
58#include "Decoration.h"
59#include "CaseFolder.h"
60#include "Document.h"
61#include "Selection.h"
62#include "PositionCache.h"
63#include "EditModel.h"
64#include "MarginView.h"
65#include "EditView.h"
66#include "Editor.h"
67#include "ScintillaBase.h"
68#include "CaseConvert.h"
69
70#include <QObject>
71#include <QAbstractScrollArea>
72#include <QAction>
73#include <QClipboard>
74#include <QPaintEvent>
75
76class ScintillaEditBase;
77
78namespace Scintilla::Internal {
79
80class ScintillaQt : public QObject, public ScintillaBase {
81 Q_OBJECT
82
83public:
84 explicit ScintillaQt(QAbstractScrollArea *parent);
85 virtual ~ScintillaQt();
86
87signals:
88 void horizontalScrolled(int value);
89 void verticalScrolled(int value);
90 void horizontalRangeChanged(int max, int page);
91 void verticalRangeChanged(int max, int page);
92
93 void notifyParent(Scintilla::NotificationData scn);
94 void notifyChange();
95
96 // Clients can use this hook to add additional
97 // formats (e.g. rich text) to the MIME data.
98 void aboutToCopy(QMimeData *data);
99
100 void command(Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
101
102private slots:
103 void onIdle();
104 void execCommand(QAction *action);
105 void SelectionChanged();
106
107private:
108 void Init();
109 void Finalise() override;
110 bool DragThreshold(Point ptStart, Point ptNow) override;
111 bool ValidCodePage(int codePage) const override;
112 std::string UTF8FromEncoded(std::string_view encoded) const override;
113 std::string EncodedFromUTF8(std::string_view utf8) const override;
114
115private:
116 void ScrollText(Sci::Line linesToMove) override;
117 void SetVerticalScrollPos() override;
118 void SetHorizontalScrollPos() override;
119 bool ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) override;
120 void ReconfigureScrollBars() override;
121 void CopyToModeClipboard(const SelectionText &selectedText, QClipboard::Mode clipboardMode_);
122 void Copy() override;
123 void CopyToClipboard(const SelectionText &selectedText) override;
124 void PasteFromMode(QClipboard::Mode clipboardMode_);
125 void Paste() override;
126 void ClaimSelection() override;
127 void NotifyChange() override;
128 void NotifyFocus(bool focus) override;
129 void NotifyParent(Scintilla::NotificationData scn) override;
130 void NotifyURIDropped(const char *uri);
131 int timers[static_cast<size_t>(TickReason::dwell)+1]{};
132 bool FineTickerRunning(TickReason reason) override;
133 void FineTickerStart(TickReason reason, int millis, int tolerance) override;
134 void CancelTimers();
135 void FineTickerCancel(TickReason reason) override;
136 bool ChangeIdle(bool on);
137 bool SetIdle(bool on) override;
138 void SetMouseCapture(bool on) override;
139 bool HaveMouseCapture() override;
140 void StartDrag() override;
141 Scintilla::CharacterSet CharacterSetOfDocument() const;
142 const char *CharacterSetIDOfDocument() const;
143 QString StringFromDocument(const char *s) const;
144 QByteArray BytesForDocument(const QString &text) const;
145 std::unique_ptr<CaseFolder> CaseFolderForEncoding() override;
146 std::string CaseMapString(const std::string &s, CaseMapping caseMapping) override;
147
148 void CreateCallTipWindow(PRectangle rc) override;
149 void AddToPopUp(const char *label, int cmd, bool enabled) override;
150 sptr_t WndProc(Scintilla::Message iMessage, uptr_t wParam, sptr_t lParam) override;
151 sptr_t DefWndProc(Scintilla::Message iMessage, uptr_t wParam, sptr_t lParam) override;
152
153 static sptr_t DirectFunction(sptr_t ptr,
154 unsigned int iMessage, uptr_t wParam, sptr_t lParam);
155 static sptr_t DirectStatusFunction(sptr_t ptr,
156 unsigned int iMessage, uptr_t wParam, sptr_t lParam, int *pStatus);
157
158protected:
159
160 void PartialPaint(const PRectangle &rect);
161
162 void DragEnter(const Point &point);
163 void DragMove(const Point &point);
164 void DragLeave();
165 void Drop(const Point &point, const QMimeData *data, bool move);
166 void DropUrls(const QMimeData *data);
167
168 void timerEvent(QTimerEvent *event) override;
169
170private:
171 QAbstractScrollArea *scrollArea;
172
173 int vMax, hMax; // Scroll bar maximums.
174 int vPage, hPage; // Scroll bar page sizes.
175
176 bool haveMouseCapture;
177 bool dragWasDropped;
178 int rectangularSelectionModifier;
179
180 friend class ::ScintillaEditBase;
181};
182
183}
184
185#endif /* SCINTILLAQT_H */
186