View Issue Details

IDProjectCategoryView StatusLast Update
0026116LazarusWidgetsetpublic2018-01-29 19:41
ReporterBart Broersma Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Platformi386OSLinux 
Product Version1.3 (SVN) 
Summary0026116: Altering Utf8Key in OnUtf8KeyPress does not work correctly in native GTK2 controls
DescriptionWhen you try to change the value of an Utf8Key in a controls OnUtf8KeyPress event handler, this in amnybcases does not work as expected.

E.g. if in a TEdit I try to change Utf8Key "á" (without quotes) into "Ä" this does not work. The net effect in this case is that the key is dismissed.

I have keyboard layout Englis (US) latin1 with dead keys.
In order to type a "á" I type "'a" into the control.
Steps To ReproduceBuild and run the attached sample project.
When typing in any of the editable controls on the bottom, any "character" you type that is present in the edit labeled "Change this" will be converted into the corresponding (by place) "character" in the edit labeled "into this".

Here's the output of typing "abcáéí" into a TEdit and into a TSynEdit.
The TComboBox behaves as the TEdit.

OrigEdit.Text = abcáéí
Replaceedit.Text = xyzÄËÏ

Typing "abcáéí" (without the quotes) in TEdit
------------------------------------
Edit1.KeyDown: Key = 65
Edit1.Utf8KeyPress: Utf8Key = a -> a
Edit1.KeyPress: Key = a -> x
Edit1.Text = x
------------------------------------
------------------------------------
Edit1.KeyDown: Key = 66
Edit1.Utf8KeyPress: Utf8Key = b -> b
Edit1.KeyPress: Key = b -> y
Edit1.Text = xy
------------------------------------
------------------------------------
Edit1.KeyDown: Key = 67
Edit1.Utf8KeyPress: Utf8Key = c -> c
Edit1.KeyPress: Key = c -> z
Edit1.Text = xyz
------------------------------------
------------------------------------
Edit1.KeyDown: Key = 222
------------------------------------
Edit1.KeyDown: Key = 65
Edit1.Utf8KeyPress: Utf8Key = á -> Ä
------------------------------------
Edit1.KeyDown: Key = 222
------------------------------------
Edit1.KeyDown: Key = 69
Edit1.Utf8KeyPress: Utf8Key = é -> Ë
------------------------------------
Edit1.KeyDown: Key = 222
------------------------------------
Edit1.KeyDown: Key = 73
Edit1.Utf8KeyPress: Utf8Key = í -> Ï
Edit1.Text = xyzḮ
------------------------------------




OrigEdit.Text = abcáéí
Replaceedit.Text = xyzÄËÏ

Typing "abcáéí" (without the quotes) in TEdit
------------------------------------
SynEdit1.KeyDown: Key = 65
SynEdit1.Utf8KeyPress: Utf8Key = a -> a
SynEdit1.KeyPress: Key = a -> x
SynEdit1.Text = x

------------------------------------
------------------------------------
SynEdit1.KeyDown: Key = 66
SynEdit1.Utf8KeyPress: Utf8Key = b -> b
SynEdit1.KeyPress: Key = b -> y
SynEdit1.Text = xy

------------------------------------
------------------------------------
SynEdit1.KeyDown: Key = 67
SynEdit1.Utf8KeyPress: Utf8Key = c -> c
SynEdit1.KeyPress: Key = c -> z
SynEdit1.Text = xyz

------------------------------------
------------------------------------
SynEdit1.KeyDown: Key = 222
------------------------------------
SynEdit1.KeyDown: Key = 65
SynEdit1.Utf8KeyPress: Utf8Key = á -> Ä
SynEdit1.Text = xyzÄ

------------------------------------
------------------------------------
SynEdit1.KeyDown: Key = 222
------------------------------------
SynEdit1.KeyDown: Key = 69
SynEdit1.Utf8KeyPress: Utf8Key = é -> Ë
SynEdit1.Text = xyzÄË

------------------------------------
------------------------------------
SynEdit1.KeyDown: Key = 222
------------------------------------
SynEdit1.KeyDown: Key = 73
SynEdit1.Utf8KeyPress: Utf8Key = í -> Ï
SynEdit1.Text = xyzÄËÏ

------------------------------------

The SynEdit behaves as expected.
TagsNo tags attached.
Fixed in Revision
LazTarget-
WidgetsetGTK 2
Attached Files

Relationships

