View Issue Details

IDProjectCategoryView StatusLast Update
0028123PatchesWidgetsetpublic2020-10-10 19:08
ReporterPéter Gábor Assigned ToZeljan Rikalo  
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionopen 
OSLinux 
Product Version1.5 (SVN) 
Summary0028123: TFloatSpinEdit, TSpinEdit: Cannot enter value as expected
DescriptionSelect some (or full) content then try to type in a new value: the entered value is immediately (at first keypress) replaced or "completed" with .MinValue or .MaxValue.

On windows (in wine) the above components works fine.

This issue exists in the fixes branch too (and maybe in older versions).
TagsNo tags attached.
Fixed in Revision
LazTarget-
WidgetsetGTK 2
Attached Files

Relationships

related to 0018554 closedZeljan Rikalo Lazarus putting a TFloatSpinEdit on a form crashes Lazarus CentOS 
related to 0023190 closedZeljan Rikalo Lazarus TFloatSpinEdit - Lazarus freezes when opening 
related to 0018679 closedZeljan Rikalo Lazarus wrong behaviour of TFloatSpinEdit at Keyboard input 
related to 0023266 assignedZeljan Rikalo Lazarus while FloatSpinEdit.MinValue<>0 Keyboard input does not work correctly 
related to 0025735 closedBart Broersma Lazarus Behavior of TSpinEdit.MaxValue differs under Win32 and Gtk2 widgetsets 
has duplicate 0033101 resolvedBart Broersma Lazarus TSpinEdit is not working properly on Linux 
related to 0029645 closedBart Broersma Lazarus TFloatSpinEdit on GTK2 does not allow unconstrained min and max values 

Activities

Bart Broersma

2015-05-18 11:01

developer   ~0083746

What WidgetSet (GTK2, QT)?

Péter Gábor

2015-05-18 12:00

reporter   ~0083747

I already set "Widgetset" to "GTK 2" when I wrote this bug-report...

Zeljan Rikalo

2015-05-18 12:07

developer   ~0083749

please attach example project

Péter Gábor

2015-05-18 12:21

reporter  

bug_tspinedit.tar.gz (128,648 bytes)

Péter Gábor

2015-05-18 12:21

reporter   ~0083751

Example project uploaded...

Bart Broersma

2015-05-18 18:22

developer   ~0083756

> I already set "Widgetset" to "GTK 2" when I wrote this bug-report...
Oops

Bart Broersma

2015-05-20 18:09

developer   ~0083843

Last edited: 2015-05-20 18:11

View 2 revisions

Problem (I think) is in gtkchanged_spinbox (gtk2callback.inc)

      if (AValue < AMin) or (AValue > AMax) then
      begin
        if AValue < AMin then
          SValue := FloatToStr(AMin);
        if AValue > AMax then
          SValue := FloatToStr(AMax);
        AValue := StrToFloatDef(SValue, 0);
      end;
...
      if SNewValue <> SValue then
        gtk_entry_set_text(PGtkEntry(Widget), PChar(SValue));


I think it should not do that if the control still has focus.

Bart Broersma

2015-06-21 12:38

developer  

gtk2spinbox.diff (917 bytes)   
Index: lcl/interfaces/gtk2/gtk2callback.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2callback.inc	(revision 48844)
+++ lcl/interfaces/gtk2/gtk2callback.inc	(working copy)
@@ -554,7 +554,7 @@
       // gtk2 have different meaning how validator should work and trigger
       // so we change it. #18679
       // do not use while loop, but assign to minimum or maximum allowed. #23190
-      if (AValue < AMin) or (AValue > AMax) then
+      if (AValue < AMin) or (AValue > AMax) and not (PGtkWidget(GetFocus)=widget) then
       begin
         if AValue < AMin then
           SValue := FloatToStr(AMin);
@@ -571,7 +571,7 @@
           inc(NumDigits);
         end;
       end;
-      if SNewValue <> SValue then
+      if (SNewValue <> SValue) then
         gtk_entry_set_text(PGtkEntry(Widget), PChar(SValue));
 
       // inform LCL about our changes to entry
gtk2spinbox.diff (917 bytes)   

Bart Broersma

2015-06-21 12:39

developer   ~0084610

@Zeljan: can you review my patch?

Zeljan Rikalo

2015-06-21 16:12

developer   ~0084613

Yes, I'll do it.

Zeljan Rikalo

2015-06-23 16:46

developer   ~0084686

@Bart: what's the meaning of your patch ? ;) It doesn't work here at all and IMO it's totally wrong.

Bart Broersma

2015-06-24 12:49

developer   ~0084697

@Zeljan:
> what's the meaning of your patch ?
if I understand the issue correctly, then it is about the control enforcing Min/Max bounds _while the user is typing in the control_.

AFAICS this is done in gtkchanged_spinbox.

My patch disables this when the control has focus (or at least that is what I intended it to do).

It does work as expected on my Linux/GTK2 setup (Fedora Core 18 in a VM under Win7): you can type any number into the control, and only when exiting the control the Min/Max restraints are applied. Which is what I was aiming for, and which is the way it works on Windows.

> It doesn't work here at all
Define: "does not work at all". In what way does it not behave as you expect it?

> and IMO it's totally wrong
1. That's why I did not commit it
2. "totally wrong" in what sense?

Zeljan Rikalo

2015-06-24 14:46

developer  

gtk2_spinedit.diff (2,074 bytes)   
Index: lcl/interfaces/gtk2/gtk2wsspin.pp
===================================================================
--- lcl/interfaces/gtk2/gtk2wsspin.pp	(revision 49420)
+++ lcl/interfaces/gtk2/gtk2wsspin.pp	(working copy)
@@ -100,17 +100,6 @@
     Exit(0);
 
   Result := gtk_spin_button_get_value({%H-}PGtkSpinButton(ACustomFloatSpinEdit.Handle));
