Qt: fixed crash and wrong events if key is changed in UTF8KeyPress.issue #26103

git-svn-id: trunk@44891 -
This commit is contained in:
zeljko 2014-05-02 15:54:32 +00:00
parent ec4d3bd225
commit 17a8339268

View File

@ -2840,6 +2840,33 @@ var
or (AQtKey = QtKey_Up) or (AQtKey = QtKey_Down)); or (AQtKey = QtKey_Up) or (AQtKey = QtKey_Down));
end; end;
function SendChangedKey: boolean;
begin
if UTF8Char <> UTF8Text then
Text := UTF8ToUTF16(Utf8Char)
else
if Word(AChar) <> CharMsg.CharCode then
Text := Char(CharMsg.CharCode);
AKeyEvent := QKeyEvent_createExtendedKeyEvent(
QEvent_type(Event),
LCLKeyToQtKey(KeyMsg.CharCode),
Modifiers,
0,
KeyMsg.CharCode,
0,
@Text,
QKeyEvent_isAutoRepeat(QKeyEventH(Event)),
QKeyEvent_count(QKeyEventH(Event))
);
try
QObject_event(Sender, AKeyEvent);
finally
QKeyEvent_destroy(AKeyEvent);
end;
end;
begin begin
{$ifdef VerboseQt} {$ifdef VerboseQt}
DebugLn('TQtWidget.SlotKey ', dbgsname(LCLObject)); DebugLn('TQtWidget.SlotKey ', dbgsname(LCLObject));
@ -3150,21 +3177,29 @@ begin
begin begin
UTF8Text := UTF16ToUTF8(Text); UTF8Text := UTF16ToUTF8(Text);
UTF8Char := UTF8Text; UTF8Char := UTF8Text;
{$ifdef VerboseQt} {$ifdef VerboseQt}
WriteLn('sending char ', UTF8Char); WriteLn('sending char ', UTF8Char);
{$endif} {$endif}
if not IsControlKey and LCLObject.IntfUTF8KeyPress(UTF8Char, 1, IsSysKey) then if not IsControlKey and LCLObject.IntfUTF8KeyPress(UTF8Char, 1, IsSysKey) then
begin begin
// the LCL has handled the key // the LCL has handled the key
{$ifdef VerboseQt} {$ifdef VerboseQt}
WriteLn('handled!'); WriteLn('handled!');
{$endif} {$endif}
Exit; Exit;
end; end;
if not CanSendLCLMessage or (Sender = nil) then if not CanSendLCLMessage or (Sender = nil) then
exit; exit;
if (UTF8Char <> UTF8Text) then
begin
// process changed key and exit.
// issue #26103
SendChangedKey;
exit;
end;
// create the CN_CHAR / CN_SYSCHAR message // create the CN_CHAR / CN_SYSCHAR message
FillChar(CharMsg, SizeOf(CharMsg), 0); FillChar(CharMsg, SizeOf(CharMsg), 0);
CharMsg.Msg := CN_CharMsg[IsSysKey]; CharMsg.Msg := CN_CharMsg[IsSysKey];
@ -3173,9 +3208,9 @@ begin
CharMsg.CharCode := Word(AChar); CharMsg.CharCode := Word(AChar);
//Send message to LCL //Send message to LCL
{$ifdef VerboseQt} {$ifdef VerboseQt}
WriteLn(' message: ', CharMsg.Msg); WriteLn(' message: ', CharMsg.Msg);
{$endif} {$endif}
NotifyApplicationUserInput(LCLObject, CharMsg.Msg); NotifyApplicationUserInput(LCLObject, CharMsg.Msg);
if not CanSendLCLMessage or (Sender = nil) then if not CanSendLCLMessage or (Sender = nil) then
@ -3184,9 +3219,9 @@ begin
if (DeliverMessage(CharMsg, True) <> 0) or (CharMsg.CharCode = VK_UNKNOWN) then if (DeliverMessage(CharMsg, True) <> 0) or (CharMsg.CharCode = VK_UNKNOWN) then
begin begin
// the LCL has handled the key // the LCL has handled the key
{$ifdef VerboseQt} {$ifdef VerboseQt}
WriteLn('handled!'); WriteLn('handled!');
{$endif} {$endif}
Exit; Exit;
end; end;
@ -3196,9 +3231,9 @@ begin
//Send a LM_(SYS)CHAR //Send a LM_(SYS)CHAR
CharMsg.Msg := LM_CharMsg[IsSysKey]; CharMsg.Msg := LM_CharMsg[IsSysKey];
{$ifdef VerboseQt} {$ifdef VerboseQt}
WriteLn(' message: ', CharMsg.Msg); WriteLn(' message: ', CharMsg.Msg);
{$endif} {$endif}
if not CanSendLCLMessage or (Sender = nil) then if not CanSendLCLMessage or (Sender = nil) then
exit; exit;
@ -3218,27 +3253,8 @@ begin
(Word(AChar) <> CharMsg.CharCode)) then (Word(AChar) <> CharMsg.CharCode)) then
begin begin
// data was changed // data was changed
if UTF8Char <> UTF8Text then // moved to nested proc because of issue #26103
Text := UTF8ToUTF16(Utf8Char) SendChangedKey;
else
if Word(AChar) <> CharMsg.CharCode then
Text := Char(CharMsg.CharCode);
AKeyEvent := QKeyEvent_createExtendedKeyEvent(
QEvent_type(Event),
LCLKeyToQtKey(KeyMsg.CharCode),
Modifiers,
0,
KeyMsg.CharCode,
0,
@Text,
QKeyEvent_isAutoRepeat(QKeyEventH(Event)),
QKeyEvent_count(QKeyEventH(Event))
);
try
QCoreApplication_sendEvent(Sender, AKeyEvent);
finally
QKeyEvent_destroy(AKeyEvent);
end;
end else end else
begin begin
Result := KeyMsg.CharCode in KeysToEat; Result := KeyMsg.CharCode in KeysToEat;