Răsfoiți Sursa

Use SCI_GETDIRECTSTATUSFUNCTION from 5.1.0, halving the number of calls to Scintilla.

Martijn Laan 1 an în urmă
părinte
comite
a2e773c077
2 a modificat fișierele cu 24 adăugiri și 7 ștergeri
  1. 13 5
      Components/ScintEdit.pas
  2. 11 2
      Components/ScintInt.pas

+ 13 - 5
Components/ScintEdit.pas

@@ -82,6 +82,7 @@ type
     FAutoCompleteFontSize: Integer;
     FCodePage: Integer;
     FDirectPtr: Pointer;
+    FDirectStatusFunction: SciFnDirectStatus;
     FEffectiveCodePage: Integer;
     FEffectiveCodePageDBCS: Boolean;
     FFillSelectionToEdge: Boolean;
@@ -532,19 +533,20 @@ begin
 end;
 
 function TScintEdit.Call(Msg: Cardinal; WParam: Longint; LParam: Longint): Longint;
-var
-  ErrorStatus: LRESULT;
+
 begin
   HandleNeeded;
   if FDirectPtr = nil then
     Error('Call: FDirectPtr is nil');
-  Result := Scintilla_DirectFunction(FDirectPtr, Msg, WParam, LParam);
+  if not Assigned(FDirectStatusFunction) then
+    Error('Call: FDirectStatusFunction is nil');
+  var ErrorStatus: Integer;
+  Result := FDirectStatusFunction(FDirectPtr, Msg, WParam, LParam, ErrorStatus);
 
-  ErrorStatus := Scintilla_DirectFunction(FDirectPtr, SCI_GETSTATUS, 0, 0);
   if ErrorStatus <> 0 then begin
-    Scintilla_DirectFunction(FDirectPtr, SCI_SETSTATUS, 0, 0);
     ErrorFmt('Error status %d returned after Call(%u, %d, %d) = %d',
       [ErrorStatus, Msg, WParam, LParam, Result]);
+    FDirectStatusFunction(FDirectPtr, SCI_SETSTATUS, 0, 0, ErrorStatus);
   end;
 end;
 
@@ -679,10 +681,15 @@ end;
 
 procedure TScintEdit.CreateWnd;
 begin
+  if IsscintLibary = 0 then
+    Error('CreateWnd: IsscintLibary is 0');
   inherited;
   FDirectPtr := Pointer(SendMessage(Handle, SCI_GETDIRECTPOINTER, 0, 0));
   if FDirectPtr = nil then
     Error('CreateWnd: FDirectPtr is nil');
+  FDirectStatusFunction := SciFnDirectStatus(SendMessage(Handle, SCI_GETDIRECTSTATUSFUNCTION, WPARAM(FDirectPtr), 0));
+  if not Assigned(FDirectStatusFunction) then
+    Error('CreateWnd: FDirectStatusFunction is nil');
   UpdateCodePage;
   Call(SCI_SETCOMMANDEVENTS, 0, 0);
   Call(SCI_SETMODEVENTMASK, SC_MOD_INSERTTEXT or SC_MOD_DELETETEXT, 0);
@@ -1967,6 +1974,7 @@ end;
 procedure TScintEdit.WMDestroy(var Message: TWMDestroy);
 begin
   FDirectPtr := nil;
+  FDirectStatusFunction := nil;
   inherited;
 end;
 

+ 11 - 2
Components/ScintInt.pas

@@ -1276,9 +1276,18 @@ type
     characterSource: Integer;   { SCN_CHARADDED }
   end;
 
-function Scintilla_DirectFunction(ptr: Pointer; iMessage: Cardinal;
-  wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; external 'isscint.dll';
+  SciFnDirectStatus = function(ptr: Pointer; iMessage: Cardinal;
+    wParam: WPARAM; lParam: LPARAM; var Status: Integer): LRESULT; cdecl;
+
+var
+  IsscintLibary: HMODULE;
 
 implementation
 
+uses
+  PathFunc;
+
+initialization
+  IsscintLibary := LoadLibrary(PChar(AddBackslash(PathExtractPath(ParamStr(0))) + 'isscint.dll'));
+
 end.