Skip to content

Commit

Permalink
Partial fix for issue #413 Chinese IME bug in OSR
Browse files Browse the repository at this point in the history
  • Loading branch information
salvadordf committed Apr 23, 2022
1 parent b94d03b commit 63bd707
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 151 deletions.
27 changes: 22 additions & 5 deletions source/uCEFBufferPanel.pas
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ TBufferPanel = class(TCustomPanel)
{$IFDEF MSWINDOWS}
procedure CreateParams(var Params: TCreateParams); override;
procedure WndProc(var aMessage: TMessage); override;
procedure WMCEFInvalidate(var aMessage: TMessage); message CEF_INVALIDATE;
procedure WMEraseBkgnd(var aMessage : TWMEraseBkgnd); message WM_ERASEBKGND;
procedure WMTouch(var aMessage: TMessage); message WM_TOUCH;
procedure WMPointerDown(var aMessage: TMessage); message WM_POINTERDOWN;
Expand Down Expand Up @@ -488,7 +489,7 @@ function TBufferPanel.SaveToFile(const aFilename : string) : boolean;
function TBufferPanel.InvalidatePanel : boolean;
begin
{$IFDEF MSWINDOWS}
Result := HandleAllocated and PostMessage(Handle, CM_INVALIDATE, 0, 0);
Result := HandleAllocated and PostMessage(Handle, CEF_INVALIDATE, 0, 0);
{$ELSE}
Result := True;
TThread.ForceQueue(nil, @Invalidate);
Expand Down Expand Up @@ -678,6 +679,11 @@ procedure TBufferPanel.WndProc(var aMessage: TMessage);
end;
end;

procedure TBufferPanel.WMCEFInvalidate(var aMessage: TMessage);
begin
Invalidate;
end;

procedure TBufferPanel.WMEraseBkgnd(var aMessage : TWMEraseBkgnd);
begin
aMessage.Result := 1;
Expand Down Expand Up @@ -762,6 +768,17 @@ procedure TBufferPanel.WMIMESetContext(var aMessage: TMessage);
end;

procedure TBufferPanel.WMIMEComposition(var aMessage: TMessage);
const
// CEF uses UINT32_MAX to initialize the TCefRange parameters.
// FPC works fine with a high(integer) value but if we try to use
// integer(high(cardinal)) then it duplicates the result string.
// Delphi however works fine with integer(high(cardinal)) but it doesn't show
// any resul string if we use high(integer)
{$IFDEF FPC}
UINT32_MAX = high(integer);
{$ELSE}
UINT32_MAX = integer(high(cardinal));
{$ENDIF}
var
TempText : ustring;
TempRange : TCefRange;
Expand All @@ -780,8 +797,8 @@ procedure TBufferPanel.WMIMEComposition(var aMessage: TMessage);
begin
if assigned(FOnIMECommitText) then
begin
TempRange.from := high(Integer);
TempRange.to_ := high(Integer);
TempRange.from := UINT32_MAX;
TempRange.to_ := UINT32_MAX;

DoOnIMECommitText(TempText, @TempRange, 0);
end;
Expand All @@ -793,8 +810,8 @@ procedure TBufferPanel.WMIMEComposition(var aMessage: TMessage);
begin
if assigned(FOnIMESetComposition) then
begin
TempRange.from := high(Integer);
TempRange.to_ := high(Integer);
TempRange.from := UINT32_MAX;
TempRange.to_ := UINT32_MAX;

TempSelection.from := TempCompStart;
TempSelection.to_ := TempCompStart + length(TempText);
Expand Down
2 changes: 1 addition & 1 deletion source/uCEFConstants.pas
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,6 @@ interface
CEF_DOCKING_MODE_BOTTOM_LEFT = 3;
CEF_DOCKING_MODE_BOTTOM_RIGHT = 4;
CEF_DOCKING_MODE_CUSTOM = 5;

// /include/internal/cef_types.h (cef_show_state_t)
CEF_SHOW_STATE_NORMAL = 1;
CEF_SHOW_STATE_MINIMIZED = 2;
Expand Down Expand Up @@ -704,6 +703,7 @@ interface
CEF_SENTINEL_START = {$IFDEF MSWINDOWS}WM_APP +{$ENDIF} $A0A;
CEF_SENTINEL_DOCLOSE = {$IFDEF MSWINDOWS}WM_APP +{$ENDIF} $A0B;
CEF_BEFORECLOSE = {$IFDEF MSWINDOWS}WM_APP +{$ENDIF} $A0C;
CEF_INVALIDATE = {$IFDEF MSWINDOWS}WM_APP +{$ENDIF} $A0D;

// Lazarus and some old Delphi versions don't have these message contants
{$IF NOT DECLARED(WM_TOUCH)}
Expand Down
Loading

0 comments on commit 63bd707

Please # to comment.