mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-09 20:36:48 +02:00
Gtk2: fixed input in TFloatSpinEdit. issue #18679
git-svn-id: trunk@36068 -
This commit is contained in:
parent
32b1b8d917
commit
4c122be304
@ -196,7 +196,7 @@ end;
|
|||||||
function HandleFloatSpinEditKeyPress(Widget: PGtkWidget; Event: PGdkEventKey; Data: gPointer): Boolean;
|
function HandleFloatSpinEditKeyPress(Widget: PGtkWidget; Event: PGdkEventKey; Data: gPointer): Boolean;
|
||||||
var
|
var
|
||||||
Entry: PGtkEntry;
|
Entry: PGtkEntry;
|
||||||
AChar: Array [0..0] of Char;
|
AChar: Char;
|
||||||
ACurPos: Integer;
|
ACurPos: Integer;
|
||||||
ASelLen: Integer;
|
ASelLen: Integer;
|
||||||
FL: Double;
|
FL: Double;
|
||||||
@ -204,19 +204,26 @@ var
|
|||||||
SSel: String;
|
SSel: String;
|
||||||
P: PChar;
|
P: PChar;
|
||||||
SpinButton: PGtkSpinButton;
|
SpinButton: PGtkSpinButton;
|
||||||
|
|
||||||
|
function ValidNumberKey(out AKey: Char): Boolean;
|
||||||
|
begin
|
||||||
|
AKey := #0;
|
||||||
|
if Event^.length <> 1 then
|
||||||
|
exit(False);
|
||||||
|
AKey := Event^._string^;
|
||||||
|
Result := (Byte(Ord(AKey)) in [VK_0..VK_9]) or (AKey = DecimalSeparator);
|
||||||
|
end;
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
Entry := GTK_ENTRY(Widget);
|
Entry := GTK_ENTRY(Widget);
|
||||||
if (ABS(Entry^.current_pos - Entry^.selection_bound) >= 0) and
|
if (ABS(Entry^.current_pos - Entry^.selection_bound) >= 0) and
|
||||||
(Event^.keyval > 31) and (Event^.keyval < 256) then
|
ValidNumberKey(AChar) then
|
||||||
begin
|
begin
|
||||||
SpinButton := GTK_SPIN_BUTTON(Entry);
|
SpinButton := GTK_SPIN_BUTTON(Entry);
|
||||||
FL := gtk_spin_button_get_value(SpinButton);
|
FL := gtk_spin_button_get_value(SpinButton);
|
||||||
ACurPos := Min(Entry^.current_pos, Entry^.selection_bound);
|
ACurPos := Min(Entry^.current_pos, Entry^.selection_bound);
|
||||||
ASelLen := ABS(Entry^.current_pos - Entry^.selection_bound);
|
ASelLen := ABS(Entry^.current_pos - Entry^.selection_bound);
|
||||||
S := StrPas(gtk_entry_get_text(Entry));
|
S := StrPas(gtk_entry_get_text(Entry));
|
||||||
// writeln(Format('Value %12.2n text %s start %d len %d',
|
|
||||||
// [FL, StrPas(gtk_entry_get_text(Entry)), ACurPos, ASelLen]));
|
|
||||||
|
|
||||||
if ASelLen > 0 then
|
if ASelLen > 0 then
|
||||||
begin
|
begin
|
||||||
@ -231,7 +238,7 @@ begin
|
|||||||
SSel := Copy(S,ACurPos + 1, ASelLen + 1);
|
SSel := Copy(S,ACurPos + 1, ASelLen + 1);
|
||||||
|
|
||||||
Delete(S, ACurPos + 1, ASelLen);
|
Delete(S, ACurPos + 1, ASelLen);
|
||||||
Insert(Chr(Event^.keyVal), S, ACurPos + 1);
|
Insert(AChar, S, ACurPos + 1);
|
||||||
|
|
||||||
// if clocale isn't included in our project we are in trouble.
|
// if clocale isn't included in our project we are in trouble.
|
||||||
S := StringReplace(S,',',DecimalSeparator,[rfReplaceAll]);
|
S := StringReplace(S,',',DecimalSeparator,[rfReplaceAll]);
|
||||||
|
Loading…
Reference in New Issue
Block a user