View Issue Details

IDProjectCategoryView StatusLast Update
0038736LazarusLCLpublic2021-04-17 22:12
ReporterMarco van de Voort Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status feedbackResolutionopen 
Target Version2.2 
Summary0038736: tspinedit missed editorenabled property
DescriptionNoticed while porting delphi code: TSpinEdit has not editorenabled property that allows to disable manually editing a value (and just up down instead).

This is usual for IOT applications if you want to value to change gradually.
TagsNo tags attached.
Fixed in Revisionr64989, r65014, r65015, r65016, r65017, r65018
LazTarget2.2
WidgetsetWin32/Win64
Attached Files

Activities

Bart Broersma

2021-04-10 16:57

developer   ~0130234

Last edited: 2021-04-10 17:15

View 2 revisions

If editorenabled is false, can you paste text in the control?
(I meant pasting via native context menu, suppressing Ctl+V is easy)
(If so, then this can be implemented real easily, otherwise it has to be implemted (at least partially) in the widgetset code)

CudaText man

2021-04-10 17:18

reporter   ~0130238

>can you paste text in the control?

It must be disabled as well-- both editing and pasting, because Paste can give any text.

Bart Broersma

2021-04-10 18:14

developer   ~0130241

@CudaText man: I did not ask for opinions, but for the actual behaviour of Delphi.
The fact that paste can give any text has no bearing on this issue whatsoever.

wp

2021-04-10 18:44

developer   ~0130245

Checked Delphi XE 10.3 Community Edition: When EditorEnabled is false I cannot paste anything into the control, neither by CTRL+V nor by the context menu. (Of course, it is possible to copy the text from the spinedit into the clipboard.)

BTW: There is a difference to the LCL SpinEdits: The MaxValue now defaults to 0 rather than the 100 of the LCL, and I do think that 0 really is more appropriate.

Bart Broersma

2021-04-10 22:50

developer   ~0130251

OK, that sucks (as in: not a super easy solution).
@wp: please file a separate bugreport for the MaxValue thing.
Really nice (from the greek) to break existing programs in such a way though.

wp

2021-04-10 23:17

developer   ~0130252

> @wp: please file a separate bugreport for the MaxValue thing.
Done: 0038738.

> Really nice (from the greek) to break existing programs in such a way though.
I had the same impression, but now I explicitely looked also at D7, and found MaxValue = 0 there, too.

Bart Broersma

2021-04-10 23:32

developer   ~0130254

My D7 PE does not have a TSpinEdit at all it seems.

Bart Broersma

2021-04-10 23:34

developer   ~0130255

I assume that setting ReadOnly has no effect on the value of EditorEnabled?

wp

2021-04-10 23:54

developer   ~0130257

> My D7 PE does not have a TSpinEdit at all it seems.
I don't know about the PE edition, D7 Pro has it on palette "Samples", and this is where it is even in XE10.3. Yes, it's not even a "real" VCL component...

> I assume that setting ReadOnly has no effect on the value of EditorEnabled?
ReadOnly, in addition to disabling typing, also disables the spin buttons, like in Lazarus

Bart Broersma

2021-04-10 23:55

developer   ~0130258

B.t.w. I implemented EditorEnabled for T(Float)SpinEditEx.

wp

2021-04-11 00:02

developer   ~0130262

But there is already a "DirectInput" which seems to do exactly the same.

Bart Broersma

2021-04-11 18:17

developer   ~0130272

Last edited: 2021-04-11 18:29

View 2 revisions

> But there is already a "DirectInput" which seems to do exactly the same.
Stupid me, I thought this was implemented in TButtonEdit and controls derived from that (so not in the abstract base class).
Reverted it.

I think they (the greek) do this deliberately. We have a nice feature, they implement it with a defferent name and we have to adjust.

Bart Broersma

2021-04-12 18:28

developer   ~0130318

