Gtk2: pass non-handled UTF8Key as KeyPress if UTF8KeyPress returns false. issue #21489

git-svn-id: trunk@36266 -
This commit is contained in:
zeljko 2012-03-23 11:09:03 +00:00
parent 33afd9a994
commit 059da29fac

View File

@ -1927,6 +1927,7 @@ var
TargetWidget: PGtkWidget; TargetWidget: PGtkWidget;
TargetObj: gPointer; TargetObj: gPointer;
KeyPressesChar: char; KeyPressesChar: char;
PassUTF8AsKeyPress: Boolean;
procedure StopKeyEvent; procedure StopKeyEvent;
begin begin
@ -1961,7 +1962,7 @@ var
function GetSpecialChar: Char; function GetSpecialChar: Char;
begin begin
if (AEvent^.keyval > $FF00) and (AEvent^.keyval < $FF20) and if (AEvent^.keyval > $FF00) and (AEvent^.keyval < $FF20) and
(AEvent^.keyval <> GDK_KEY_Tab) then (AEvent^.keyval <> GDK_KEY_TAB) then
Result := Chr(AEvent^.keyval xor $FF00) Result := Chr(AEvent^.keyval xor $FF00)
else else
Result := #0; Result := #0;
@ -2392,21 +2393,25 @@ begin
end; end;
{$IFDEF VerboseKeyboard} {$IFDEF VerboseKeyboard}
debugln('[HandleGTKKeyUpDown] GDK_KEY_PRESS UTF8="',DbgStr(Character),'"'); debugln('[HandleGTKKeyUpDown] GDK_KEY_PRESS UTF8="',DbgStr(Character),'"',
' EventStopped ',dbgs(EventStopped),' CanSendChar ',dbgs(CanSendChar));
{$ENDIF} {$ENDIF}
if Character <> '' // we must pass KeyPress if UTF8KeyPress returned false result. issue #21489
then begin PassUTF8AsKeyPress := False;
if Character <> '' then
begin
LCLObject := GetNearestLCLObject(TargetWidget); LCLObject := GetNearestLCLObject(TargetWidget);
if LCLObject is TWinControl if LCLObject is TWinControl then
then begin begin
OldCharacter := Character; OldCharacter := Character;
// send the key after navigation keys were handled // send the key after navigation keys were handled
Result := TWinControl(LCLObject).IntfUTF8KeyPress(Character, 1, SysKey); Result := TWinControl(LCLObject).IntfUTF8KeyPress(Character, 1, SysKey);
if Result or (Character = '') if Result or (Character = '') then
then StopKeyEvent StopKeyEvent
else if (Character <> OldCharacter) else
then begin if (Character <> OldCharacter) then
begin
WS := UTF8ToUTF16(Character); WS := UTF8ToUTF16(Character);
if Length(WS) > 0 then if Length(WS) > 0 then
begin begin
@ -2425,32 +2430,36 @@ begin
end end
else else
AEvent^.length := 1; AEvent^.length := 1;
end end else
else
StopKeyEvent; StopKeyEvent;
end; end;
end; end;
PassUTF8AsKeyPress := not EventStopped and not Result;
end; end;
end; end;
// send a normal KeyPress Event for Delphi compatibility // send a normal KeyPress Event for Delphi compatibility
if not EventStopped and CanSendChar if not EventStopped and (CanSendChar or PassUTF8AsKeyPress) then
then begin begin
{$IFDEF EventTrace} {$IFDEF EventTrace}
EventTrace('char', data); EventTrace('char', data);
{$ENDIF} {$ENDIF}
KeyPressesChar := #0; KeyPressesChar := #0;
if AEvent^.Length = 1 if AEvent^.Length = 1 then
then begin begin
// ASCII key was pressed // ASCII key was pressed
KeyPressesChar := EventString^; KeyPressesChar := EventString^;
end end else
else begin
KeyPressesChar := GetSpecialChar; KeyPressesChar := GetSpecialChar;
//NonAscii key was pressed, and UTF8KeyPress didn't handle it.issue #21489
if PassUTF8AsKeyPress and (KeyPressesChar = #0) then
KeyPressesChar := Char($3F);
end;
if KeyPressesChar <> #0 if KeyPressesChar <> #0 then
then begin begin
FillChar(Msg, SizeOf(Msg), 0); FillChar(Msg, SizeOf(Msg), 0);
Msg.KeyData := CommonKeyData; Msg.KeyData := CommonKeyData;
@ -2459,24 +2468,23 @@ begin
// send the (Sys)Char message directly (not queued) to the LCL // send the (Sys)Char message directly (not queued) to the LCL
Msg.Result:=0; Msg.Result:=0;
Msg.CharCode := Ord(KeyPressesChar); Msg.CharCode := Ord(KeyPressesChar);
if DeliverKeyMessage(TargetObj, Msg) if DeliverKeyMessage(TargetObj, Msg) and
and (Ord(KeyPressesChar) <> Msg.CharCode) (Ord(KeyPressesChar) <> Msg.CharCode) then
then begin begin
// key was changed by lcl // key was changed by lcl
if (Msg.CharCode=0) or (Msg.CharCode>=128) if (Msg.CharCode=0) or (Msg.CharCode>=128) then
then begin begin
// key set to invalid => just stop // key set to invalid => just stop
StopKeyEvent; StopKeyEvent;
end end else
else begin begin
// try to change the key // try to change the key
CharToKeyVal(chr(Msg.CharCode), AEvent^.KeyVal, AEvent^.length); CharToKeyVal(chr(Msg.CharCode), AEvent^.KeyVal, AEvent^.length);
if AEvent^.length = 1 then if AEvent^.length = 1 then
begin begin
EventString^ := Character[1]; EventString^ := Character[1];
EventString[1] := #0; EventString[1] := #0;
end end else
else
EventString^ := #0; EventString^ := #0;
gdk_event_key_set_string(AEvent, EventString); gdk_event_key_set_string(AEvent, EventString);
end; end;