aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Editor.cxx5
-rw-r--r--src/Editor.h1
-rw-r--r--win32/ScintillaWin.cxx58
3 files changed, 64 insertions, 0 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index eff38e63a..0ef69d1bf 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -1394,6 +1394,7 @@ void Editor::EnsureCaretVisible(bool useMargin, bool vert, bool horiz) {
Redraw();
}
}
+ UpdateSystemCaret();
}
void Editor::ShowCaretAtCurrentPosition() {
@@ -1418,6 +1419,10 @@ void Editor::InvalidateCaret() {
InvalidateRange(posDrag, posDrag + 1);
else
InvalidateRange(currentPos, currentPos + 1);
+ UpdateSystemCaret();
+}
+
+void Editor::UpdateSystemCaret() {
}
void Editor::NeedWrapping(int docLineStartWrapping, int docLineEndWrapping) {
diff --git a/src/Editor.h b/src/Editor.h
index d5116f0de..181e1ffd4 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -369,6 +369,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
void ShowCaretAtCurrentPosition();
void DropCaret();
void InvalidateCaret();
+ virtual void UpdateSystemCaret();
void NeedWrapping(int docLineStartWrapping = 0, int docLineEndWrapping = 0x7ffffff);
bool WrapLines(bool fullWrap, int priorityWrapLineStart);
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index e7a57ae9c..1038f4838 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -184,6 +184,7 @@ class ScintillaWin :
virtual void SetMouseCapture(bool on);
virtual bool HaveMouseCapture();
virtual void ScrollText(int linesToMove);
+ virtual void UpdateSystemCaret();
virtual void SetVerticalScrollPos();
virtual void SetHorizontalScrollPos();
virtual bool ModifyScrollBars(int nMax, int nPage);
@@ -251,6 +252,15 @@ public:
bool DragIsRectangularOK(CLIPFORMAT fmt) {
return drag.rectangular && (fmt == cfColumnSelect);
}
+
+private:
+ // For use in creating a system caret
+ bool HasCaretSizeChanged();
+ BOOL CreateSystemCaret();
+ BOOL DestroySystemCaret();
+ HBITMAP sysCaretBitmap;
+ int sysCaretWidth;
+ int sysCaretHeight;
};
HINSTANCE ScintillaWin::hInstance = 0;
@@ -276,6 +286,10 @@ ScintillaWin::ScintillaWin(HWND hwnd) {
ds.sci = this;
dt.sci = this;
+ sysCaretBitmap = 0;
+ sysCaretWidth = 0;
+ sysCaretHeight = 0;
+
Initialise();
}
@@ -742,6 +756,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam
if (!wParam ||
!(::IsChild(wThis,wOther) || (wOther == wCT))) {
SetFocusState(false);
+ DestroySystemCaret();
}
}
//RealizeWindowPalette(true);
@@ -750,6 +765,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam
case WM_SETFOCUS:
SetFocusState(true);
RealizeWindowPalette(false);
+ CreateSystemCaret();
break;
case WM_SYSCOLORCHANGE:
@@ -978,6 +994,17 @@ void ScintillaWin::ScrollText(int linesToMove) {
::UpdateWindow(MainHWND());
}
+void ScintillaWin::UpdateSystemCaret() {
+ if (hasFocus) {
+ if (HasCaretSizeChanged()) {
+ DestroySystemCaret();
+ CreateSystemCaret();
+ }
+ Point pos = LocationFromPosition(currentPos);
+ ::SetCaretPos(pos.x, pos.y);
+ }
+}
+
int ScintillaWin::SetScrollInfo(int nBar, LPCSCROLLINFO lpsi, BOOL bRedraw) {
return ::SetScrollInfo(MainHWND(), nBar, lpsi, bRedraw);
}
@@ -2100,6 +2127,37 @@ bool ScintillaWin::Unregister() {
return result;
}
+bool ScintillaWin::HasCaretSizeChanged() {
+ if (
+ ( (0 != vs.caretWidth) && (sysCaretWidth != vs.caretWidth) )
+ || (0 != vs.lineHeight) && (sysCaretHeight != vs.lineHeight)
+ ) {
+ return true;
+ }
+ return false;
+}
+
+BOOL ScintillaWin::CreateSystemCaret() {
+ sysCaretWidth = vs.caretWidth;
+ if (0 == sysCaretWidth) {
+ sysCaretWidth = 1;
+ }
+ sysCaretHeight = vs.lineHeight;
+ sysCaretBitmap = ::CreateBitmap(sysCaretWidth, sysCaretHeight, 1, 1, NULL);
+ BOOL retval = ::CreateCaret(
+ MainHWND(), sysCaretBitmap,
+ sysCaretWidth, sysCaretHeight);
+ ::ShowCaret(MainHWND());
+ return retval;
+}
+
+BOOL ScintillaWin::DestroySystemCaret() {
+ ::HideCaret(MainHWND());
+ BOOL retval = ::DestroyCaret();
+ ::DeleteObject(sysCaretBitmap);
+ return retval;
+}
+
// Take care of 32/64 bit pointers
#ifdef GetWindowLongPtr
static void *PointerFromWindow(HWND hWnd) {