Possible patch attached to implement this for the win32 WS.
I'm not sure this is the right approach.
Please comment.
spinedit.editorenabled.win32.diff (4,238 bytes)   
Index: lcl/include/spinedit.inc
===================================================================
--- lcl/include/spinedit.inc	(revision 64973)
+++ lcl/include/spinedit.inc	(working copy)
@@ -160,6 +160,16 @@
   Result := FValue;
 end;
 
+procedure TCustomFloatSpinEdit.SetEditorEnabled(AValue: Boolean);
+begin
+  if FEditorEnabled <> AValue then
+  begin
+    FEditorEnabled := AValue;
+    if HandleAllocated then
+      TWSCustomFloatSpinEditClass(WidgetSetClass).SetEditorEnabled(Self, AValue);
+  end;
+end;
+
 function TCustomFloatSpinEdit.IncrementStored: Boolean;
 begin
   Result := not SameValue(FIncrement, DefIncrement);
@@ -182,6 +192,7 @@
   FMaxValue := DefMaxValue;
   FUpdatePending := True;
   FValueChanged := True;
+  FEditorEnabled := True;
 
   with GetControlClassDefaultSize do
     SetInitialBounds(0, 0, CX, CY);
Index: lcl/interfaces/win32/win32wsspin.pp
===================================================================
--- lcl/interfaces/win32/win32wsspin.pp	(revision 64844)
+++ lcl/interfaces/win32/win32wsspin.pp	(working copy)
@@ -65,6 +65,8 @@
     class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
     class procedure ShowHide(const AWinControl: TWinControl); override;
 
+    class procedure SetEditorEnabled(const ACustomFloatSpinEdit: TCustomFloatSpinEdit; AValue: Boolean); override;
+
     class procedure UpdateControl(const ACustomFloatSpinEdit: TCustomFloatSpinEdit); override;
   end;
 
@@ -429,6 +431,22 @@
     SWP_NOSIZE or SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or VisibilityToFlag[AWinControl.HandleObjectShouldBeVisible]);
 end;
 
+class procedure TWin32WSCustomFloatSpinEdit.SetEditorEnabled(
+  const ACustomFloatSpinEdit: TCustomFloatSpinEdit; AValue: Boolean);
+begin
+  if not AValue then
+  begin
+    //make the Edit readonly, without setting the property ReadOnly to True
+    if not ACustomFloatSpinEdit.ReadOnly then
+      Windows.SendMessage(ACustomFloatSpinEdit.Handle, EM_SETREADONLY, Windows.WPARAM(True), 0);
+  end
+  else
+  begin
+    if not ACustomFloatSpinEdit.ReadOnly then
+      Windows.SendMessage(ACustomFloatSpinEdit.Handle, EM_SETREADONLY, Windows.WPARAM(False), 0);
+  end;
+end;
+
 class procedure TWin32WSCustomFloatSpinEdit.UpdateControl(
   const ACustomFloatSpinEdit: TCustomFloatSpinEdit);
 begin
Index: lcl/spin.pp
===================================================================
--- lcl/spin.pp	(revision 64972)
+++ lcl/spin.pp	(working copy)
@@ -37,6 +37,7 @@
   private
     FIncrement: Double;
     FDecimals: Integer;
+    FEditorEnabled: Boolean;
     FMaxValue: Double;
     FMinValue: Double;
     FValue: Double;
@@ -44,6 +45,7 @@
     FUpdatePending: Boolean;
     FValueChanged: Boolean;
     function GetValue: Double;
+    procedure SetEditorEnabled(AValue: Boolean);
     procedure UpdateControl;
     function MaxValueStored: Boolean;
     function IncrementStored: Boolean;
@@ -70,6 +72,7 @@
     function StrToValue(const S: String): Double; virtual;
   public
     property DecimalPlaces: Integer read FDecimals write SetDecimals default DefDecimals;
+    property EditorEnabled: Boolean read FEditorEnabled write SetEditorEnabled default True;
     property Increment: Double read FIncrement write SetIncrement stored IncrementStored nodefault;
     property MinValue: Double read FMinValue write SetMinValue;
     property MaxValue: Double read FMaxValue write SetMaxValue stored MaxValueStored nodefault;
