aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2025-04-22 11:13:52 +1000
committerNeil <nyamatongwe@gmail.com>2025-04-22 11:13:52 +1000
commit99e69de57d94f4bcf8d72a69c9215684ee4152ee (patch)
treec9d4fb2406babae42a9772309becc59c017f3165
parentac87d3e3b29fead6e30514535b8cf87dcc66304e (diff)
downloadscintilla-mirror-99e69de57d94f4bcf8d72a69c9215684ee4152ee.tar.gz
Move common IME code from platform layers to ScintillaBase.
-rwxr-xr-xgtk/ScintillaGTK.cxx23
-rwxr-xr-xgtk/ScintillaGTK.h2
-rw-r--r--qt/ScintillaEditBase/ScintillaEditBase.cpp34
-rw-r--r--qt/ScintillaEditBase/ScintillaEditBase.h2
-rw-r--r--src/ScintillaBase.cxx24
-rw-r--r--src/ScintillaBase.h8
-rw-r--r--win32/ScintillaWin.cxx30
7 files changed, 34 insertions, 89 deletions
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx
index 38e0d0376..d1cce0fbd 100755
--- a/gtk/ScintillaGTK.cxx
+++ b/gtk/ScintillaGTK.cxx
@@ -2375,29 +2375,6 @@ bool ScintillaGTK::KoreanIME() {
return lastNonCommonScript == G_UNICODE_SCRIPT_HANGUL;
}
-void ScintillaGTK::MoveImeCarets(Sci::Position pos) {
- // Move carets relatively by bytes
- for (size_t r=0; r<sel.Count(); r++) {
- const Sci::Position positionInsert = sel.Range(r).Start().Position();
- sel.Range(r) = SelectionRange(positionInsert + pos);
- }
-}
-
-void ScintillaGTK::DrawImeIndicator(int indicator, Sci::Position len) {
- // Emulate the visual style of IME characters with indicators.
- // Draw an indicator on the character before caret by the character bytes of len
- // so it should be called after InsertCharacter().
- // It does not affect caret positions.
- if (indicator < 8 || indicator > INDICATOR_MAX) {
- return;
- }
- pdoc->DecorationSetCurrentIndicator(indicator);
- for (size_t r=0; r<sel.Count(); r++) {
- const Sci::Position positionInsert = sel.Range(r).Start().Position();
- pdoc->DecorationFillRange(positionInsert - len, 1, len);
- }
-}
-
namespace {
std::vector<int> MapImeIndicators(PangoAttrList *attrs, const char *u8Str) {
diff --git a/gtk/ScintillaGTK.h b/gtk/ScintillaGTK.h
index 126072856..5f73d8174 100755
--- a/gtk/ScintillaGTK.h
+++ b/gtk/ScintillaGTK.h
@@ -243,8 +243,6 @@ private:
bool DeleteSurroundingThis(GtkIMContext *context, gint characterOffset, gint characterCount);
static gboolean DeleteSurrounding(GtkIMContext *context, gint characterOffset, gint characterCount,
ScintillaGTK *sciThis);
- void MoveImeCarets(Sci::Position pos);
- void DrawImeIndicator(int indicator, Sci::Position len);
void SetCandidateWindowPos();
static void StyleSetText(GtkWidget *widget, GtkStyle *previous, void *);
diff --git a/qt/ScintillaEditBase/ScintillaEditBase.cpp b/qt/ScintillaEditBase/ScintillaEditBase.cpp
index ef686de20..c316dca11 100644
--- a/qt/ScintillaEditBase/ScintillaEditBase.cpp
+++ b/qt/ScintillaEditBase/ScintillaEditBase.cpp
@@ -21,11 +21,6 @@
#include <QScrollBar>
#include <QTextFormat>
-constexpr int IndicatorInput = static_cast<int>(Scintilla::IndicatorNumbers::Ime);
-constexpr int IndicatorTarget = IndicatorInput + 1;
-constexpr int IndicatorConverted = IndicatorInput + 2;
-constexpr int IndicatorUnknown = IndicatorInput + 3;
-
// Q_WS_MAC and Q_WS_X11 aren't defined in Qt5
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#ifdef Q_OS_MAC
@@ -458,31 +453,6 @@ bool ScintillaEditBase::IsHangul(const QChar qchar)
HangulJamoExtendedA || HangulJamoExtendedB;
}
-void ScintillaEditBase::MoveImeCarets(Scintilla::Position offset)
-{
- // Move carets relatively by bytes
- for (size_t r=0; r < sqt->sel.Count(); r++) {
- const Sci::Position positionInsert = sqt->sel.Range(r).Start().Position();
- sqt->sel.Range(r) = SelectionRange(positionInsert + offset);
- }
-}
-
-void ScintillaEditBase::DrawImeIndicator(int indicator, int len)
-{
- // Emulate the visual style of IME characters with indicators.
- // Draw an indicator on the character before caret by the character bytes of len
- // so it should be called after InsertCharacter().
- // It does not affect caret positions.
- if (indicator < INDICATOR_CONTAINER || indicator > INDICATOR_MAX) {
- return;
- }
- sqt->pdoc->DecorationSetCurrentIndicator(indicator);
- for (size_t r=0; r< sqt-> sel.Count(); r++) {
- const Sci::Position positionInsert = sqt->sel.Range(r).Start().Position();
- sqt->pdoc->DecorationFillRange(positionInsert - len, 1, len);
- }
-}
-
namespace {
int GetImeCaretPos(QInputMethodEvent *event)
@@ -613,7 +583,7 @@ void ScintillaEditBase::inputMethodEvent(QInputMethodEvent *event)
sqt->InsertCharacter(std::string_view(oneChar.data(), oneCharLen), CharacterSource::TentativeInput);
- DrawImeIndicator(imeIndicator[i], oneCharLen);
+ sqt->DrawImeIndicator(imeIndicator[i], oneCharLen);
i += ucWidth;
}
@@ -622,7 +592,7 @@ void ScintillaEditBase::inputMethodEvent(QInputMethodEvent *event)
const int imeEndToImeCaretU16 = imeCaretPos - preeditStrLen;
const Sci::Position imeCaretPosDoc = sqt->pdoc->GetRelativePositionUTF16(sqt->CurrentPosition(), imeEndToImeCaretU16);
- MoveImeCarets(- sqt->CurrentPosition() + imeCaretPosDoc);
+ sqt->MoveImeCarets(- sqt->CurrentPosition() + imeCaretPosDoc);
if (IsHangul(preeditStr.at(0))) {
#ifndef Q_OS_WIN
diff --git a/qt/ScintillaEditBase/ScintillaEditBase.h b/qt/ScintillaEditBase/ScintillaEditBase.h
index bccd67ffa..5ad750b6e 100644
--- a/qt/ScintillaEditBase/ScintillaEditBase.h
+++ b/qt/ScintillaEditBase/ScintillaEditBase.h
@@ -162,8 +162,6 @@ private:
int wheelDelta;
static bool IsHangul(const QChar qchar);
- void MoveImeCarets(Scintilla::Position offset);
- void DrawImeIndicator(int indicator, int len);
static Scintilla::KeyMod ModifiersOfKeyboard();
};
diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx
index a95df76ae..e19f75d36 100644
--- a/src/ScintillaBase.cxx
+++ b/src/ScintillaBase.cxx
@@ -213,6 +213,30 @@ void ScintillaBase::ListNotify(ListBoxEvent *plbe) {
}
}
+void ScintillaBase::MoveImeCarets(Sci::Position offset) noexcept {
+ // Move carets relatively by bytes.
+ for (size_t r = 0; r < sel.Count(); r++) {
+ const Sci::Position positionInsert = sel.Range(r).Start().Position();
+ sel.Range(r) = SelectionRange(positionInsert + offset);
+ }
+}
+
+void ScintillaBase::DrawImeIndicator(int indicator, Sci::Position len) {
+ // Emulate the visual style of IME characters with indicators.
+ // Draw an indicator on the character before caret by the character bytes of len
+ // so it should be called after InsertCharacter().
+ // It does not affect caret positions.
+ const IndicatorNumbers ind = static_cast<IndicatorNumbers>(indicator);
+ if (ind < IndicatorNumbers::Container || ind > IndicatorNumbers::Max) {
+ return;
+ }
+ pdoc->DecorationSetCurrentIndicator(indicator);
+ for (size_t r = 0; r < sel.Count(); r++) {
+ const Sci::Position positionInsert = sel.Range(r).Start().Position();
+ pdoc->DecorationFillRange(positionInsert - len, 1, len);
+ }
+}
+
void ScintillaBase::AutoCompleteInsert(Sci::Position startPos, Sci::Position removeLen, std::string_view text) {
UndoGroup ug(pdoc);
if (multiAutoCMode == MultiAutoComplete::Once) {
diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h
index bfeb5a3d9..d3a6e1ad6 100644
--- a/src/ScintillaBase.h
+++ b/src/ScintillaBase.h
@@ -14,6 +14,11 @@ namespace Scintilla::Internal {
// blue, with different patterns.
constexpr ColourRGBA colourIME(0x0, 0x0, 0xffU);
+constexpr int IndicatorInput = static_cast<int>(Scintilla::IndicatorNumbers::Ime);
+constexpr int IndicatorTarget = IndicatorInput + 1;
+constexpr int IndicatorConverted = IndicatorInput + 2;
+constexpr int IndicatorUnknown = IndicatorInput + 3;
+
class LexState;
/**
*/
@@ -61,6 +66,9 @@ protected:
void CancelModes() override;
int KeyCommand(Scintilla::Message iMessage) override;
+ void MoveImeCarets(Sci::Position offset) noexcept;
+ void DrawImeIndicator(int indicator, Sci::Position len);
+
void AutoCompleteInsert(Sci::Position startPos, Sci::Position removeLen, std::string_view text);
void AutoCompleteStart(Sci::Position lenEntered, const char *list);
void AutoCompleteCancel();
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index bfa5dbb1f..c05dbd8fc 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -125,11 +125,6 @@ constexpr UINT SC_WIN_IDLE = 5001;
// and delivering SCN_UPDATEUI
constexpr UINT SC_WORK_IDLE = 5002;
-constexpr int IndicatorInput = static_cast<int>(Scintilla::IndicatorNumbers::Ime);
-constexpr int IndicatorTarget = IndicatorInput + 1;
-constexpr int IndicatorConverted = IndicatorInput + 2;
-constexpr int IndicatorUnknown = IndicatorInput + 3;
-
using SetCoalescableTimerSig = UINT_PTR (WINAPI *)(HWND hwnd, UINT_PTR nIDEvent,
UINT uElapse, TIMERPROC lpTimerFunc, ULONG uToleranceDelay);
@@ -548,8 +543,6 @@ class ScintillaWin :
sptr_t HandleCompositionWindowed(uptr_t wParam, sptr_t lParam);
sptr_t HandleCompositionInline(uptr_t wParam, sptr_t lParam);
static bool KoreanIME() noexcept;
- void MoveImeCarets(Sci::Position offset) noexcept;
- void DrawImeIndicator(int indicator, Sci::Position len);
void SetCandidateWindowPos();
void SelectionToHangul();
void EscapeHanja();
@@ -1334,29 +1327,6 @@ bool ScintillaWin::KoreanIME() noexcept {
return codePage == cp949 || codePage == cp1361;
}
-void ScintillaWin::MoveImeCarets(Sci::Position offset) noexcept {
- // Move carets relatively by bytes.
- for (size_t r=0; r<sel.Count(); r++) {
- const Sci::Position positionInsert = sel.Range(r).Start().Position();
- sel.Range(r) = SelectionRange(positionInsert + offset);
- }
-}
-
-void ScintillaWin::DrawImeIndicator(int indicator, Sci::Position len) {
- // Emulate the visual style of IME characters with indicators.
- // Draw an indicator on the character before caret by the character bytes of len
- // so it should be called after InsertCharacter().
- // It does not affect caret positions.
- if (indicator < 8 || indicator > IndicatorMax) {
- return;
- }
- pdoc->DecorationSetCurrentIndicator(indicator);
- for (size_t r=0; r<sel.Count(); r++) {
- const Sci::Position positionInsert = sel.Range(r).Start().Position();
- pdoc->DecorationFillRange(positionInsert - len, 1, len);
- }
-}
-
void ScintillaWin::SetCandidateWindowPos() {
IMContext imc(MainHWND());
if (imc.hIMC) {