has duplicate 0033091 resolvedBart Broersma Characters changed in TWinControl.KeyPress will not enter changed; original character is entered 
related to 0026121 closedJuha Manninen Native controls in Linux-GTK2 do not trigger OnUtf8KeyPress for keys ^A..^Z 

Activities

Bart Broersma

2014-05-06 16:17

developer  

kp.zip (5,277 bytes)

Bart Broersma

2014-05-06 16:19

developer   ~0074804

Fixed wrong string in output of OnUtf8Keypress.

Zeljan Rikalo

2014-05-06 16:42

developer   ~0074807

Changed from "many Gtk2 controls" to "native Gtk2 controls" ... it's better explanation of problem. TCustomControl works ok.

Bart Broersma

2014-05-06 19:09

developer   ~0074811

Just for my knowledge and entertainment: apart from SynEdit, which other CustomControl works?
Synedit just eats all keys and inserts the characters itself, bypassing the widgetset completely.

In HandleGtkKeyUpDown there is this part starting with

          Result := TWinControl(LCLObject).IntfUTF8KeyPress(Character, 1, SysKey);

          if Result or (Character = '') then
            // dont' stop key event here, just clear it since we need a keyUp event
            ClearKey
          else
          if (Character <> OldCharacter) then
          begin
            WS := UTF8ToUTF16(Character);

This part, AFAICS, tries then to alter the character sent.

Just for the fun of it I replaced
  WS := UTF8ToUTF16(Character)
with
  WS := UTF8ToUTF16(OldCharacter),
expecting that it would have the effect of undoing the changes made in OnUtf8KeyPress. But the only effect it had was just killing the input.

Bart Broersma

2018-01-29 19:40

developer   ~0106121

I changed the test program (it was bugged), kp2.zip.
On GTK2 for me it currently behaves like this:

(Lazarus 1.9.0 r57042 FPC 3.0.4 x86_64-linux-gtk2)

Only OnKeyPress:
In TEdit:
- typing á hangs the program
- a,b,c get converted as expected

In TComboBox:
- typing á gives nothing
- a,b,c get converted as expected

In TSynEdit
- a,b,c get converted as expected

Only OnUtf8KeyPress:
In TEdit:
- á and é give nothing, í gets erroneously converted to Ḯ (note, this is not Ï)

In TComboBox:
- á and é give nothing, í gets erroneously converted to Ḯ (note, this is not Ï)

In TSynEdit:
- á,é,í get converted as expected to Ä,Ë,Ï


Both OnKeyPress and OnUtf8KeyPress:
In TEdit and TComboBox
- a,b,c get converted as expected
- á and é give nothing, í gets erroneously converted to Ḯ (note, this is not Ï)

In TSynEdit
- a,b,c,á,é,í all get converted as expected

So, TSynEdit behaves as expected (which is not surprising, since it intercepts and handles all keystrokes by itself, completely bypassing the widgetset).

For GTK2 native controls:
Changing Key in OnKeyPress works, for Keys < Chr(128)
TEdit hangs when typing á
Changing Key in OnUtf8KeyPress does not change the Key as expected (it either "eats" it, or it changes them erroneaously).

Bart Broersma

2018-01-29 19:41

developer  

kp2.zip (6,648 bytes)

Issue History

Date Modified Username Field Change
2014-05-06 15:17 Bart Broersma New Issue
2014-05-06 15:19 Bart Broersma Steps to Reproduce Updated View Revisions
2014-05-06 15:20 Bart Broersma File Added: kp.zip
2014-05-06 16:17 Bart Broersma File Deleted: kp.zip
2014-05-06 16:17 Bart Broersma File Added: kp.zip
2014-05-06 16:19 Bart Broersma Note Added: 0074804
2014-05-06 16:19 Bart Broersma Steps to Reproduce Updated View Revisions
2014-05-06 16:41 Zeljan Rikalo Summary Altering Utf8Key in OnUtf8KeyPress does not work correctly in many GTK2 controls => Altering Utf8Key in OnUtf8KeyPress does not work correctly in native GTK2 controls
2014-05-06 16:42 Zeljan Rikalo Note Added: 0074807
2014-05-06 19:09 Bart Broersma Note Added: 0074811
2014-06-29 01:16 Juha Manninen Relationship added related to 0026121
2018-01-28 22:45 Bart Broersma Relationship added related to 0033091
2018-01-29 19:40 Bart Broersma Note Added: 0106121
2018-01-29 19:41 Bart Broersma File Added: kp2.zip
2018-03-20 22:28 Bart Broersma Relationship replaced has duplicate 0033091