Index: lcl/widgetset/wsspin.pp
===================================================================
--- lcl/widgetset/wsspin.pp	(revision 64844)
+++ lcl/widgetset/wsspin.pp	(working copy)
@@ -58,6 +58,7 @@
 *)
 
     class procedure UpdateControl(const ACustomFloatSpinEdit: TCustomFloatSpinEdit); virtual;
+    class procedure SetEditorEnabled(const ACustomFloatSpinEdit: TCustomFloatSpinEdit; AValue: Boolean); virtual;
   end;
   TWSCustomFloatSpinEditClass = class of TWSCustomFloatSpinEdit;
 
@@ -78,6 +79,11 @@
 begin
 end;
 
+class procedure TWSCustomFloatSpinEdit.SetEditorEnabled(
+  const ACustomFloatSpinEdit: TCustomFloatSpinEdit; AValue: Boolean);
+begin
+end;
+
 { WidgetSetRegistration }
 
 procedure RegisterCustomFloatSpinEdit;

Bart Broersma

2021-04-13 18:24

developer   ~0130355

Patch for win32 + wince attached.
It compiles fo WinCE, but someone with a WinCE device should test if it works (in theory it should).
spinedit.editorenabled.win32.wince.diff (5,640 bytes)   
Index: lcl/include/spinedit.inc
===================================================================
--- lcl/include/spinedit.inc	(revision 64973)
+++ lcl/include/spinedit.inc	(working copy)
@@ -160,6 +160,16 @@
   Result := FValue;
 end;
 
+procedure TCustomFloatSpinEdit.SetEditorEnabled(AValue: Boolean);
+begin
+  if FEditorEnabled <> AValue then
+  begin
+    FEditorEnabled := AValue;
+    if HandleAllocated then
+      TWSCustomFloatSpinEditClass(WidgetSetClass).SetEditorEnabled(Self, AValue);
+  end;
+end;
+
 function TCustomFloatSpinEdit.IncrementStored: Boolean;
 begin
   Result := not SameValue(FIncrement, DefIncrement);
@@ -182,6 +192,7 @@
   FMaxValue := DefMaxValue;
   FUpdatePending := True;
   FValueChanged := True;
+  FEditorEnabled := True;
 
   with GetControlClassDefaultSize do
     SetInitialBounds(0, 0, CX, CY);
Index: lcl/interfaces/win32/win32wsspin.pp
===================================================================
--- lcl/interfaces/win32/win32wsspin.pp	(revision 64844)
+++ lcl/interfaces/win32/win32wsspin.pp	(working copy)
@@ -65,6 +65,8 @@
     class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
     class procedure ShowHide(const AWinControl: TWinControl); override;
 
+    class procedure SetEditorEnabled(const ACustomFloatSpinEdit: TCustomFloatSpinEdit; AValue: Boolean); override;
+
     class procedure UpdateControl(const ACustomFloatSpinEdit: TCustomFloatSpinEdit); override;
   end;
 
@@ -429,6 +431,22 @@
     SWP_NOSIZE or SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or VisibilityToFlag[AWinControl.HandleObjectShouldBeVisible]);
 end;
 
+class procedure TWin32WSCustomFloatSpinEdit.SetEditorEnabled(
+  const ACustomFloatSpinEdit: TCustomFloatSpinEdit; AValue: Boolean);
+begin
+  if not AValue then
+  begin
+    //make the Edit readonly, without setting the property ReadOnly to True
+    if not ACustomFloatSpinEdit.ReadOnly then
+      Windows.SendMessage(ACustomFloatSpinEdit.Handle, EM_SETREADONLY, Windows.WPARAM(True), 0);
+  end
+  else
+  begin
+    if not ACustomFloatSpinEdit.ReadOnly then
+      Windows.SendMessage(ACustomFloatSpinEdit.Handle, EM_SETREADONLY, Windows.WPARAM(False), 0);
+  end;
+end;
+
 class procedure TWin32WSCustomFloatSpinEdit.UpdateControl(
   const ACustomFloatSpinEdit: TCustomFloatSpinEdit);
 begin