-
-  // gtk2 have different meaning of value vs text in GtkSpinBox when
-  // we are dealing with real FloatSpinEdit. #18679.
-  // We need this because of validator in gtk2callback.inc -> gtkchanged_spinbox()
-  if ACustomFloatSpinEdit.DecimalPlaces > 0  then
-  begin
-    S := StrPas(gtk_entry_get_text({%H-}PGtkEntry(ACustomFloatSpinEdit.Handle)));
-    FL := 0;
-    if TryStrToFloat(S, FL) then
-      Result := FL;
-  end;
 end;
 
 class procedure TGtk2WSCustomFloatSpinEdit.SetSelStart(const ACustomEdit: TCustomEdit;
Index: lcl/interfaces/gtk2/gtk2callback.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2callback.inc	(revision 49420)
+++ lcl/interfaces/gtk2/gtk2callback.inc	(working copy)
@@ -554,6 +554,7 @@
       // gtk2 have different meaning how validator should work and trigger
       // so we change it. #18679
       // do not use while loop, but assign to minimum or maximum allowed. #23190
+      (*
       if (AValue < AMin) or (AValue > AMax) then
       begin
         if AValue < AMin then
@@ -562,6 +563,7 @@
           SValue := FloatToStr(AMax);
         AValue := StrToFloatDef(SValue, 0);
       end;
+      *)
       if (Pos(ADecimalSeparator, SValue) > 0) and (length(SValue) > 1) then
       begin
         SNewValue := Copy(SValue,Pos(ADecimalSeparator, SValue) + 1, length(SValue));
@@ -579,8 +581,11 @@
       Mess.Msg := CM_TEXTCHANGED;
       DeliverMessage(Data, Mess);
     end else
-      // always signal update to pure TSpinEdit
-      gtk_spin_button_update(PGtkSpinButton(Widget));
+    begin
+      FillByte(Mess{%H-},SizeOf(Mess),0);
+      Mess.Msg := CM_TEXTCHANGED;
+      DeliverMessage(Data, Mess);
+    end;
   end;
 end;
 
gtk2_spinedit.diff (2,074 bytes)   

Zeljan Rikalo

2015-06-24 14:46

developer   ~0084701

Attached patch which fixes this problem, but don't know how it will imply on issue 0018679 .

Péter Gábor

2017-09-09 13:06

reporter   ~0102734

Last edited: 2017-09-09 13:07

View 2 revisions

I applied the patch (gtk2_spinedit.diff) in my trunk copy and it seems to be working.
However the min/max value is applied only when the focus changes to another control, but it must be applied on editing done too (for example: when enter key pressed).
I took a look at other GTK applications on my system and they apply min/max when editing done (when enter key pressed).

Also I tested 0018679 and I don't see any problem.

Issue History

Date Modified Username Field Change
2015-05-18 10:31 Péter Gábor New Issue
2015-05-18 11:01 Bart Broersma LazTarget => -
2015-05-18 11:01 Bart Broersma Note Added: 0083746
2015-05-18 11:01 Bart Broersma Status new => feedback
2015-05-18 12:00 Péter Gábor Note Added: 0083747
2015-05-18 12:00 Péter Gábor Status feedback => new
2015-05-18 12:07 Zeljan Rikalo Note Added: 0083749
2015-05-18 12:21 Péter Gábor File Added: bug_tspinedit.tar.gz
2015-05-18 12:21 Péter Gábor Note Added: 0083751
2015-05-18 18:22 Bart Broersma Note Added: 0083756
2015-05-20 15:59 Bart Broersma Category LCL => Widgetset
2015-05-20 18:09 Bart Broersma Note Added: 0083843
2015-05-20 18:11 Bart Broersma Note Edited: 0083843 View Revisions
2015-06-21 12:38 Bart Broersma File Added: gtk2spinbox.diff
2015-06-21 12:39 Bart Broersma Note Added: 0084610
2015-06-21 12:39 Bart Broersma Assigned To => Zeljan Rikalo
2015-06-21 12:39 Bart Broersma Status new => assigned
2015-06-21 12:41 Bart Broersma Project Lazarus => Patches
2015-06-21 16:12 Zeljan Rikalo Note Added: 0084613
2015-06-23 16:46 Zeljan Rikalo Note Added: 0084686
2015-06-23 16:46 Zeljan Rikalo Status assigned => feedback
2015-06-24 12:49 Bart Broersma Note Added: 0084697
2015-06-24 12:49 Bart Broersma Status feedback => assigned
2015-06-24 14:26 Zeljan Rikalo Relationship added related to 0018554
2015-06-24 14:27 Zeljan Rikalo Relationship added related to 0023190
2015-06-24 14:30 Zeljan Rikalo Relationship added related to 0018679
2015-06-24 14:46 Zeljan Rikalo File Added: gtk2_spinedit.diff
2015-06-24 14:46 Zeljan Rikalo Note Added: 0084701
2015-06-25 13:58 Zeljan Rikalo Relationship added related to 0023266
2015-06-25 13:58 Zeljan Rikalo Relationship added related to 0025735
2016-02-12 18:23 Juha Manninen Relationship added related to 0029645
2017-09-09 13:06 Péter Gábor Note Added: 0102734
2017-09-09 13:07 Péter Gábor Note Edited: 0102734 View Revisions
2018-02-04 14:02 Bart Broersma Relationship added related to 0033101
2020-10-10 19:08 Bart Broersma Relationship replaced has duplicate 0033101