aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2021-06-17 09:28:05 +1000
committerNeil <nyamatongwe@gmail.com>2021-06-17 09:28:05 +1000
commit9e52243831ceffced1e9f0ef27041770fe13a85a (patch)
treea14b3f24127e77c4c28e16e0b81e0a5dac929e2c
parent37edcd47eed457d80e353bccfe9e601578ccca33 (diff)
downloadscintilla-mirror-9e52243831ceffced1e9f0ef27041770fe13a85a.tar.gz
Add SciFnDirectStatus, a direct access function which also returns status so can
improve performance for client code that called SCI_GETSTATUS after every API to check for failure.
-rw-r--r--cocoa/ScintillaCocoa.h1
-rw-r--r--cocoa/ScintillaCocoa.mm29
-rw-r--r--doc/ScintillaDoc.html18
-rw-r--r--doc/ScintillaHistory.html6
-rwxr-xr-xgtk/ScintillaGTK.cxx11
-rwxr-xr-xgtk/ScintillaGTK.h2
-rw-r--r--include/Scintilla.h2
-rw-r--r--include/Scintilla.iface3
-rw-r--r--include/ScintillaMessages.h1
-rw-r--r--qt/ScintillaEditBase/ScintillaQt.cpp15
-rw-r--r--qt/ScintillaEditBase/ScintillaQt.h2
-rw-r--r--win32/ScintillaWin.cxx20
12 files changed, 100 insertions, 10 deletions
diff --git a/cocoa/ScintillaCocoa.h b/cocoa/ScintillaCocoa.h
index 40c389f5f..00a0fbc03 100644
--- a/cocoa/ScintillaCocoa.h
+++ b/cocoa/ScintillaCocoa.h
@@ -189,6 +189,7 @@ public:
std::string EncodedFromUTF8(std::string_view utf8) const override;
static sptr_t DirectFunction(sptr_t ptr, unsigned int iMessage, uptr_t wParam, sptr_t lParam);
+ static sptr_t DirectStatusFunction(sptr_t ptr, unsigned int iMessage, uptr_t wParam, sptr_t lParam, int *pStatus);
NSTimer *timers[static_cast<size_t>(TickReason::platform)+1];
void TimerFired(NSTimer *timer);
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index 81e31d9aa..242cd4162 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -811,7 +811,31 @@ void ScintillaCocoa::Redraw() {
*/
sptr_t ScintillaCocoa::DirectFunction(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
sptr_t lParam) {
- return reinterpret_cast<ScintillaCocoa *>(ptr)->WndProc(static_cast<Message>(iMessage), wParam, lParam);
+ ScintillaCocoa *sci = reinterpret_cast<ScintillaCocoa *>(ptr);
+ return sci->WndProc(static_cast<Message>(iMessage), wParam, lParam);
+}
+
+//--------------------------------------------------------------------------------------------------
+
+/**
+ * A function to directly execute code that would usually go the long way via window messages.
+ * Similar to DirectFunction but also returns the status.
+ * However this is a Windows metaphor and not used here, hence we just call our fake
+ * window proc. The given parameters directly reflect the message parameters used on Windows.
+ *
+ * @param ptr The target which is to be called.
+ * @param iMessage A code that indicates which message was sent.
+ * @param wParam One of the two free parameters for the message. Traditionally a word sized parameter
+ * (hence the w prefix).
+ * @param lParam The other of the two free parameters. A signed long.
+ * @param pStatus Return the status to the caller. A pointer to an int.
+ */
+sptr_t ScintillaCocoa::DirectStatusFunction(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
+ sptr_t lParam, int *pStatus) {
+ ScintillaCocoa *sci = reinterpret_cast<ScintillaCocoa *>(ptr);
+ const sptr_t returnValue = sci->WndProc(static_cast<Message>(iMessage), wParam, lParam);
+ *pStatus = static_cast<int>(sci->errorStatus);
+ return returnValue;
}
//--------------------------------------------------------------------------------------------------
@@ -856,6 +880,9 @@ sptr_t ScintillaCocoa::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
case Message::GetDirectFunction:
return reinterpret_cast<sptr_t>(DirectFunction);
+ case Message::GetDirectStatusFunction:
+ return reinterpret_cast<sptr_t>(DirectStatusFunction);
+
case Message::GetDirectPointer:
return reinterpret_cast<sptr_t>(this);
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index 2a842b222..7e048c273 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -128,7 +128,7 @@
<h1>Scintilla Documentation</h1>
- <p>Last edited 10 June 2021 NH</p>
+ <p>Last edited 17 June 2021 NH</p>
<p style="background:#90F0C0">Scintilla 5 has moved the lexers from Scintilla into a new
<a href="Lexilla.html">Lexilla</a> project.<br />
@@ -6654,7 +6654,9 @@ struct Sci_RangeToFormat {
<code>SC_WRAP_CHAR</code> is not supported for printing.</p>
<h2 id="DirectAccess">Direct access</h2>
- <code><a class="message" href="#SCI_GETDIRECTFUNCTION">SCI_GETDIRECTFUNCTION &rarr; pointer</a><br />
+ <code>
+ <a class="message" href="#SCI_GETDIRECTFUNCTION">SCI_GETDIRECTFUNCTION &rarr; pointer</a><br />
+ <a class="message" href="#SCI_GETDIRECTSTATUSFUNCTION">SCI_GETDIRECTSTATUSFUNCTION &rarr; pointer</a><br />
<a class="message" href="#SCI_GETDIRECTPOINTER">SCI_GETDIRECTPOINTER &rarr; pointer</a><br />
<a class="message" href="#SCI_GETCHARACTERPOINTER">SCI_GETCHARACTERPOINTER &rarr; pointer</a><br />
<a class="message" href="#SCI_GETRANGEPOINTER">SCI_GETRANGEPOINTER(position start, position lengthRange) &rarr; pointer</a><br />
@@ -6677,7 +6679,7 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){
}
</pre>
- <p><code>SciFnDirect</code>, <code>sptr_t</code> and <code>uptr_t</code> are declared in
+ <p><code>SciFnDirect</code>, <code>SciFnDirectStatus</code>, <code>sptr_t</code> and <code>uptr_t</code> are declared in
<code>Scintilla.h</code>. <code class="parameter">hSciWnd</code> is the window handle returned when you created
the Scintilla window.</p>
@@ -6685,9 +6687,9 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){
to the native thread of the Scintilla window in which case <code>SendMessage(hSciWnd, SCI_*,
wParam, lParam)</code> should be used to synchronize with the window's thread.</p>
- <p>This feature also works on GTK but has no significant impact on speed.</p>
+ <p>This feature also works on other platforms but has less impact on speed.</p>
- <p>From version 1.47 on Windows, Scintilla exports a function called
+ <p>On Windows, Scintilla exports a function called
<code>Scintilla_DirectFunction</code> that can be used the same as the function returned by
<code>SCI_GETDIRECTFUNCTION</code>. This saves you the call to
<code>SCI_GETDIRECTFUNCTION</code> and the need to call Scintilla indirectly via the function
@@ -6698,6 +6700,12 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){
the overhead of passing through the Windows messaging system. You need only call this once,
regardless of the number of Scintilla windows you create.</p>
+ <p><b id="SCI_GETDIRECTSTATUSFUNCTION">SCI_GETDIRECTSTATUSFUNCTION &rarr; pointer</b><br />
+ This is similar to <code>SCI_GETDIRECTFUNCTION</code> but the returned function
+ is of type <code>SciFnDirectStatus</code> which also returns the status to the caller through a
+ pointer to an int.
+ This saves performing an extra call to retrieve the status in many situations so can be faster.</p>
+
<p><b id="SCI_GETDIRECTPOINTER">SCI_GETDIRECTPOINTER &rarr; pointer</b><br />
This returns a pointer to data that identifies which Scintilla window is in use. You must call
this once for each Scintilla window you create. When you call the direct function, you must
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 39af707b8..84a29578e 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -581,6 +581,12 @@
Released 2 June 2021.
</li>
<li>
+ Add SciFnDirectStatus, a direct access function which also returns status.
+ It can be retrieved with SCI_GETDIRECTSTATUSFUNCTION.
+ This can avoid calling SCI_GETSTATUS after every API to determine failure so can
+ improve performance.
+ </li>
+ <li>
Add APIs for setting appearance (traditional blob or plain text) and colour of representations
and support setting a representation for the "\r\n" line end sequence.
</li>
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx
index 93a952357..62f1e1e94 100755
--- a/gtk/ScintillaGTK.cxx
+++ b/gtk/ScintillaGTK.cxx
@@ -3100,7 +3100,16 @@ AtkObject *ScintillaGTK::GetAccessible(GtkWidget *widget) {
sptr_t ScintillaGTK::DirectFunction(
sptr_t ptr, unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
- return reinterpret_cast<ScintillaGTK *>(ptr)->WndProc(static_cast<Message>(iMessage), wParam, lParam);
+ ScintillaGTK *sci = reinterpret_cast<ScintillaGTK *>(ptr);
+ return sci->WndProc(static_cast<Message>(iMessage), wParam, lParam);
+}
+
+sptr_t ScintillaGTK::DirectStatusFunction(
+ sptr_t ptr, unsigned int iMessage, uptr_t wParam, sptr_t lParam, int *pStatus) {
+ ScintillaGTK *sci = reinterpret_cast<ScintillaGTK *>(ptr);
+ const sptr_t returnValue = sci->WndProc(static_cast<Message>(iMessage), wParam, lParam);
+ *pStatus = static_cast<int>(sci->errorStatus);
+ return returnValue;
}
/* legacy name for scintilla_object_send_message */
diff --git a/gtk/ScintillaGTK.h b/gtk/ScintillaGTK.h
index 715e7ed50..2db733c87 100755
--- a/gtk/ScintillaGTK.h
+++ b/gtk/ScintillaGTK.h
@@ -271,6 +271,8 @@ private:
static sptr_t DirectFunction(sptr_t ptr,
unsigned int iMessage, uptr_t wParam, sptr_t lParam);
+ static sptr_t DirectStatusFunction(sptr_t ptr,
+ unsigned int iMessage, uptr_t wParam, sptr_t lParam, int *pStatus);
};
// helper class to watch a GObject lifetime and get notified when it dies
diff --git a/include/Scintilla.h b/include/Scintilla.h
index de96d81d8..a92b51684 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -36,6 +36,7 @@ typedef intptr_t sptr_t;
#include "Sci_Position.h"
typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, sptr_t lParam);
+typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, sptr_t lParam, int *pStatus);
#ifndef SCI_DISABLE_AUTOGENERATED
@@ -497,6 +498,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_GETTEXT 2182
#define SCI_GETTEXTLENGTH 2183
#define SCI_GETDIRECTFUNCTION 2184
+#define SCI_GETDIRECTSTATUSFUNCTION 2772
#define SCI_GETDIRECTPOINTER 2185
#define SCI_SETOVERTYPE 2186
#define SCI_GETOVERTYPE 2187
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index 4cb76e3b3..131ca2814 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -1296,6 +1296,9 @@ get position GetTextLength=2183(,)
# Retrieve a pointer to a function that processes messages for this Scintilla.
get pointer GetDirectFunction=2184(,)
+# Retrieve a pointer to a function that processes messages for this Scintilla and returns status.
+get pointer GetDirectStatusFunction=2772(,)
+
# Retrieve a pointer value to use as the first argument when calling
# the function returned by GetDirectFunction.
get pointer GetDirectPointer=2185(,)
diff --git a/include/ScintillaMessages.h b/include/ScintillaMessages.h
index 861981574..2d19db1ae 100644
--- a/include/ScintillaMessages.h
+++ b/include/ScintillaMessages.h
@@ -286,6 +286,7 @@ enum class Message {
GetText = 2182,
GetTextLength = 2183,
GetDirectFunction = 2184,
+ GetDirectStatusFunction = 2772,
GetDirectPointer = 2185,
SetOvertype = 2186,
GetOvertype = 2187,
diff --git a/qt/ScintillaEditBase/ScintillaQt.cpp b/qt/ScintillaEditBase/ScintillaQt.cpp
index f90313554..383f32c10 100644
--- a/qt/ScintillaEditBase/ScintillaQt.cpp
+++ b/qt/ScintillaEditBase/ScintillaQt.cpp
@@ -748,6 +748,9 @@ sptr_t ScintillaQt::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam)
case Message::GetDirectFunction:
return reinterpret_cast<sptr_t>(DirectFunction);
+ case Message::GetDirectStatusFunction:
+ return reinterpret_cast<sptr_t>(DirectStatusFunction);
+
case Message::GetDirectPointer:
return reinterpret_cast<sptr_t>(this);
@@ -770,7 +773,17 @@ sptr_t ScintillaQt::DefWndProc(Message, uptr_t, sptr_t)
sptr_t ScintillaQt::DirectFunction(
sptr_t ptr, unsigned int iMessage, uptr_t wParam, sptr_t lParam)
{
- return reinterpret_cast<ScintillaQt *>(ptr)->WndProc(static_cast<Message>(iMessage), wParam, lParam);
+ ScintillaQt *sci = reinterpret_cast<ScintillaQt *>(ptr);
+ return sci->WndProc(static_cast<Message>(iMessage), wParam, lParam);
+}
+
+sptr_t ScintillaQt::DirectStatusFunction(
+ sptr_t ptr, unsigned int iMessage, uptr_t wParam, sptr_t lParam, int *pStatus)
+{
+ ScintillaQt *sci = reinterpret_cast<ScintillaQt *>(ptr);
+ const sptr_t returnValue = sci->WndProc(static_cast<Message>(iMessage), wParam, lParam);
+ *pStatus = static_cast<int>(sci->errorStatus);
+ return returnValue;
}
// Additions to merge in Scientific Toolworks widget structure
diff --git a/qt/ScintillaEditBase/ScintillaQt.h b/qt/ScintillaEditBase/ScintillaQt.h
index 053e59cc8..a4b59e03c 100644
--- a/qt/ScintillaEditBase/ScintillaQt.h
+++ b/qt/ScintillaEditBase/ScintillaQt.h
@@ -151,6 +151,8 @@ private:
static sptr_t DirectFunction(sptr_t ptr,
unsigned int iMessage, uptr_t wParam, sptr_t lParam);
+ static sptr_t DirectStatusFunction(sptr_t ptr,
+ unsigned int iMessage, uptr_t wParam, sptr_t lParam, int *pStatus);
protected:
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index 068cef15f..0af4a6d65 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -371,6 +371,8 @@ class ScintillaWin :
static sptr_t DirectFunction(
sptr_t ptr, UINT iMessage, uptr_t wParam, sptr_t lParam);
+ static sptr_t DirectStatusFunction(
+ sptr_t ptr, UINT iMessage, uptr_t wParam, sptr_t lParam, int *pStatus);
static LRESULT PASCAL SWndProc(
HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
static LRESULT PASCAL CTWndProc(
@@ -1792,6 +1794,9 @@ sptr_t ScintillaWin::SciMessage(Message iMessage, uptr_t wParam, sptr_t lParam)
case Message::GetDirectFunction:
return reinterpret_cast<sptr_t>(DirectFunction);
+ case Message::GetDirectStatusFunction:
+ return reinterpret_cast<sptr_t>(DirectStatusFunction);
+
case Message::GetDirectPointer:
return reinterpret_cast<sptr_t>(this);
@@ -2032,6 +2037,7 @@ sptr_t ScintillaWin::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
iMessage = SciMessageFromEM(msg);
switch (iMessage) {
case Message::GetDirectFunction:
+ case Message::GetDirectStatusFunction:
case Message::GetDirectPointer:
case Message::GrabFocus:
case Message::SetTechnology:
@@ -3549,8 +3555,18 @@ LRESULT PASCAL ScintillaWin::CTWndProc(
sptr_t ScintillaWin::DirectFunction(
sptr_t ptr, UINT iMessage, uptr_t wParam, sptr_t lParam) {
- PLATFORM_ASSERT(::GetCurrentThreadId() == ::GetWindowThreadProcessId(reinterpret_cast<ScintillaWin *>(ptr)->MainHWND(), nullptr));
- return reinterpret_cast<ScintillaWin *>(ptr)->WndProc(static_cast<Message>(iMessage), wParam, lParam);
+ ScintillaWin *sci = reinterpret_cast<ScintillaWin *>(ptr);
+ PLATFORM_ASSERT(::GetCurrentThreadId() == ::GetWindowThreadProcessId(sci->MainHWND(), nullptr));
+ return sci->WndProc(static_cast<Message>(iMessage), wParam, lParam);
+}
+
+sptr_t ScintillaWin::DirectStatusFunction(
+ sptr_t ptr, UINT iMessage, uptr_t wParam, sptr_t lParam, int *pStatus) {
+ ScintillaWin *sci = reinterpret_cast<ScintillaWin *>(ptr);
+ PLATFORM_ASSERT(::GetCurrentThreadId() == ::GetWindowThreadProcessId(sci->MainHWND(), nullptr));
+ const sptr_t returnValue = sci->WndProc(static_cast<Message>(iMessage), wParam, lParam);
+ *pStatus = static_cast<int>(sci->errorStatus);
+ return returnValue;
}
namespace Scintilla::Internal {