Index: lcl/interfaces/wince/wincewsspin.pp
===================================================================
--- lcl/interfaces/wince/wincewsspin.pp	(revision 64844)
+++ lcl/interfaces/wince/wincewsspin.pp	(working copy)
@@ -50,6 +50,8 @@
     class procedure SetText(const AWinControl: TWinControl; const AText: string); override;
     class procedure ShowHide(const AWinControl: TWinControl); override;
 
+    class procedure SetEditorEnabled(const ACustomFloatSpinEdit: TCustomFloatSpinEdit; AValue: Boolean); override;
+
     class procedure UpdateControl(const ACustomFloatSpinEdit: TCustomFloatSpinEdit); override;
   end;
 
@@ -255,6 +257,22 @@
     ShowWindow(Buddy, SW_HIDE);
 end;
 
+class procedure TWinCEWSCustomFloatSpinEdit.SetEditorEnabled(
+  const ACustomFloatSpinEdit: TCustomFloatSpinEdit; AValue: Boolean);
+begin
+  if not AValue then
+  begin
+    //make the Edit readonly, without setting the property ReadOnly to True
+    if not ACustomFloatSpinEdit.ReadOnly then
+      Windows.SendMessage(ACustomFloatSpinEdit.Handle, EM_SETREADONLY, Windows.WPARAM(True), 0);
+  end
+  else
+  begin
+    if not ACustomFloatSpinEdit.ReadOnly then
+      Windows.SendMessage(ACustomFloatSpinEdit.Handle, EM_SETREADONLY, Windows.WPARAM(False), 0);
+  end;
+end;
+
 class procedure TWinCEWSCustomFloatSpinEdit.UpdateControl(
   const ACustomFloatSpinEdit: TCustomFloatSpinEdit);
 begin
Index: lcl/spin.pp
===================================================================
--- lcl/spin.pp	(revision 64972)
+++ lcl/spin.pp	(working copy)
@@ -37,6 +37,7 @@
   private
     FIncrement: Double;
     FDecimals: Integer;
+    FEditorEnabled: Boolean;
     FMaxValue: Double;
     FMinValue: Double;
     FValue: Double;
@@ -44,6 +45,7 @@
     FUpdatePending: Boolean;
     FValueChanged: Boolean;
     function GetValue: Double;
+    procedure SetEditorEnabled(AValue: Boolean);
     procedure UpdateControl;
     function MaxValueStored: Boolean;
     function IncrementStored: Boolean;
@@ -70,6 +72,7 @@
     function StrToValue(const S: String): Double; virtual;
   public
     property DecimalPlaces: Integer read FDecimals write SetDecimals default DefDecimals;
+    property EditorEnabled: Boolean read FEditorEnabled write SetEditorEnabled default True;
     property Increment: Double read FIncrement write SetIncrement stored IncrementStored nodefault;
     property MinValue: Double read FMinValue write SetMinValue;
     property MaxValue: Double read FMaxValue write SetMaxValue stored MaxValueStored nodefault;
Index: lcl/widgetset/wsspin.pp
===================================================================
--- lcl/widgetset/wsspin.pp	(revision 64844)
+++ lcl/widgetset/wsspin.pp	(working copy)
@@ -58,6 +58,7 @@
 *)
 
     class procedure UpdateControl(const ACustomFloatSpinEdit: TCustomFloatSpinEdit); virtual;
+    class procedure SetEditorEnabled(const ACustomFloatSpinEdit: TCustomFloatSpinEdit; AValue: Boolean); virtual;
   end;
   TWSCustomFloatSpinEditClass = class of TWSCustomFloatSpinEdit;
 
@@ -78,6 +79,11 @@
 begin
 end;
 
+class procedure TWSCustomFloatSpinEdit.SetEditorEnabled(
+  const ACustomFloatSpinEdit: TCustomFloatSpinEdit; AValue: Boolean);
+begin
+end;
+
 { WidgetSetRegistration }
 
 procedure RegisterCustomFloatSpinEdit;

Bart Broersma

2021-04-14 09:26

developer   ~0130369

Implemented for win32 and wince in r64989.
I have no idea how to implement this for the other widgetsets, and I can't test most of them,
Please test with r64989 or later and give feedback.

Bart Broersma

2021-04-17 17:27

developer   ~0130431

Last edited: 2021-04-17 17:33

View 2 revisions

Implemented QT(4) in r65014.
GTK2, GTK3, QT5 and Cocoa remain to be done (by someone with access to those widgetsets).

Bart Broersma

2021-04-17 18:19

developer   ~0130433

Implemented for GTK2 (I hope) in r65016.

Issue History

Date Modified Username Field Change
2021-04-10 11:41 Marco van de Voort New Issue
2021-04-10 16:57 Bart Broersma Status new => feedback
2021-04-10 16:57 Bart Broersma LazTarget => -
2021-04-10 16:57 Bart Broersma Note Added: 0130234
2021-04-10 17:15 Bart Broersma Note Edited: 0130234 View Revisions
2021-04-10 17:18 CudaText man Note Added: 0130238
2021-04-10 18:14 Bart Broersma Note Added: 0130241
2021-04-10 18:44 wp Note Added: 0130245
2021-04-10 22:50 Bart Broersma Note Added: 0130251
2021-04-10 22:50 Bart Broersma Status feedback => acknowledged
2021-04-10 23:17 wp Note Added: 0130252
2021-04-10 23:32 Bart Broersma Note Added: 0130254
2021-04-10 23:34 Bart Broersma Status acknowledged => feedback
2021-04-10 23:34 Bart Broersma Note Added: 0130255
2021-04-10 23:54 wp Note Added: 0130257
2021-04-10 23:55 Bart Broersma Note Added: 0130258
2021-04-11 00:02 wp Note Added: 0130262
2021-04-11 18:17 Bart Broersma Note Added: 0130272
2021-04-11 18:29 Bart Broersma Note Edited: 0130272 View Revisions
2021-04-12 18:28 Bart Broersma Note Added: 0130318
2021-04-12 18:28 Bart Broersma File Added: spinedit.editorenabled.win32.diff
2021-04-13 18:24 Bart Broersma Note Added: 0130355
2021-04-13 18:24 Bart Broersma File Added: spinedit.editorenabled.win32.wince.diff
2021-04-14 09:26 Bart Broersma Note Added: 0130369
2021-04-14 09:27 Bart Broersma Target Version => 2.2
2021-04-14 09:27 Bart Broersma Fixed in Revision => r64989
2021-04-14 09:27 Bart Broersma LazTarget - => 2.2
2021-04-14 09:27 Bart Broersma Widgetset Win32/Win64 => Win32/Win64
2021-04-17 17:27 Bart Broersma Fixed in Revision r64989 => r64989, r65014
2021-04-17 17:27 Bart Broersma Widgetset Win32/Win64 => Win32/Win64
2021-04-17 17:27 Bart Broersma Note Added: 0130431
2021-04-17 17:33 Bart Broersma Note Edited: 0130431 View Revisions
2021-04-17 18:19 Bart Broersma Fixed in Revision r64989, r65014 => r64989, r65014, r65015, r65016
2021-04-17 18:19 Bart Broersma Widgetset Win32/Win64 => Win32/Win64
2021-04-17 18:19 Bart Broersma Note Added: 0130433
2021-04-17 18:32 Bart Broersma Fixed in Revision r64989, r65014, r65015, r65016 => r64989, r65014, r65015, r65016, r65017
2021-04-17 18:32 Bart Broersma Widgetset Win32/Win64 => Win32/Win64
2021-04-17 22:12 Bart Broersma Fixed in Revision r64989, r65014, r65015, r65016, r65017 => r64989, r65014, r65015, r65016, r65017, r65018
2021-04-17 22:12 Bart Broersma Widgetset Win32/Win64 => Win32/Win64